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