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