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

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