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#if QT_DEPRECATED_SINCE(5, 14)
528 QT_DEPRECATED_X("use contentsMargins()")
529 void getContentsMargins(int *left, int *top, int *right, int *bottom) const;
530#endif
531 QMargins contentsMargins() const;
532
533 QRect contentsRect() const;
534
535public:
536 QLayout *layout() const;
537 void setLayout(QLayout *);
538 void updateGeometry();
539
540 void setParent(QWidget *parent);
541 void setParent(QWidget *parent, Qt::WindowFlags f);
542
543 void scroll(int dx, int dy);
544 void scroll(int dx, int dy, const QRect&);
545
546 // Misc. functions
547
548 QWidget *focusWidget() const;
549 QWidget *nextInFocusChain() const;
550 QWidget *previousInFocusChain() const;
551
552 // drag and drop
553 bool acceptDrops() const;
554 void setAcceptDrops(bool on);
555
556#ifndef QT_NO_ACTION
557 //actions
558 void addAction(QAction *action);
559#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
560 void addActions(const QList<QAction*> &actions);
561 void insertActions(QAction *before, const QList<QAction*> &actions);
562#else
563 void addActions(QList<QAction*> actions);
564 void insertActions(QAction *before, QList<QAction*> actions);
565#endif
566 void insertAction(QAction *before, QAction *action);
567 void removeAction(QAction *action);
568 QList<QAction*> actions() const;
569#endif
570
571 QWidget *parentWidget() const;
572
573 void setWindowFlags(Qt::WindowFlags type);
574 inline Qt::WindowFlags windowFlags() const;
575 void setWindowFlag(Qt::WindowType, bool on = true);
576 void overrideWindowFlags(Qt::WindowFlags type);
577
578 inline Qt::WindowType windowType() const;
579
580 static QWidget *find(WId);
581 inline QWidget *childAt(int x, int y) const;
582 QWidget *childAt(const QPoint &p) const;
583
584 void setAttribute(Qt::WidgetAttribute, bool on = true);
585 inline bool testAttribute(Qt::WidgetAttribute) const;
586
587 QPaintEngine *paintEngine() const override;
588
589 void ensurePolished() const;
590
591 bool isAncestorOf(const QWidget *child) const;
592
593#ifdef QT_KEYPAD_NAVIGATION
594 bool hasEditFocus() const;
595 void setEditFocus(bool on);
596#endif
597
598 bool autoFillBackground() const;
599 void setAutoFillBackground(bool enabled);
600
601 QBackingStore *backingStore() const;
602
603 QWindow *windowHandle() const;
604
605 static QWidget *createWindowContainer(QWindow *window, QWidget *parent=nullptr, Qt::WindowFlags flags=Qt::WindowFlags());
606
607 friend class QDesktopScreenWidget;
608
609Q_SIGNALS:
610 void windowTitleChanged(const QString &title);
611 void windowIconChanged(const QIcon &icon);
612 void windowIconTextChanged(const QString &iconText);
613 void customContextMenuRequested(const QPoint &pos);
614
615protected:
616 // Event handlers
617 bool event(QEvent *event) override;
618 virtual void mousePressEvent(QMouseEvent *event);
619 virtual void mouseReleaseEvent(QMouseEvent *event);
620 virtual void mouseDoubleClickEvent(QMouseEvent *event);
621 virtual void mouseMoveEvent(QMouseEvent *event);
622#if QT_CONFIG(wheelevent)
623 virtual void wheelEvent(QWheelEvent *event);
624#endif
625 virtual void keyPressEvent(QKeyEvent *event);
626 virtual void keyReleaseEvent(QKeyEvent *event);
627 virtual void focusInEvent(QFocusEvent *event);
628 virtual void focusOutEvent(QFocusEvent *event);
629 virtual void enterEvent(QEvent *event);
630 virtual void leaveEvent(QEvent *event);
631 virtual void paintEvent(QPaintEvent *event);
632 virtual void moveEvent(QMoveEvent *event);
633 virtual void resizeEvent(QResizeEvent *event);
634 virtual void closeEvent(QCloseEvent *event);
635#ifndef QT_NO_CONTEXTMENU
636 virtual void contextMenuEvent(QContextMenuEvent *event);
637#endif
638#if QT_CONFIG(tabletevent)
639 virtual void tabletEvent(QTabletEvent *event);
640#endif
641#ifndef QT_NO_ACTION
642 virtual void actionEvent(QActionEvent *event);
643#endif
644
645#if QT_CONFIG(draganddrop)
646 virtual void dragEnterEvent(QDragEnterEvent *event);
647 virtual void dragMoveEvent(QDragMoveEvent *event);
648 virtual void dragLeaveEvent(QDragLeaveEvent *event);
649 virtual void dropEvent(QDropEvent *event);
650#endif
651
652 virtual void showEvent(QShowEvent *event);
653 virtual void hideEvent(QHideEvent *event);
654
655#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
656 virtual bool nativeEvent(const QByteArray &eventType, void *message, qintptr *result);
657#else
658 virtual bool nativeEvent(const QByteArray &eventType, void *message, long *result);
659#endif
660
661 // Misc. protected functions
662 virtual void changeEvent(QEvent *);
663
664 int metric(PaintDeviceMetric) const override;
665 void initPainter(QPainter *painter) const override;
666 QPaintDevice *redirected(QPoint *offset) const override;
667 QPainter *sharedPainter() const override;
668
669 virtual void inputMethodEvent(QInputMethodEvent *);
670public:
671 virtual QVariant inputMethodQuery(Qt::InputMethodQuery) const;
672
673 Qt::InputMethodHints inputMethodHints() const;
674 void setInputMethodHints(Qt::InputMethodHints hints);
675
676protected Q_SLOTS:
677 void updateMicroFocus();
678protected:
679
680 void create(WId = 0, bool initializeWindow = true,
681 bool destroyOldWindow = true);
682 void destroy(bool destroyWindow = true,
683 bool destroySubWindows = true);
684
685 friend class QDataWidgetMapperPrivate; // for access to focusNextPrevChild
686 virtual bool focusNextPrevChild(bool next);
687 inline bool focusNextChild() { return focusNextPrevChild(true); }
688 inline bool focusPreviousChild() { return focusNextPrevChild(false); }
689
690protected:
691 QWidget(QWidgetPrivate &d, QWidget* parent, Qt::WindowFlags f);
692private:
693 void setBackingStore(QBackingStore *store);
694
695 bool testAttribute_helper(Qt::WidgetAttribute) const;
696
697 QLayout *takeLayout();
698
699 friend class QBackingStoreDevice;
700 friend class QWidgetBackingStore;
701 friend class QApplication;
702 friend class QApplicationPrivate;
703 friend class QGuiApplication;
704 friend class QGuiApplicationPrivate;
705 friend class QBaseApplication;
706 friend class QPainter;
707 friend class QPainterPrivate;
708 friend class QPixmap; // for QPixmap::fill()
709 friend class QFontMetrics;
710 friend class QFontInfo;
711 friend class QLayout;
712 friend class QWidgetItem;
713 friend class QWidgetItemV2;
714 friend class QGLContext;
715 friend class QGLWidget;
716 friend class QGLWindowSurface;
717 friend class QX11PaintEngine;
718 friend class QWin32PaintEngine;
719 friend class QShortcutPrivate;
720 friend class QWindowSurface;
721 friend class QGraphicsProxyWidget;
722 friend class QGraphicsProxyWidgetPrivate;
723 friend class QStyleSheetStyle;
724 friend struct QWidgetExceptionCleaner;
725 friend class QWidgetWindow;
726 friend class QAccessibleWidget;
727 friend class QAccessibleTable;
728 friend class QAccessibleTabButton;
729#ifndef QT_NO_GESTURES
730 friend class QGestureManager;
731 friend class QWinNativePanGestureRecognizer;
732#endif // QT_NO_GESTURES
733 friend class QWidgetEffectSourcePrivate;
734
735#ifdef Q_OS_MAC
736 friend bool qt_mac_is_metal(const QWidget *w);
737#endif
738 friend Q_WIDGETS_EXPORT QWidgetData *qt_qwidget_data(QWidget *widget);
739 friend Q_WIDGETS_EXPORT QWidgetPrivate *qt_widget_private(QWidget *widget);
740
741private:
742 Q_DISABLE_COPY(QWidget)
743 Q_PRIVATE_SLOT(d_func(), void _q_showIfNotHidden())
744
745 QWidgetData *data;
746};
747
748Q_DECLARE_OPERATORS_FOR_FLAGS(QWidget::RenderFlags)
749
750#ifndef Q_QDOC
751template <> inline QWidget *qobject_cast<QWidget*>(QObject *o)
752{
753 if (!o || !o->isWidgetType()) return nullptr;
754 return static_cast<QWidget*>(o);
755}
756template <> inline const QWidget *qobject_cast<const QWidget*>(const QObject *o)
757{
758 if (!o || !o->isWidgetType()) return nullptr;
759 return static_cast<const QWidget*>(o);
760}
761#endif // !Q_QDOC
762
763inline QWidget *QWidget::childAt(int ax, int ay) const
764{ return childAt(QPoint(ax, ay)); }
765
766inline Qt::WindowType QWidget::windowType() const
767{ return static_cast<Qt::WindowType>(int(data->window_flags & Qt::WindowType_Mask)); }
768inline Qt::WindowFlags QWidget::windowFlags() const
769{ return data->window_flags; }
770
771inline bool QWidget::isTopLevel() const
772{ return (windowType() & Qt::Window); }
773
774inline bool QWidget::isWindow() const
775{ return (windowType() & Qt::Window); }
776
777inline bool QWidget::isEnabled() const
778{ return !testAttribute(Qt::WA_Disabled); }
779
780inline bool QWidget::isModal() const
781{ return data->window_modality != Qt::NonModal; }
782
783#if QT_DEPRECATED_SINCE(5, 13)
784inline bool QWidget::isEnabledToTLW() const
785{ return isEnabled(); }
786#endif
787
788inline int QWidget::minimumWidth() const
789{ return minimumSize().width(); }
790
791inline int QWidget::minimumHeight() const
792{ return minimumSize().height(); }
793
794inline int QWidget::maximumWidth() const
795{ return maximumSize().width(); }
796
797inline int QWidget::maximumHeight() const
798{ return maximumSize().height(); }
799
800inline void QWidget::setMinimumSize(const QSize &s)
801{ setMinimumSize(s.width(),s.height()); }
802
803inline void QWidget::setMaximumSize(const QSize &s)
804{ setMaximumSize(s.width(),s.height()); }
805
806inline void QWidget::setSizeIncrement(const QSize &s)
807{ setSizeIncrement(s.width(),s.height()); }
808
809inline void QWidget::setBaseSize(const QSize &s)
810{ setBaseSize(s.width(),s.height()); }
811
812inline const QFont &QWidget::font() const
813{ return data->fnt; }
814
815inline QFontMetrics QWidget::fontMetrics() const
816{ return QFontMetrics(data->fnt); }
817
818inline QFontInfo QWidget::fontInfo() const
819{ return QFontInfo(data->fnt); }
820
821inline void QWidget::setMouseTracking(bool enable)
822{ setAttribute(Qt::WA_MouseTracking, enable); }
823
824inline bool QWidget::hasMouseTracking() const
825{ return testAttribute(Qt::WA_MouseTracking); }
826
827inline bool QWidget::underMouse() const
828{ return testAttribute(Qt::WA_UnderMouse); }
829
830inline void QWidget::setTabletTracking(bool enable)
831{ setAttribute(Qt::WA_TabletTracking, enable); }
832
833inline bool QWidget::hasTabletTracking() const
834{ return testAttribute(Qt::WA_TabletTracking); }
835
836inline bool QWidget::updatesEnabled() const
837{ return !testAttribute(Qt::WA_UpdatesDisabled); }
838
839inline void QWidget::update(int ax, int ay, int aw, int ah)
840{ update(QRect(ax, ay, aw, ah)); }
841
842inline bool QWidget::isVisible() const
843{ return testAttribute(Qt::WA_WState_Visible); }
844
845inline bool QWidget::isHidden() const
846{ return testAttribute(Qt::WA_WState_Hidden); }
847
848inline void QWidget::move(int ax, int ay)
849{ move(QPoint(ax, ay)); }
850
851inline void QWidget::resize(int w, int h)
852{ resize(QSize(w, h)); }
853
854inline void QWidget::setGeometry(int ax, int ay, int aw, int ah)
855{ setGeometry(QRect(ax, ay, aw, ah)); }
856
857inline QRect QWidget::rect() const
858{ return QRect(0,0,data->crect.width(),data->crect.height()); }
859
860inline const QRect &QWidget::geometry() const
861{ return data->crect; }
862
863inline QSize QWidget::size() const
864{ return data->crect.size(); }
865
866inline int QWidget::width() const
867{ return data->crect.width(); }
868
869inline int QWidget::height() const
870{ return data->crect.height(); }
871
872inline QWidget *QWidget::parentWidget() const
873{ return static_cast<QWidget *>(QObject::parent()); }
874
875inline void QWidget::setSizePolicy(QSizePolicy::Policy hor, QSizePolicy::Policy ver)
876{ setSizePolicy(QSizePolicy(hor, ver)); }
877
878inline bool QWidget::testAttribute(Qt::WidgetAttribute attribute) const
879{
880 if (attribute < int(8*sizeof(uint)))
881 return data->widget_attributes & (1<<attribute);
882 return testAttribute_helper(attribute);
883}
884
885
886#define QWIDGETSIZE_MAX ((1<<24)-1)
887
888#ifndef QT_NO_DEBUG_STREAM
889Q_WIDGETS_EXPORT QDebug operator<<(QDebug, const QWidget *);
890#endif
891
892QT_END_NAMESPACE
893
894#endif // QWIDGET_H
895