1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QWIDGET_H
5#define QWIDGET_H
6
7#include <QtWidgets/qtwidgetsglobal.h>
8#include <QtGui/qwindowdefs.h>
9#include <QtCore/qobject.h>
10#include <QtCore/qmargins.h>
11#if QT_CONFIG(action)
12#include <QtGui/qaction.h>
13#endif
14#include <QtGui/qpaintdevice.h>
15#include <QtGui/qpalette.h>
16#include <QtGui/qfont.h>
17#include <QtGui/qfontmetrics.h>
18#include <QtGui/qfontinfo.h>
19#include <QtWidgets/qsizepolicy.h>
20#include <QtGui/qregion.h>
21#include <QtGui/qbrush.h>
22#include <QtGui/qcursor.h>
23#if QT_CONFIG(shortcut)
24# include <QtGui/qkeysequence.h>
25#endif
26
27#ifdef QT_INCLUDE_COMPAT
28#include <QtGui/qevent.h>
29#endif
30
31QT_BEGIN_NAMESPACE
32
33
34class QLayout;
35class QStyle;
36class QAction;
37class QVariant;
38class QWindow;
39class QActionEvent;
40class QMouseEvent;
41class QWheelEvent;
42class QHoverEvent;
43class QKeyEvent;
44class QEnterEvent;
45class QFocusEvent;
46class QPaintEvent;
47class QMoveEvent;
48class QResizeEvent;
49class QCloseEvent;
50class QContextMenuEvent;
51class QInputMethodEvent;
52class QTabletEvent;
53class QDragEnterEvent;
54class QDragMoveEvent;
55class QDragLeaveEvent;
56class QDropEvent;
57class QScreen;
58class QShowEvent;
59class QHideEvent;
60class QIcon;
61class QBackingStore;
62class QPlatformWindow;
63class QLocale;
64class QGraphicsProxyWidget;
65class QGraphicsEffect;
66class QRasterWindowSurface;
67class QUnifiedToolbarSurface;
68class QPixmap;
69#ifndef QT_NO_DEBUG_STREAM
70class QDebug;
71#endif
72
73class QWidgetData
74{
75public:
76 WId winid;
77 uint widget_attributes;
78 Qt::WindowFlags window_flags;
79 uint window_state : 4;
80 uint focus_policy : 4;
81 uint sizehint_forced :1;
82 uint is_closing :1;
83 uint in_show : 1;
84 uint in_set_window_state : 1;
85 mutable uint fstrut_dirty : 1;
86 uint context_menu_policy : 3;
87 uint window_modality : 2;
88 uint in_destructor : 1;
89 uint unused : 13;
90 QRect crect;
91 mutable QPalette pal;
92 QFont fnt;
93 QRect wrect;
94};
95
96class QWidgetPrivate;
97
98class Q_WIDGETS_EXPORT QWidget : public QObject, public QPaintDevice
99{
100 Q_OBJECT
101 Q_DECLARE_PRIVATE(QWidget)
102
103 Q_PROPERTY(bool modal READ isModal)
104 Q_PROPERTY(Qt::WindowModality windowModality READ windowModality WRITE setWindowModality)
105 Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled)
106 Q_PROPERTY(QRect geometry READ geometry WRITE setGeometry)
107 Q_PROPERTY(QRect frameGeometry READ frameGeometry)
108 Q_PROPERTY(QRect normalGeometry READ normalGeometry)
109 Q_PROPERTY(int x READ x)
110 Q_PROPERTY(int y READ y)
111 Q_PROPERTY(QPoint pos READ pos WRITE move DESIGNABLE false STORED false)
112 Q_PROPERTY(QSize frameSize READ frameSize)
113 Q_PROPERTY(QSize size READ size WRITE resize DESIGNABLE false STORED false)
114 Q_PROPERTY(int width READ width)
115 Q_PROPERTY(int height READ height)
116 Q_PROPERTY(QRect rect READ rect)
117 Q_PROPERTY(QRect childrenRect READ childrenRect)
118 Q_PROPERTY(QRegion childrenRegion READ childrenRegion)
119 Q_PROPERTY(QSizePolicy sizePolicy READ sizePolicy WRITE setSizePolicy)
120 Q_PROPERTY(QSize minimumSize READ minimumSize WRITE setMinimumSize)
121 Q_PROPERTY(QSize maximumSize READ maximumSize WRITE setMaximumSize)
122 Q_PROPERTY(int minimumWidth READ minimumWidth WRITE setMinimumWidth STORED false
123 DESIGNABLE false)
124 Q_PROPERTY(int minimumHeight READ minimumHeight WRITE setMinimumHeight STORED false
125 DESIGNABLE false)
126 Q_PROPERTY(int maximumWidth READ maximumWidth WRITE setMaximumWidth STORED false
127 DESIGNABLE false)
128 Q_PROPERTY(int maximumHeight READ maximumHeight WRITE setMaximumHeight STORED false
129 DESIGNABLE false)
130 Q_PROPERTY(QSize sizeIncrement READ sizeIncrement WRITE setSizeIncrement)
131 Q_PROPERTY(QSize baseSize READ baseSize WRITE setBaseSize)
132 Q_PROPERTY(QPalette palette READ palette WRITE setPalette)
133 Q_PROPERTY(QFont font READ font WRITE setFont)
134#ifndef QT_NO_CURSOR
135 Q_PROPERTY(QCursor cursor READ cursor WRITE setCursor RESET unsetCursor)
136#endif
137 Q_PROPERTY(bool mouseTracking READ hasMouseTracking WRITE setMouseTracking)
138 Q_PROPERTY(bool tabletTracking READ hasTabletTracking WRITE setTabletTracking)
139 Q_PROPERTY(bool isActiveWindow READ isActiveWindow)
140 Q_PROPERTY(Qt::FocusPolicy focusPolicy READ focusPolicy WRITE setFocusPolicy)
141 Q_PROPERTY(bool focus READ hasFocus)
142 Q_PROPERTY(Qt::ContextMenuPolicy contextMenuPolicy READ contextMenuPolicy WRITE setContextMenuPolicy)
143 Q_PROPERTY(bool updatesEnabled READ updatesEnabled WRITE setUpdatesEnabled DESIGNABLE false)
144 Q_PROPERTY(bool visible READ isVisible WRITE setVisible DESIGNABLE false)
145 Q_PROPERTY(bool minimized READ isMinimized)
146 Q_PROPERTY(bool maximized READ isMaximized)
147 Q_PROPERTY(bool fullScreen READ isFullScreen)
148 Q_PROPERTY(QSize sizeHint READ sizeHint)
149 Q_PROPERTY(QSize minimumSizeHint READ minimumSizeHint)
150 Q_PROPERTY(bool acceptDrops READ acceptDrops WRITE setAcceptDrops)
151 Q_PROPERTY(QString windowTitle READ windowTitle WRITE setWindowTitle NOTIFY windowTitleChanged)
152 Q_PROPERTY(QIcon windowIcon READ windowIcon WRITE setWindowIcon NOTIFY windowIconChanged)
153 Q_PROPERTY(QString windowIconText READ windowIconText WRITE setWindowIconText NOTIFY windowIconTextChanged) // deprecated
154 Q_PROPERTY(double windowOpacity READ windowOpacity WRITE setWindowOpacity)
155 Q_PROPERTY(bool windowModified READ isWindowModified WRITE setWindowModified)
156#if QT_CONFIG(tooltip)
157 Q_PROPERTY(QString toolTip READ toolTip WRITE setToolTip)
158 Q_PROPERTY(int toolTipDuration READ toolTipDuration WRITE setToolTipDuration)
159#endif
160#if QT_CONFIG(statustip)
161 Q_PROPERTY(QString statusTip READ statusTip WRITE setStatusTip)
162#endif
163#if QT_CONFIG(whatsthis)
164 Q_PROPERTY(QString whatsThis READ whatsThis WRITE setWhatsThis)
165#endif
166#if QT_CONFIG(accessibility)
167 Q_PROPERTY(QString accessibleName READ accessibleName WRITE setAccessibleName)
168 Q_PROPERTY(QString accessibleDescription READ accessibleDescription WRITE setAccessibleDescription)
169#endif
170 Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection RESET unsetLayoutDirection)
171 QDOC_PROPERTY(Qt::WindowFlags windowFlags READ windowFlags WRITE setWindowFlags)
172 Q_PROPERTY(bool autoFillBackground READ autoFillBackground WRITE setAutoFillBackground)
173#ifndef QT_NO_STYLE_STYLESHEET
174 Q_PROPERTY(QString styleSheet READ styleSheet WRITE setStyleSheet)
175#endif
176 Q_PROPERTY(QLocale locale READ locale WRITE setLocale RESET unsetLocale)
177 Q_PROPERTY(QString windowFilePath READ windowFilePath WRITE setWindowFilePath)
178 Q_PROPERTY(Qt::InputMethodHints inputMethodHints READ inputMethodHints WRITE setInputMethodHints)
179
180#if QT_CONFIG(action)
181#if 0
182 // ### TODO: make this work (requires SFINAE-friendly connect())
183 template <typename...Args>
184 using compatible_action_slot_args = std::void_t<
185 decltype(QObject::connect(std::declval<QAction*>(), &QAction::triggered,
186 std::declval<Args>()...))
187 >;
188#else
189 // good-enough compromise for now
190 template <typename...Args>
191 using compatible_action_slot_args = std::enable_if_t<std::conjunction_v<
192#if QT_CONFIG(shortcut)
193 std::disjunction<
194 std::is_same<Args, Qt::ConnectionType>,
195 std::negation<std::is_convertible<Args, QKeySequence>>
196 >...,
197#endif
198 std::negation<std::is_convertible<Args, QIcon>>...,
199 std::negation<std::is_convertible<Args, const char*>>...,
200 std::negation<std::is_convertible<Args, QString>>...
201 >>;
202#endif
203#endif // QT_CONFIG(action)
204
205public:
206 enum RenderFlag {
207 DrawWindowBackground = 0x1,
208 DrawChildren = 0x2,
209 IgnoreMask = 0x4
210 };
211 Q_DECLARE_FLAGS(RenderFlags, RenderFlag)
212
213 explicit QWidget(QWidget* parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags());
214 ~QWidget();
215
216 int devType() const override;
217
218 WId winId() const;
219 void createWinId(); // internal, going away
220 inline WId internalWinId() const { return data->winid; }
221 WId effectiveWinId() const;
222
223 // GUI style setting
224 QStyle *style() const;
225 void setStyle(QStyle *);
226 // Widget types and states
227
228#if QT_DEPRECATED_SINCE(6, 1)
229 QT_DEPRECATED_VERSION_X_6_1("Use isWindow()")
230 bool isTopLevel() const;
231#endif
232 bool isWindow() const;
233
234 bool isModal() const;
235 Qt::WindowModality windowModality() const;
236 void setWindowModality(Qt::WindowModality windowModality);
237
238 bool isEnabled() const;
239 bool isEnabledTo(const QWidget *) const;
240
241public Q_SLOTS:
242 void setEnabled(bool);
243 void setDisabled(bool);
244 void setWindowModified(bool);
245
246 // Widget coordinates
247
248public:
249 QRect frameGeometry() const;
250 const QRect &geometry() const;
251 QRect normalGeometry() const;
252
253 int x() const;
254 int y() const;
255 QPoint pos() const;
256 QSize frameSize() const;
257 QSize size() const;
258 inline int width() const;
259 inline int height() const;
260 inline QRect rect() const;
261 QRect childrenRect() const;
262 QRegion childrenRegion() const;
263
264 QSize minimumSize() const;
265 QSize maximumSize() const;
266 int minimumWidth() const;
267 int minimumHeight() const;
268 int maximumWidth() const;
269 int maximumHeight() const;
270 void setMinimumSize(const QSize &);
271 void setMinimumSize(int minw, int minh);
272 void setMaximumSize(const QSize &);
273 void setMaximumSize(int maxw, int maxh);
274 void setMinimumWidth(int minw);
275 void setMinimumHeight(int minh);
276 void setMaximumWidth(int maxw);
277 void setMaximumHeight(int maxh);
278
279#ifdef Q_QDOC
280 void setupUi(QWidget *widget);
281#endif
282
283 QSize sizeIncrement() const;
284 void setSizeIncrement(const QSize &);
285 void setSizeIncrement(int w, int h);
286 QSize baseSize() const;
287 void setBaseSize(const QSize &);
288 void setBaseSize(int basew, int baseh);
289
290 void setFixedSize(const QSize &);
291 void setFixedSize(int w, int h);
292 void setFixedWidth(int w);
293 void setFixedHeight(int h);
294
295 // Widget coordinate mapping
296
297 QPointF mapToGlobal(const QPointF &) const;
298 QPoint mapToGlobal(const QPoint &) const;
299 QPointF mapFromGlobal(const QPointF &) const;
300 QPoint mapFromGlobal(const QPoint &) const;
301 QPointF mapToParent(const QPointF &) const;
302 QPoint mapToParent(const QPoint &) const;
303 QPointF mapFromParent(const QPointF &) const;
304 QPoint mapFromParent(const QPoint &) const;
305 QPointF mapTo(const QWidget *, const QPointF &) const;
306 QPoint mapTo(const QWidget *, const QPoint &) const;
307 QPointF mapFrom(const QWidget *, const QPointF &) const;
308 QPoint mapFrom(const QWidget *, const QPoint &) const;
309
310 QWidget *window() const;
311 QWidget *nativeParentWidget() const;
312 inline QWidget *topLevelWidget() const { return window(); }
313
314 // Widget appearance functions
315 const QPalette &palette() const;
316 void setPalette(const QPalette &);
317
318 void setBackgroundRole(QPalette::ColorRole);
319 QPalette::ColorRole backgroundRole() const;
320
321 void setForegroundRole(QPalette::ColorRole);
322 QPalette::ColorRole foregroundRole() const;
323
324 const QFont &font() const;
325 void setFont(const QFont &);
326 QFontMetrics fontMetrics() const;
327 QFontInfo fontInfo() const;
328
329#ifndef QT_NO_CURSOR
330 QCursor cursor() const;
331 void setCursor(const QCursor &);
332 void unsetCursor();
333#endif
334
335 void setMouseTracking(bool enable);
336 bool hasMouseTracking() const;
337 bool underMouse() const;
338
339 void setTabletTracking(bool enable);
340 bool hasTabletTracking() const;
341
342 void setMask(const QBitmap &);
343 void setMask(const QRegion &);
344 QRegion mask() const;
345 void clearMask();
346
347 void render(QPaintDevice *target, const QPoint &targetOffset = QPoint(),
348 const QRegion &sourceRegion = QRegion(),
349 RenderFlags renderFlags = RenderFlags(DrawWindowBackground | DrawChildren));
350
351 void render(QPainter *painter, const QPoint &targetOffset = QPoint(),
352 const QRegion &sourceRegion = QRegion(),
353 RenderFlags renderFlags = RenderFlags(DrawWindowBackground | DrawChildren));
354
355 Q_INVOKABLE QPixmap grab(const QRect &rectangle = QRect(QPoint(0, 0), QSize(-1, -1)));
356
357#if QT_CONFIG(graphicseffect)
358 QGraphicsEffect *graphicsEffect() const;
359 void setGraphicsEffect(QGraphicsEffect *effect);
360#endif // QT_CONFIG(graphicseffect)
361
362#ifndef QT_NO_GESTURES
363 void grabGesture(Qt::GestureType type, Qt::GestureFlags flags = Qt::GestureFlags());
364 void ungrabGesture(Qt::GestureType type);
365#endif
366
367public Q_SLOTS:
368 void setWindowTitle(const QString &);
369#ifndef QT_NO_STYLE_STYLESHEET
370 void setStyleSheet(const QString& styleSheet);
371#endif
372public:
373#ifndef QT_NO_STYLE_STYLESHEET
374 QString styleSheet() const;
375#endif
376 QString windowTitle() const;
377 void setWindowIcon(const QIcon &icon);
378 QIcon windowIcon() const;
379 void setWindowIconText(const QString &);
380 QString windowIconText() const;
381 void setWindowRole(const QString &);
382 QString windowRole() const;
383 void setWindowFilePath(const QString &filePath);
384 QString windowFilePath() const;
385
386 void setWindowOpacity(qreal level);
387 qreal windowOpacity() const;
388
389 bool isWindowModified() const;
390#if QT_CONFIG(tooltip)
391 void setToolTip(const QString &);
392 QString toolTip() const;
393 void setToolTipDuration(int msec);
394 int toolTipDuration() const;
395#endif
396#if QT_CONFIG(statustip)
397 void setStatusTip(const QString &);
398 QString statusTip() const;
399#endif
400#if QT_CONFIG(whatsthis)
401 void setWhatsThis(const QString &);
402 QString whatsThis() const;
403#endif
404#if QT_CONFIG(accessibility)
405 QString accessibleName() const;
406 void setAccessibleName(const QString &name);
407 QString accessibleDescription() const;
408 void setAccessibleDescription(const QString &description);
409#endif
410
411 void setLayoutDirection(Qt::LayoutDirection direction);
412 Qt::LayoutDirection layoutDirection() const;
413 void unsetLayoutDirection();
414
415 void setLocale(const QLocale &locale);
416 QLocale locale() const;
417 void unsetLocale();
418
419 inline bool isRightToLeft() const { return layoutDirection() == Qt::RightToLeft; }
420 inline bool isLeftToRight() const { return layoutDirection() == Qt::LeftToRight; }
421
422public Q_SLOTS:
423 inline void setFocus() { setFocus(Qt::OtherFocusReason); }
424
425public:
426 bool isActiveWindow() const;
427 void activateWindow();
428 void clearFocus();
429
430 void setFocus(Qt::FocusReason reason);
431 Qt::FocusPolicy focusPolicy() const;
432 void setFocusPolicy(Qt::FocusPolicy policy);
433 bool hasFocus() const;
434 static void setTabOrder(QWidget *, QWidget *);
435 static void setTabOrder(std::initializer_list<QWidget *> widgets);
436 void setFocusProxy(QWidget *);
437 QWidget *focusProxy() const;
438 Qt::ContextMenuPolicy contextMenuPolicy() const;
439 void setContextMenuPolicy(Qt::ContextMenuPolicy policy);
440
441 // Grab functions
442 void grabMouse();
443#ifndef QT_NO_CURSOR
444 void grabMouse(const QCursor &);
445#endif
446 void releaseMouse();
447 void grabKeyboard();
448 void releaseKeyboard();
449#ifndef QT_NO_SHORTCUT
450 int grabShortcut(const QKeySequence &key, Qt::ShortcutContext context = Qt::WindowShortcut);
451 void releaseShortcut(int id);
452 void setShortcutEnabled(int id, bool enable = true);
453 void setShortcutAutoRepeat(int id, bool enable = true);
454#endif
455 static QWidget *mouseGrabber();
456 static QWidget *keyboardGrabber();
457
458 // Update/refresh functions
459 inline bool updatesEnabled() const;
460 void setUpdatesEnabled(bool enable);
461
462#if QT_CONFIG(graphicsview)
463 QGraphicsProxyWidget *graphicsProxyWidget() const;
464#endif
465
466public Q_SLOTS:
467 void update();
468 void repaint();
469
470public:
471 inline void update(int x, int y, int w, int h);
472 void update(const QRect&);
473 void update(const QRegion&);
474
475 void repaint(int x, int y, int w, int h);
476 void repaint(const QRect &);
477 void repaint(const QRegion &);
478
479public Q_SLOTS:
480 // Widget management functions
481
482 virtual void setVisible(bool visible);
483 void setHidden(bool hidden);
484 void show();
485 void hide();
486
487 void showMinimized();
488 void showMaximized();
489 void showFullScreen();
490 void showNormal();
491
492 bool close();
493 void raise();
494 void lower();
495
496public:
497 void stackUnder(QWidget*);
498 void move(int x, int y);
499 void move(const QPoint &);
500 void resize(int w, int h);
501 void resize(const QSize &);
502 inline void setGeometry(int x, int y, int w, int h);
503 void setGeometry(const QRect &);
504 QByteArray saveGeometry() const;
505 bool restoreGeometry(const QByteArray &geometry);
506 void adjustSize();
507 bool isVisible() const;
508 bool isVisibleTo(const QWidget *) const;
509 inline bool isHidden() const;
510
511 bool isMinimized() const;
512 bool isMaximized() const;
513 bool isFullScreen() const;
514
515 Qt::WindowStates windowState() const;
516 void setWindowState(Qt::WindowStates state);
517 void overrideWindowState(Qt::WindowStates state);
518
519 virtual QSize sizeHint() const;
520 virtual QSize minimumSizeHint() const;
521
522 QSizePolicy sizePolicy() const;
523 void setSizePolicy(QSizePolicy);
524 inline void setSizePolicy(QSizePolicy::Policy horizontal, QSizePolicy::Policy vertical);
525 virtual int heightForWidth(int) const;
526 virtual bool hasHeightForWidth() const;
527
528 QRegion visibleRegion() const;
529
530 void setContentsMargins(int left, int top, int right, int bottom);
531 void setContentsMargins(const QMargins &margins);
532 QMargins contentsMargins() const;
533
534 QRect contentsRect() const;
535
536public:
537 QLayout *layout() const;
538 void setLayout(QLayout *);
539 void updateGeometry();
540
541 void setParent(QWidget *parent);
542 void setParent(QWidget *parent, Qt::WindowFlags f);
543
544 void scroll(int dx, int dy);
545 void scroll(int dx, int dy, const QRect&);
546
547 // Misc. functions
548
549 QWidget *focusWidget() const;
550 QWidget *nextInFocusChain() const;
551 QWidget *previousInFocusChain() const;
552
553 // drag and drop
554 bool acceptDrops() const;
555 void setAcceptDrops(bool on);
556
557#ifndef QT_NO_ACTION
558 //actions
559 void addAction(QAction *action);
560 void addActions(const QList<QAction*> &actions);
561 void insertActions(QAction *before, const QList<QAction*> &actions);
562 void insertAction(QAction *before, QAction *action);
563 void removeAction(QAction *action);
564 QList<QAction*> actions() const;
565
566 // convenience action factories
567 QAction *addAction(const QString &text);
568 QAction *addAction(const QIcon &icon, const QString &text);
569 QAction *addAction(const QString &text, const QObject *receiver,
570 const char *member, Qt::ConnectionType type = Qt::AutoConnection);
571 QAction *addAction(const QIcon &icon, const QString &text, const QObject *receiver,
572 const char *member, Qt::ConnectionType type = Qt::AutoConnection);
573 template <typename...Args, typename = compatible_action_slot_args<Args...>>
574 QAction *addAction(const QString &text, Args&&...args)
575 {
576 QAction *result = addAction(text);
577 connect(result, &QAction::triggered, std::forward<Args>(args)...);
578 return result;
579 }
580 template <typename...Args, typename = compatible_action_slot_args<Args...>>
581 QAction *addAction(const QIcon &icon, const QString &text, Args&&...args)
582 {
583 QAction *result = addAction(icon, text);
584 connect(result, &QAction::triggered, std::forward<Args>(args)...);
585 return result;
586 }
587
588#if QT_CONFIG(shortcut)
589 QAction *addAction(const QString &text, const QKeySequence &shortcut);
590 QAction *addAction(const QIcon &icon, const QString &text, const QKeySequence &shortcut);
591 QAction *addAction(const QString &text, const QKeySequence &shortcut,
592 const QObject *receiver, const char *member,
593 Qt::ConnectionType type = Qt::AutoConnection);
594 QAction *addAction(const QIcon &icon, const QString &text, const QKeySequence &shortcut,
595 const QObject *receiver, const char *member,
596 Qt::ConnectionType type = Qt::AutoConnection);
597
598 template <typename...Args, typename = compatible_action_slot_args<Args...>>
599 QAction *addAction(const QString &text, const QKeySequence &shortcut, Args&&...args)
600 {
601 QAction *result = addAction(text, shortcut);
602 connect(result, &QAction::triggered, std::forward<Args>(args)...);
603 return result;
604 }
605 template <typename...Args, typename = compatible_action_slot_args<Args...>>
606 QAction *addAction(const QIcon &icon, const QString &text, const QKeySequence &shortcut, Args&&...args)
607 {
608 QAction *result = addAction(icon, text, shortcut);
609 connect(result, &QAction::triggered, std::forward<Args>(args)...);
610 return result;
611 }
612#endif // QT_CONFIG(shortcut)
613#endif // QT_NO_ACTION
614
615 QWidget *parentWidget() const;
616
617 void setWindowFlags(Qt::WindowFlags type);
618 inline Qt::WindowFlags windowFlags() const;
619 void setWindowFlag(Qt::WindowType, bool on = true);
620 void overrideWindowFlags(Qt::WindowFlags type);
621
622 inline Qt::WindowType windowType() const;
623
624 static QWidget *find(WId);
625 inline QWidget *childAt(int x, int y) const;
626 QWidget *childAt(const QPoint &p) const;
627
628 void setAttribute(Qt::WidgetAttribute, bool on = true);
629 inline bool testAttribute(Qt::WidgetAttribute) const;
630
631 QPaintEngine *paintEngine() const override;
632
633 void ensurePolished() const;
634
635 bool isAncestorOf(const QWidget *child) const;
636
637#ifdef QT_KEYPAD_NAVIGATION
638 bool hasEditFocus() const;
639 void setEditFocus(bool on);
640#endif
641
642 bool autoFillBackground() const;
643 void setAutoFillBackground(bool enabled);
644
645 QBackingStore *backingStore() const;
646
647 QWindow *windowHandle() const;
648 QScreen *screen() const;
649 void setScreen(QScreen *);
650
651 static QWidget *createWindowContainer(QWindow *window, QWidget *parent=nullptr, Qt::WindowFlags flags=Qt::WindowFlags());
652
653Q_SIGNALS:
654 void windowTitleChanged(const QString &title);
655 void windowIconChanged(const QIcon &icon);
656 void windowIconTextChanged(const QString &iconText);
657 void customContextMenuRequested(const QPoint &pos);
658
659protected:
660 // Event handlers
661 bool event(QEvent *event) override;
662 virtual void mousePressEvent(QMouseEvent *event);
663 virtual void mouseReleaseEvent(QMouseEvent *event);
664 virtual void mouseDoubleClickEvent(QMouseEvent *event);
665 virtual void mouseMoveEvent(QMouseEvent *event);
666#if QT_CONFIG(wheelevent)
667 virtual void wheelEvent(QWheelEvent *event);
668#endif
669 virtual void keyPressEvent(QKeyEvent *event);
670 virtual void keyReleaseEvent(QKeyEvent *event);
671 virtual void focusInEvent(QFocusEvent *event);
672 virtual void focusOutEvent(QFocusEvent *event);
673 virtual void enterEvent(QEnterEvent *event);
674 virtual void leaveEvent(QEvent *event);
675 virtual void paintEvent(QPaintEvent *event);
676 virtual void moveEvent(QMoveEvent *event);
677 virtual void resizeEvent(QResizeEvent *event);
678 virtual void closeEvent(QCloseEvent *event);
679#ifndef QT_NO_CONTEXTMENU
680 virtual void contextMenuEvent(QContextMenuEvent *event);
681#endif
682#if QT_CONFIG(tabletevent)
683 virtual void tabletEvent(QTabletEvent *event);
684#endif
685#ifndef QT_NO_ACTION
686 virtual void actionEvent(QActionEvent *event);
687#endif
688
689#if QT_CONFIG(draganddrop)
690 virtual void dragEnterEvent(QDragEnterEvent *event);
691 virtual void dragMoveEvent(QDragMoveEvent *event);
692 virtual void dragLeaveEvent(QDragLeaveEvent *event);
693 virtual void dropEvent(QDropEvent *event);
694#endif
695
696 virtual void showEvent(QShowEvent *event);
697 virtual void hideEvent(QHideEvent *event);
698
699 virtual bool nativeEvent(const QByteArray &eventType, void *message, qintptr *result);
700
701 // Misc. protected functions
702 virtual void changeEvent(QEvent *);
703
704 int metric(PaintDeviceMetric) const override;
705 void initPainter(QPainter *painter) const override;
706 QPaintDevice *redirected(QPoint *offset) const override;
707 QPainter *sharedPainter() const override;
708
709 virtual void inputMethodEvent(QInputMethodEvent *);
710public:
711 virtual QVariant inputMethodQuery(Qt::InputMethodQuery) const;
712
713 Qt::InputMethodHints inputMethodHints() const;
714 void setInputMethodHints(Qt::InputMethodHints hints);
715
716protected Q_SLOTS:
717 void updateMicroFocus(Qt::InputMethodQuery query = Qt::ImQueryAll);
718protected:
719
720 void create(WId = 0, bool initializeWindow = true,
721 bool destroyOldWindow = true);
722 void destroy(bool destroyWindow = true,
723 bool destroySubWindows = true);
724
725 friend class QDataWidgetMapperPrivate; // for access to focusNextPrevChild
726 virtual bool focusNextPrevChild(bool next);
727 inline bool focusNextChild() { return focusNextPrevChild(next: true); }
728 inline bool focusPreviousChild() { return focusNextPrevChild(next: false); }
729
730protected:
731 QWidget(QWidgetPrivate &d, QWidget* parent, Qt::WindowFlags f);
732private:
733 void setBackingStore(QBackingStore *store);
734
735 bool testAttribute_helper(Qt::WidgetAttribute) const;
736
737 QLayout *takeLayout();
738
739 friend class QBackingStoreDevice;
740 friend class QWidgetRepaintManager;
741 friend class QApplication;
742 friend class QApplicationPrivate;
743 friend class QGuiApplication;
744 friend class QGuiApplicationPrivate;
745 friend class QBaseApplication;
746 friend class QPainter;
747 friend class QPainterPrivate;
748 friend class QPixmap; // for QPixmap::fill()
749 friend class QFontMetrics;
750 friend class QFontInfo;
751 friend class QLayout;
752 friend class QWidgetItem;
753 friend class QWidgetItemV2;
754 friend class QX11PaintEngine;
755 friend class QWin32PaintEngine;
756 friend class QShortcutPrivate;
757 friend class QWindowSurface;
758 friend class QGraphicsProxyWidget;
759 friend class QGraphicsProxyWidgetPrivate;
760 friend class QStyleSheetStyle;
761 friend struct QWidgetExceptionCleaner;
762 friend class QWidgetWindow;
763 friend class QAccessibleWidget;
764 friend class QAccessibleTable;
765 friend class QAccessibleTabButton;
766#ifndef QT_NO_GESTURES
767 friend class QGestureManager;
768 friend class QWinNativePanGestureRecognizer;
769#endif // QT_NO_GESTURES
770 friend class QWidgetEffectSourcePrivate;
771
772 friend Q_WIDGETS_EXPORT QWidgetData *qt_qwidget_data(QWidget *widget);
773 friend Q_WIDGETS_EXPORT QWidgetPrivate *qt_widget_private(QWidget *widget);
774
775private:
776 Q_DISABLE_COPY(QWidget)
777 Q_PRIVATE_SLOT(d_func(), void _q_showIfNotHidden())
778 Q_PRIVATE_SLOT(d_func(), QWindow *_q_closestWindowHandle())
779
780 QWidgetData *data;
781};
782
783Q_DECLARE_OPERATORS_FOR_FLAGS(QWidget::RenderFlags)
784
785#ifndef Q_QDOC
786template <> inline QWidget *qobject_cast<QWidget*>(QObject *o)
787{
788 if (!o || !o->isWidgetType()) return nullptr;
789 return static_cast<QWidget*>(o);
790}
791template <> inline const QWidget *qobject_cast<const QWidget*>(const QObject *o)
792{
793 if (!o || !o->isWidgetType()) return nullptr;
794 return static_cast<const QWidget*>(o);
795}
796#endif // !Q_QDOC
797
798inline QWidget *QWidget::childAt(int ax, int ay) const
799{ return childAt(p: QPoint(ax, ay)); }
800
801inline Qt::WindowType QWidget::windowType() const
802{ return static_cast<Qt::WindowType>((data->window_flags & Qt::WindowType_Mask).toInt()); }
803inline Qt::WindowFlags QWidget::windowFlags() const
804{ return data->window_flags; }
805
806#if QT_DEPRECATED_SINCE(6, 1)
807inline bool QWidget::isTopLevel() const
808{ return bool(windowType() & Qt::Window); }
809#endif
810
811inline bool QWidget::isWindow() const
812{ return bool(windowType() & Qt::Window); }
813
814inline bool QWidget::isEnabled() const
815{ return !testAttribute(Qt::WA_Disabled); }
816
817inline bool QWidget::isModal() const
818{ return data->window_modality != Qt::NonModal; }
819
820inline int QWidget::minimumWidth() const
821{ return minimumSize().width(); }
822
823inline int QWidget::minimumHeight() const
824{ return minimumSize().height(); }
825
826inline int QWidget::maximumWidth() const
827{ return maximumSize().width(); }
828
829inline int QWidget::maximumHeight() const
830{ return maximumSize().height(); }
831
832inline void QWidget::setMinimumSize(const QSize &s)
833{ setMinimumSize(minw: s.width(),minh: s.height()); }
834
835inline void QWidget::setMaximumSize(const QSize &s)
836{ setMaximumSize(maxw: s.width(),maxh: s.height()); }
837
838inline void QWidget::setSizeIncrement(const QSize &s)
839{ setSizeIncrement(w: s.width(),h: s.height()); }
840
841inline void QWidget::setBaseSize(const QSize &s)
842{ setBaseSize(basew: s.width(),baseh: s.height()); }
843
844inline const QFont &QWidget::font() const
845{ return data->fnt; }
846
847inline QFontMetrics QWidget::fontMetrics() const
848{ return QFontMetrics(data->fnt); }
849
850inline QFontInfo QWidget::fontInfo() const
851{ return QFontInfo(data->fnt); }
852
853inline void QWidget::setMouseTracking(bool enable)
854{ setAttribute(Qt::WA_MouseTracking, on: enable); }
855
856inline bool QWidget::hasMouseTracking() const
857{ return testAttribute(Qt::WA_MouseTracking); }
858
859inline bool QWidget::underMouse() const
860{ return testAttribute(Qt::WA_UnderMouse); }
861
862inline void QWidget::setTabletTracking(bool enable)
863{ setAttribute(Qt::WA_TabletTracking, on: enable); }
864
865inline bool QWidget::hasTabletTracking() const
866{ return testAttribute(Qt::WA_TabletTracking); }
867
868inline bool QWidget::updatesEnabled() const
869{ return !testAttribute(Qt::WA_UpdatesDisabled); }
870
871inline void QWidget::update(int ax, int ay, int aw, int ah)
872{ update(QRect(ax, ay, aw, ah)); }
873
874inline bool QWidget::isVisible() const
875{ return testAttribute(Qt::WA_WState_Visible); }
876
877inline bool QWidget::isHidden() const
878{ return testAttribute(Qt::WA_WState_Hidden); }
879
880inline void QWidget::move(int ax, int ay)
881{ move(QPoint(ax, ay)); }
882
883inline void QWidget::resize(int w, int h)
884{ resize(QSize(w, h)); }
885
886inline void QWidget::setGeometry(int ax, int ay, int aw, int ah)
887{ setGeometry(QRect(ax, ay, aw, ah)); }
888
889inline QRect QWidget::rect() const
890{ return QRect(0,0,data->crect.width(),data->crect.height()); }
891
892inline const QRect &QWidget::geometry() const
893{ return data->crect; }
894
895inline QSize QWidget::size() const
896{ return data->crect.size(); }
897
898inline int QWidget::width() const
899{ return data->crect.width(); }
900
901inline int QWidget::height() const
902{ return data->crect.height(); }
903
904inline QWidget *QWidget::parentWidget() const
905{ return static_cast<QWidget *>(QObject::parent()); }
906
907inline void QWidget::setSizePolicy(QSizePolicy::Policy hor, QSizePolicy::Policy ver)
908{ setSizePolicy(QSizePolicy(hor, ver)); }
909
910inline bool QWidget::testAttribute(Qt::WidgetAttribute attribute) const
911{
912 if (attribute < int(8*sizeof(uint)))
913 return data->widget_attributes & (1<<attribute);
914 return testAttribute_helper(attribute);
915}
916
917#define QWIDGETSIZE_MAX ((1<<24)-1)
918
919#ifndef QT_NO_DEBUG_STREAM
920Q_WIDGETS_EXPORT QDebug operator<<(QDebug, const QWidget *);
921#endif
922
923QT_END_NAMESPACE
924
925#endif // QWIDGET_H
926

source code of qtbase/src/widgets/kernel/qwidget.h