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#if QT_CONFIG(shortcut)
57# include <QtGui/qkeysequence.h>
58#endif
59
60#ifdef QT_INCLUDE_COMPAT
61#include <QtGui/qevent.h>
62#endif
63
64QT_BEGIN_NAMESPACE
65
66
67class QLayout;
68class QWSRegionManager;
69class QStyle;
70class QAction;
71class QVariant;
72class QWindow;
73class QActionEvent;
74class QMouseEvent;
75class QWheelEvent;
76class QHoverEvent;
77class QKeyEvent;
78class QEnterEvent;
79class QFocusEvent;
80class QPaintEvent;
81class QMoveEvent;
82class QResizeEvent;
83class QCloseEvent;
84class QContextMenuEvent;
85class QInputMethodEvent;
86class QTabletEvent;
87class QDragEnterEvent;
88class QDragMoveEvent;
89class QDragLeaveEvent;
90class QDropEvent;
91class QScreen;
92class QShowEvent;
93class QHideEvent;
94class QIcon;
95class QBackingStore;
96class QPlatformWindow;
97class QLocale;
98class QGraphicsProxyWidget;
99class QGraphicsEffect;
100class QRasterWindowSurface;
101class QUnifiedToolbarSurface;
102class QPixmap;
103#ifndef QT_NO_DEBUG_STREAM
104class QDebug;
105#endif
106
107class QWidgetData
108{
109public:
110 WId winid;
111 uint widget_attributes;
112 Qt::WindowFlags window_flags;
113 uint window_state : 4;
114 uint focus_policy : 4;
115 uint sizehint_forced :1;
116 uint is_closing :1;
117 uint in_show : 1;
118 uint in_set_window_state : 1;
119 mutable uint fstrut_dirty : 1;
120 uint context_menu_policy : 3;
121 uint window_modality : 2;
122 uint in_destructor : 1;
123 uint unused : 13;
124 QRect crect;
125 mutable QPalette pal;
126 QFont fnt;
127 QRect wrect;
128};
129
130class QWidgetPrivate;
131
132class Q_WIDGETS_EXPORT QWidget : public QObject, public QPaintDevice
133{
134 Q_OBJECT
135 Q_DECLARE_PRIVATE(QWidget)
136
137 Q_PROPERTY(bool modal READ isModal)
138 Q_PROPERTY(Qt::WindowModality windowModality READ windowModality WRITE setWindowModality)
139 Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled)
140 Q_PROPERTY(QRect geometry READ geometry WRITE setGeometry)
141 Q_PROPERTY(QRect frameGeometry READ frameGeometry)
142 Q_PROPERTY(QRect normalGeometry READ normalGeometry)
143 Q_PROPERTY(int x READ x)
144 Q_PROPERTY(int y READ y)
145 Q_PROPERTY(QPoint pos READ pos WRITE move DESIGNABLE false STORED false)
146 Q_PROPERTY(QSize frameSize READ frameSize)
147 Q_PROPERTY(QSize size READ size WRITE resize DESIGNABLE false STORED false)
148 Q_PROPERTY(int width READ width)
149 Q_PROPERTY(int height READ height)
150 Q_PROPERTY(QRect rect READ rect)
151 Q_PROPERTY(QRect childrenRect READ childrenRect)
152 Q_PROPERTY(QRegion childrenRegion READ childrenRegion)
153 Q_PROPERTY(QSizePolicy sizePolicy READ sizePolicy WRITE setSizePolicy)
154 Q_PROPERTY(QSize minimumSize READ minimumSize WRITE setMinimumSize)
155 Q_PROPERTY(QSize maximumSize READ maximumSize WRITE setMaximumSize)
156 Q_PROPERTY(int minimumWidth READ minimumWidth WRITE setMinimumWidth STORED false DESIGNABLE false)
157 Q_PROPERTY(int minimumHeight READ minimumHeight WRITE setMinimumHeight STORED false DESIGNABLE false)
158 Q_PROPERTY(int maximumWidth READ maximumWidth WRITE setMaximumWidth STORED false DESIGNABLE false)
159 Q_PROPERTY(int maximumHeight READ maximumHeight WRITE setMaximumHeight STORED false DESIGNABLE false)
160 Q_PROPERTY(QSize sizeIncrement READ sizeIncrement WRITE setSizeIncrement)
161 Q_PROPERTY(QSize baseSize READ baseSize WRITE setBaseSize)
162 Q_PROPERTY(QPalette palette READ palette WRITE setPalette)
163 Q_PROPERTY(QFont font READ font WRITE setFont)
164#ifndef QT_NO_CURSOR
165 Q_PROPERTY(QCursor cursor READ cursor WRITE setCursor RESET unsetCursor)
166#endif
167 Q_PROPERTY(bool mouseTracking READ hasMouseTracking WRITE setMouseTracking)
168 Q_PROPERTY(bool tabletTracking READ hasTabletTracking WRITE setTabletTracking)
169 Q_PROPERTY(bool isActiveWindow READ isActiveWindow)
170 Q_PROPERTY(Qt::FocusPolicy focusPolicy READ focusPolicy WRITE setFocusPolicy)
171 Q_PROPERTY(bool focus READ hasFocus)
172 Q_PROPERTY(Qt::ContextMenuPolicy contextMenuPolicy READ contextMenuPolicy WRITE setContextMenuPolicy)
173 Q_PROPERTY(bool updatesEnabled READ updatesEnabled WRITE setUpdatesEnabled DESIGNABLE false)
174 Q_PROPERTY(bool visible READ isVisible WRITE setVisible DESIGNABLE false)
175 Q_PROPERTY(bool minimized READ isMinimized)
176 Q_PROPERTY(bool maximized READ isMaximized)
177 Q_PROPERTY(bool fullScreen READ isFullScreen)
178 Q_PROPERTY(QSize sizeHint READ sizeHint)
179 Q_PROPERTY(QSize minimumSizeHint READ minimumSizeHint)
180 Q_PROPERTY(bool acceptDrops READ acceptDrops WRITE setAcceptDrops)
181 Q_PROPERTY(QString windowTitle READ windowTitle WRITE setWindowTitle NOTIFY windowTitleChanged)
182 Q_PROPERTY(QIcon windowIcon READ windowIcon WRITE setWindowIcon NOTIFY windowIconChanged)
183 Q_PROPERTY(QString windowIconText READ windowIconText WRITE setWindowIconText NOTIFY windowIconTextChanged) // deprecated
184 Q_PROPERTY(double windowOpacity READ windowOpacity WRITE setWindowOpacity)
185 Q_PROPERTY(bool windowModified READ isWindowModified WRITE setWindowModified)
186#if QT_CONFIG(tooltip)
187 Q_PROPERTY(QString toolTip READ toolTip WRITE setToolTip)
188 Q_PROPERTY(int toolTipDuration READ toolTipDuration WRITE setToolTipDuration)
189#endif
190#if QT_CONFIG(statustip)
191 Q_PROPERTY(QString statusTip READ statusTip WRITE setStatusTip)
192#endif
193#if QT_CONFIG(whatsthis)
194 Q_PROPERTY(QString whatsThis READ whatsThis WRITE setWhatsThis)
195#endif
196#ifndef QT_NO_ACCESSIBILITY
197 Q_PROPERTY(QString accessibleName READ accessibleName WRITE setAccessibleName)
198 Q_PROPERTY(QString accessibleDescription READ accessibleDescription WRITE setAccessibleDescription)
199#endif
200 Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection RESET unsetLayoutDirection)
201 QDOC_PROPERTY(Qt::WindowFlags windowFlags READ windowFlags WRITE setWindowFlags)
202 Q_PROPERTY(bool autoFillBackground READ autoFillBackground WRITE setAutoFillBackground)
203#ifndef QT_NO_STYLE_STYLESHEET
204 Q_PROPERTY(QString styleSheet READ styleSheet WRITE setStyleSheet)
205#endif
206 Q_PROPERTY(QLocale locale READ locale WRITE setLocale RESET unsetLocale)
207 Q_PROPERTY(QString windowFilePath READ windowFilePath WRITE setWindowFilePath)
208 Q_PROPERTY(Qt::InputMethodHints inputMethodHints READ inputMethodHints WRITE setInputMethodHints)
209
210public:
211 enum RenderFlag {
212 DrawWindowBackground = 0x1,
213 DrawChildren = 0x2,
214 IgnoreMask = 0x4
215 };
216 Q_DECLARE_FLAGS(RenderFlags, RenderFlag)
217
218 explicit QWidget(QWidget* parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags());
219 ~QWidget();
220
221 int devType() const override;
222
223 WId winId() const;
224 void createWinId(); // internal, going away
225 inline WId internalWinId() const { return data->winid; }
226 WId effectiveWinId() const;
227
228 // GUI style setting
229 QStyle *style() const;
230 void setStyle(QStyle *);
231 // Widget types and states
232
233 bool isTopLevel() const;
234 bool isWindow() const;
235
236 bool isModal() const;
237 Qt::WindowModality windowModality() const;
238 void setWindowModality(Qt::WindowModality windowModality);
239
240 bool isEnabled() const;
241 bool isEnabledTo(const QWidget *) const;
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 QPointF mapToGlobal(const QPointF &) const;
300 QPoint mapToGlobal(const QPoint &) const;
301 QPointF mapFromGlobal(const QPointF &) const;
302 QPoint mapFromGlobal(const QPoint &) const;
303 QPointF mapToParent(const QPointF &) const;
304 QPoint mapToParent(const QPoint &) const;
305 QPointF mapFromParent(const QPointF &) const;
306 QPoint mapFromParent(const QPoint &) const;
307 QPointF mapTo(const QWidget *, const QPointF &) const;
308 QPoint mapTo(const QWidget *, const QPoint &) const;
309 QPointF mapFrom(const QWidget *, const QPointF &) const;
310 QPoint mapFrom(const QWidget *, const QPoint &) const;
311
312 QWidget *window() const;
313 QWidget *nativeParentWidget() const;
314 inline QWidget *topLevelWidget() const { return window(); }
315
316 // Widget appearance functions
317 const QPalette &palette() const;
318 void setPalette(const QPalette &);
319
320 void setBackgroundRole(QPalette::ColorRole);
321 QPalette::ColorRole backgroundRole() const;
322
323 void setForegroundRole(QPalette::ColorRole);
324 QPalette::ColorRole foregroundRole() const;
325
326 const QFont &font() const;
327 void setFont(const QFont &);
328 QFontMetrics fontMetrics() const;
329 QFontInfo fontInfo() const;
330
331#ifndef QT_NO_CURSOR
332 QCursor cursor() const;
333 void setCursor(const QCursor &);
334 void unsetCursor();
335#endif
336
337 void setMouseTracking(bool enable);
338 bool hasMouseTracking() const;
339 bool underMouse() const;
340
341 void setTabletTracking(bool enable);
342 bool hasTabletTracking() const;
343
344 void setMask(const QBitmap &);
345 void setMask(const QRegion &);
346 QRegion mask() const;
347 void clearMask();
348
349 void render(QPaintDevice *target, const QPoint &targetOffset = QPoint(),
350 const QRegion &sourceRegion = QRegion(),
351 RenderFlags renderFlags = RenderFlags(DrawWindowBackground | DrawChildren));
352
353 void render(QPainter *painter, const QPoint &targetOffset = QPoint(),
354 const QRegion &sourceRegion = QRegion(),
355 RenderFlags renderFlags = RenderFlags(DrawWindowBackground | DrawChildren));
356
357 Q_INVOKABLE QPixmap grab(const QRect &rectangle = QRect(QPoint(0, 0), QSize(-1, -1)));
358
359#if QT_CONFIG(graphicseffect)
360 QGraphicsEffect *graphicsEffect() const;
361 void setGraphicsEffect(QGraphicsEffect *effect);
362#endif // QT_CONFIG(graphicseffect)
363
364#ifndef QT_NO_GESTURES
365 void grabGesture(Qt::GestureType type, Qt::GestureFlags flags = Qt::GestureFlags());
366 void ungrabGesture(Qt::GestureType type);
367#endif
368
369public Q_SLOTS:
370 void setWindowTitle(const QString &);
371#ifndef QT_NO_STYLE_STYLESHEET
372 void setStyleSheet(const QString& styleSheet);
373#endif
374public:
375#ifndef QT_NO_STYLE_STYLESHEET
376 QString styleSheet() const;
377#endif
378 QString windowTitle() const;
379 void setWindowIcon(const QIcon &icon);
380 QIcon windowIcon() const;
381 void setWindowIconText(const QString &);
382 QString windowIconText() const;
383 void setWindowRole(const QString &);
384 QString windowRole() const;
385 void setWindowFilePath(const QString &filePath);
386 QString windowFilePath() const;
387
388 void setWindowOpacity(qreal level);
389 qreal windowOpacity() const;
390
391 bool isWindowModified() const;
392#if QT_CONFIG(tooltip)
393 void setToolTip(const QString &);
394 QString toolTip() const;
395 void setToolTipDuration(int msec);
396 int toolTipDuration() const;
397#endif
398#if QT_CONFIG(statustip)
399 void setStatusTip(const QString &);
400 QString statusTip() const;
401#endif
402#if QT_CONFIG(whatsthis)
403 void setWhatsThis(const QString &);
404 QString whatsThis() const;
405#endif
406#ifndef QT_NO_ACCESSIBILITY
407 QString accessibleName() const;
408 void setAccessibleName(const QString &name);
409 QString accessibleDescription() const;
410 void setAccessibleDescription(const QString &description);
411#endif
412
413 void setLayoutDirection(Qt::LayoutDirection direction);
414 Qt::LayoutDirection layoutDirection() const;
415 void unsetLayoutDirection();
416
417 void setLocale(const QLocale &locale);
418 QLocale locale() const;
419 void unsetLocale();
420
421 inline bool isRightToLeft() const { return layoutDirection() == Qt::RightToLeft; }
422 inline bool isLeftToRight() const { return layoutDirection() == Qt::LeftToRight; }
423
424public Q_SLOTS:
425 inline void setFocus() { setFocus(Qt::OtherFocusReason); }
426
427public:
428 bool isActiveWindow() const;
429 void activateWindow();
430 void clearFocus();
431
432 void setFocus(Qt::FocusReason reason);
433 Qt::FocusPolicy focusPolicy() const;
434 void setFocusPolicy(Qt::FocusPolicy policy);
435 bool hasFocus() const;
436 static void setTabOrder(QWidget *, QWidget *);
437 void setFocusProxy(QWidget *);
438 QWidget *focusProxy() const;
439 Qt::ContextMenuPolicy contextMenuPolicy() const;
440 void setContextMenuPolicy(Qt::ContextMenuPolicy policy);
441
442 // Grab functions
443 void grabMouse();
444#ifndef QT_NO_CURSOR
445 void grabMouse(const QCursor &);
446#endif
447 void releaseMouse();
448 void grabKeyboard();
449 void releaseKeyboard();
450#ifndef QT_NO_SHORTCUT
451 int grabShortcut(const QKeySequence &key, Qt::ShortcutContext context = Qt::WindowShortcut);
452 void releaseShortcut(int id);
453 void setShortcutEnabled(int id, bool enable = true);
454 void setShortcutAutoRepeat(int id, bool enable = true);
455#endif
456 static QWidget *mouseGrabber();
457 static QWidget *keyboardGrabber();
458
459 // Update/refresh functions
460 inline bool updatesEnabled() const;
461 void setUpdatesEnabled(bool enable);
462
463#if QT_CONFIG(graphicsview)
464 QGraphicsProxyWidget *graphicsProxyWidget() const;
465#endif
466
467public Q_SLOTS:
468 void update();
469 void repaint();
470
471public:
472 inline void update(int x, int y, int w, int h);
473 void update(const QRect&);
474 void update(const QRegion&);
475
476 void repaint(int x, int y, int w, int h);
477 void repaint(const QRect &);
478 void repaint(const QRegion &);
479
480public Q_SLOTS:
481 // Widget management functions
482
483 virtual void setVisible(bool visible);
484 void setHidden(bool hidden);
485 void show();
486 void hide();
487
488 void showMinimized();
489 void showMaximized();
490 void showFullScreen();
491 void showNormal();
492
493 bool close();
494 void raise();
495 void lower();
496
497public:
498 void stackUnder(QWidget*);
499 void move(int x, int y);
500 void move(const QPoint &);
501 void resize(int w, int h);
502 void resize(const QSize &);
503 inline void setGeometry(int x, int y, int w, int h);
504 void setGeometry(const QRect &);
505 QByteArray saveGeometry() const;
506 bool restoreGeometry(const QByteArray &geometry);
507 void adjustSize();
508 bool isVisible() const;
509 bool isVisibleTo(const QWidget *) const;
510 inline bool isHidden() const;
511
512 bool isMinimized() const;
513 bool isMaximized() const;
514 bool isFullScreen() const;
515
516 Qt::WindowStates windowState() const;
517 void setWindowState(Qt::WindowStates state);
518 void overrideWindowState(Qt::WindowStates state);
519
520 virtual QSize sizeHint() const;
521 virtual QSize minimumSizeHint() const;
522
523 QSizePolicy sizePolicy() const;
524 void setSizePolicy(QSizePolicy);
525 inline void setSizePolicy(QSizePolicy::Policy horizontal, QSizePolicy::Policy vertical);
526 virtual int heightForWidth(int) const;
527 virtual bool hasHeightForWidth() const;
528
529 QRegion visibleRegion() const;
530
531 void setContentsMargins(int left, int top, int right, int bottom);
532 void setContentsMargins(const QMargins &margins);
533 QMargins contentsMargins() const;
534
535 QRect contentsRect() const;
536
537public:
538 QLayout *layout() const;
539 void setLayout(QLayout *);
540 void updateGeometry();
541
542 void setParent(QWidget *parent);
543 void setParent(QWidget *parent, Qt::WindowFlags f);
544
545 void scroll(int dx, int dy);
546 void scroll(int dx, int dy, const QRect&);
547
548 // Misc. functions
549
550 QWidget *focusWidget() const;
551 QWidget *nextInFocusChain() const;
552 QWidget *previousInFocusChain() const;
553
554 // drag and drop
555 bool acceptDrops() const;
556 void setAcceptDrops(bool on);
557
558#ifndef QT_NO_ACTION
559 //actions
560 void addAction(QAction *action);
561 void addActions(const QList<QAction*> &actions);
562 void insertActions(QAction *before, const QList<QAction*> &actions);
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 QScreen *screen() const;
602 void setScreen(QScreen *);
603
604 static QWidget *createWindowContainer(QWindow *window, QWidget *parent=nullptr, Qt::WindowFlags flags=Qt::WindowFlags());
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(QEnterEvent *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 virtual bool nativeEvent(const QByteArray &eventType, void *message, qintptr *result);
653
654 // Misc. protected functions
655 virtual void changeEvent(QEvent *);
656
657 int metric(PaintDeviceMetric) const override;
658 void initPainter(QPainter *painter) const override;
659 QPaintDevice *redirected(QPoint *offset) const override;
660 QPainter *sharedPainter() const override;
661
662 virtual void inputMethodEvent(QInputMethodEvent *);
663public:
664 virtual QVariant inputMethodQuery(Qt::InputMethodQuery) const;
665
666 Qt::InputMethodHints inputMethodHints() const;
667 void setInputMethodHints(Qt::InputMethodHints hints);
668
669protected Q_SLOTS:
670 void updateMicroFocus();
671protected:
672
673 void create(WId = 0, bool initializeWindow = true,
674 bool destroyOldWindow = true);
675 void destroy(bool destroyWindow = true,
676 bool destroySubWindows = true);
677
678 friend class QDataWidgetMapperPrivate; // for access to focusNextPrevChild
679 virtual bool focusNextPrevChild(bool next);
680 inline bool focusNextChild() { return focusNextPrevChild(true); }
681 inline bool focusPreviousChild() { return focusNextPrevChild(false); }
682
683protected:
684 QWidget(QWidgetPrivate &d, QWidget* parent, Qt::WindowFlags f);
685private:
686 void setBackingStore(QBackingStore *store);
687
688 bool testAttribute_helper(Qt::WidgetAttribute) const;
689
690 QLayout *takeLayout();
691
692 friend class QBackingStoreDevice;
693 friend class QWidgetRepaintManager;
694 friend class QApplication;
695 friend class QApplicationPrivate;
696 friend class QGuiApplication;
697 friend class QGuiApplicationPrivate;
698 friend class QBaseApplication;
699 friend class QPainter;
700 friend class QPainterPrivate;
701 friend class QPixmap; // for QPixmap::fill()
702 friend class QFontMetrics;
703 friend class QFontInfo;
704 friend class QLayout;
705 friend class QWidgetItem;
706 friend class QWidgetItemV2;
707 friend class QX11PaintEngine;
708 friend class QWin32PaintEngine;
709 friend class QShortcutPrivate;
710 friend class QWindowSurface;
711 friend class QGraphicsProxyWidget;
712 friend class QGraphicsProxyWidgetPrivate;
713 friend class QStyleSheetStyle;
714 friend struct QWidgetExceptionCleaner;
715 friend class QWidgetWindow;
716 friend class QAccessibleWidget;
717 friend class QAccessibleTable;
718 friend class QAccessibleTabButton;
719#ifndef QT_NO_GESTURES
720 friend class QGestureManager;
721 friend class QWinNativePanGestureRecognizer;
722#endif // QT_NO_GESTURES
723 friend class QWidgetEffectSourcePrivate;
724
725#ifdef Q_OS_MAC
726 friend bool qt_mac_is_metal(const QWidget *w);
727#endif
728 friend Q_WIDGETS_EXPORT QWidgetData *qt_qwidget_data(QWidget *widget);
729 friend Q_WIDGETS_EXPORT QWidgetPrivate *qt_widget_private(QWidget *widget);
730
731private:
732 Q_DISABLE_COPY(QWidget)
733 Q_PRIVATE_SLOT(d_func(), void _q_showIfNotHidden())
734 Q_PRIVATE_SLOT(d_func(), QWindow *_q_closestWindowHandle())
735
736 QWidgetData *data;
737};
738
739Q_DECLARE_OPERATORS_FOR_FLAGS(QWidget::RenderFlags)
740
741#ifndef Q_QDOC
742template <> inline QWidget *qobject_cast<QWidget*>(QObject *o)
743{
744 if (!o || !o->isWidgetType()) return nullptr;
745 return static_cast<QWidget*>(o);
746}
747template <> inline const QWidget *qobject_cast<const QWidget*>(const QObject *o)
748{
749 if (!o || !o->isWidgetType()) return nullptr;
750 return static_cast<const QWidget*>(o);
751}
752#endif // !Q_QDOC
753
754inline QWidget *QWidget::childAt(int ax, int ay) const
755{ return childAt(QPoint(ax, ay)); }
756
757inline Qt::WindowType QWidget::windowType() const
758{ return static_cast<Qt::WindowType>(int(data->window_flags & Qt::WindowType_Mask)); }
759inline Qt::WindowFlags QWidget::windowFlags() const
760{ return data->window_flags; }
761
762inline bool QWidget::isTopLevel() const
763{ return (windowType() & Qt::Window); }
764
765inline bool QWidget::isWindow() const
766{ return (windowType() & Qt::Window); }
767
768inline bool QWidget::isEnabled() const
769{ return !testAttribute(Qt::WA_Disabled); }
770
771inline bool QWidget::isModal() const
772{ return data->window_modality != Qt::NonModal; }
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