Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qwidget.cpp
Go to the documentation of this file.
1// Copyright (C) 2017 The Qt Company Ltd.
2// Copyright (C) 2016 Intel Corporation.
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4
5#include "qapplication.h"
6#include "qapplication_p.h"
7#include "qbrush.h"
8#include "qcursor.h"
9#include "private/qduplicatetracker_p.h"
10#include "qevent.h"
11#include "qlayout.h"
12#if QT_CONFIG(menu)
13#include "qmenu.h"
14#endif
15#include "qmetaobject.h"
16#include "qpixmap.h"
17#include "qpointer.h"
18#include "qstack.h"
19#include "qstyle.h"
20#include "qstylefactory.h"
21#include "qvariant.h"
22#include "qwidget.h"
23#include "qstyleoption.h"
24#include "qstylehints.h"
25#if QT_CONFIG(accessibility)
26# include "qaccessible.h"
27#endif
28#include <qpa/qplatformwindow.h>
29#include <qpa/qplatformwindow_p.h>
30#include "private/qwidgetwindow_p.h"
31#include "qpainter.h"
32#if QT_CONFIG(tooltip)
33#include "qtooltip.h"
34#endif
35#if QT_CONFIG(whatsthis)
36#include "qwhatsthis.h"
37#endif
38#include "qdebug.h"
39#include "private/qstylesheetstyle_p.h"
40#include "private/qstyle_p.h"
41#include "qfileinfo.h"
42#include "qscopeguard.h"
43#include <QtGui/private/qhighdpiscaling_p.h>
44#include <QtGui/qinputmethod.h>
45
46#if QT_CONFIG(graphicseffect)
47#include <private/qgraphicseffect_p.h>
48#endif
49#include <qbackingstore.h>
50#include <private/qwidgetrepaintmanager_p.h>
51#include <private/qpaintengine_raster_p.h>
52
53#include "qwidget_p.h"
54#include <QtGui/private/qwindow_p.h>
55#if QT_CONFIG(action)
56# include "QtGui/private/qaction_p.h"
57#endif
58#include "qlayout_p.h"
59#if QT_CONFIG(graphicsview)
60#include "QtWidgets/qgraphicsproxywidget.h"
61#include "QtWidgets/qgraphicsscene.h"
62#include "private/qgraphicsproxywidget_p.h"
63#endif
64#include "QtWidgets/qabstractscrollarea.h"
65#include "private/qabstractscrollarea_p.h"
66#include "private/qevent_p.h"
67
68#include "private/qgesturemanager_p.h"
69
70#ifdef QT_KEYPAD_NAVIGATION
71#if QT_CONFIG(tabwidget)
72#include "qtabwidget.h" // Needed in inTabWidget()
73#endif
74#endif // QT_KEYPAD_NAVIGATION
75
76#include "qwindowcontainer_p.h"
77
78#include <sstream>
79
81
82using namespace QNativeInterface::Private;
83using namespace Qt::StringLiterals;
84
85Q_LOGGING_CATEGORY(lcWidgetPainting, "qt.widgets.painting", QtWarningMsg);
86Q_LOGGING_CATEGORY(lcWidgetShowHide, "qt.widgets.showhide", QtWarningMsg);
87Q_STATIC_LOGGING_CATEGORY(lcWidgetWindow, "qt.widgets.window", QtWarningMsg);
88Q_STATIC_LOGGING_CATEGORY(lcWidgetFocus, "qt.widgets.focus")
89
90#ifndef QT_NO_DEBUG_STREAM
91namespace {
92 struct WidgetAttributes { const QWidget *widget; };
93 QDebug operator<<(QDebug debug, const WidgetAttributes &attributes);
94}
95#endif
96
97static inline bool qRectIntersects(const QRect &r1, const QRect &r2)
98{
99 return (qMax(r1.left(), r2.left()) <= qMin(r1.right(), r2.right()) &&
100 qMax(r1.top(), r2.top()) <= qMin(r1.bottom(), r2.bottom()));
101}
102
103extern bool qt_sendSpontaneousEvent(QObject*, QEvent*); // qapplication.cpp
104
106 : QObjectPrivate(version)
107 , focus_next(nullptr)
108 , focus_prev(nullptr)
109 , focus_child(nullptr)
110 , layout(nullptr)
111 , needsFlush(nullptr)
112 , redirectDev(nullptr)
113 , widgetItem(nullptr)
114 , extraPaintEngine(nullptr)
115 , polished(nullptr)
116 , graphicsEffect(nullptr)
117#if !defined(QT_NO_IM)
118 , imHints(Qt::ImhNone)
119#endif
120#if QT_CONFIG(tooltip)
121 , toolTipDuration(-1)
122#endif
123 , directFontResolveMask(0)
124 , inheritedFontResolveMask(0)
125 , directPaletteResolveMask(0)
126 , inheritedPaletteResolveMask(0)
127 , leftmargin(0)
128 , topmargin(0)
129 , rightmargin(0)
130 , bottommargin(0)
131 , leftLayoutItemMargin(0)
132 , topLayoutItemMargin(0)
133 , rightLayoutItemMargin(0)
134 , bottomLayoutItemMargin(0)
135 , hd(nullptr)
136 , size_policy(QSizePolicy::Preferred, QSizePolicy::Preferred)
137 , fg_role(QPalette::NoRole)
138 , bg_role(QPalette::NoRole)
139 , dirtyOpaqueChildren(1)
140 , isOpaque(0)
141 , retainSizeWhenHiddenChanged(0)
142 , inDirtyList(0)
143 , isScrolled(0)
144 , isMoved(0)
145 , usesDoubleBufferedGLContext(0)
146 , mustHaveWindowHandle(0)
147 , renderToTexture(0)
148 , textureChildSeen(0)
149#ifndef QT_NO_IM
150 , inheritsInputMethodHints(0)
151#endif
152 , renderToTextureReallyDirty(1)
153 , usesRhiFlush(0)
154 , childrenHiddenByWState(0)
155 , childrenShownByExpose(0)
156#if defined(Q_OS_WIN)
157 , noPaintOnScreen(0)
158#endif
159{
160 if (Q_UNLIKELY(!qApp)) {
161 qFatal("QWidget: Must construct a QApplication before a QWidget");
162 return;
163 }
164
165#ifdef QT_BUILD_INTERNAL
166 // Don't check the version parameter in internal builds.
167 // This allows incompatible versions to be loaded, possibly for testing.
168 Q_UNUSED(version);
169#else
170 if (Q_UNLIKELY(version != QObjectPrivateVersion))
171 qFatal("Cannot mix incompatible Qt library (version 0x%x) with this library (version 0x%x)",
172 version, QObjectPrivateVersion);
173#endif
174
175 willBeWidget = true; // used in QObject's ctor
176 memset(high_attributes, 0, sizeof(high_attributes));
177
178#ifdef QWIDGET_EXTRA_DEBUG
179 static int count = 0;
180 qDebug() << "widgets" << ++count;
181#endif
182}
183
184
186{
187 if (widgetItem)
188 widgetItem->wid = nullptr;
189
190 if (extra)
191 deleteExtra();
192}
193
198{
199 Q_Q(QWidget);
200 if (q->children().size() > 0) { // scroll children
201 QPoint pd(dx, dy);
202 QObjectList childObjects = q->children();
203 for (int i = 0; i < childObjects.size(); ++i) { // move all children
204 QWidget *w = qobject_cast<QWidget*>(childObjects.at(i));
205 if (w && !w->isWindow()) {
206 QPoint oldp = w->pos();
207 QRect r(w->pos() + pd, w->size());
208 w->data->crect = r;
209 if (w->testAttribute(Qt::WA_WState_Created))
210 w->d_func()->setWSGeometry();
211 w->d_func()->setDirtyOpaqueRegion();
212 QMoveEvent e(r.topLeft(), oldp);
214 }
215 }
216 }
217}
218
220{
221 Q_Q(QWidget);
222 if (QWindow *window = q->windowHandle())
223 window->setGeometry(data.crect);
224}
225
227{
228 Q_Q(QWidget);
229 if (q == QGuiApplication::focusObject() || event->type() == QEvent::FocusIn) {
231 QPoint p = q->mapTo(q->topLevelWidget(), QPoint(0,0));
232 t.translate(p.x(), p.y());
233 QGuiApplication::inputMethod()->setInputItemTransform(t);
234 QGuiApplication::inputMethod()->setInputItemRectangle(q->rect());
236 }
237}
238
239#ifdef QT_KEYPAD_NAVIGATION
240QPointer<QWidget> QWidgetPrivate::editingWidget;
241
249bool QWidget::hasEditFocus() const
250{
251 const QWidget* w = this;
252 while (w->d_func()->extra && w->d_func()->extra->focus_proxy)
253 w = w->d_func()->extra->focus_proxy;
254 return QWidgetPrivate::editingWidget == w;
255}
256
269void QWidget::setEditFocus(bool on)
270{
271 QWidget *f = this;
272 while (f->d_func()->extra && f->d_func()->extra->focus_proxy)
273 f = f->d_func()->extra->focus_proxy;
274
275 if (QWidgetPrivate::editingWidget && QWidgetPrivate::editingWidget != f)
276 QWidgetPrivate::editingWidget->setEditFocus(false);
277
278 if (on && !f->hasFocus())
279 f->setFocus();
280
281 if ((!on && !QWidgetPrivate::editingWidget)
282 || (on && QWidgetPrivate::editingWidget == f)) {
283 return;
284 }
285
286 if (!on && QWidgetPrivate::editingWidget == f) {
287 QWidgetPrivate::editingWidget = 0;
288 QEvent event(QEvent::LeaveEditFocus);
291 } else if (on) {
292 QWidgetPrivate::editingWidget = f;
293 QEvent event(QEvent::EnterEditFocus);
296 }
297}
298#endif
299
325{
326 Q_D(const QWidget);
327 return d->extra && d->extra->autoFillBackground;
328}
329
331{
332 Q_D(QWidget);
333 if (!d->extra)
334 d->createExtra();
335 if (d->extra->autoFillBackground == enabled)
336 return;
337
338 d->extra->autoFillBackground = enabled;
339 d->updateIsOpaque();
340 update();
341 d->updateIsOpaque();
342}
343
789QWidgetMapper *QWidgetPrivate::mapper = nullptr; // widget with wid
790QWidgetSet *QWidgetPrivate::allWidgets = nullptr; // widgets with no wid
791
792
793/*****************************************************************************
794 QWidget member functions
795 *****************************************************************************/
796
797/*
798 Widget state flags:
799 \list
800 \li Qt::WA_WState_Created The widget has a valid winId().
801 \li Qt::WA_WState_Visible The widget is currently visible.
802 \li Qt::WA_WState_Hidden The widget is hidden, i.e. it won't
803 become visible unless you call show() on it. Qt::WA_WState_Hidden
804 implies !Qt::WA_WState_Visible.
805 \li Qt::WA_WState_CompressKeys Compress keyboard events.
806 \li Qt::WA_WState_BlockUpdates Repaints and updates are disabled.
807 \li Qt::WA_WState_InPaintEvent Currently processing a paint event.
808 \li Qt::WA_WState_Reparented The widget has been reparented.
809 \li Qt::WA_WState_ConfigPending A configuration (resize/move) event is pending.
810 \endlist
811*/
812
814{
815 /* this cleans up when the constructor throws an exception */
816 static inline void cleanup(QWidget *that, QWidgetPrivate *d)
817 {
818#ifdef QT_NO_EXCEPTIONS
819 Q_UNUSED(that);
820 Q_UNUSED(d);
821#else
822 QWidgetPrivate::allWidgets->remove(that);
823 d->removeFromFocusChain();
824#endif
825 }
826};
827
853QWidget::QWidget(QWidget *parent, Qt::WindowFlags f)
855{
856 QT_TRY {
857 d_func()->init(parent, f);
858 } QT_CATCH(...) {
859 QWidgetExceptionCleaner::cleanup(this, d_func());
861 }
862}
863
864
867QWidget::QWidget(QWidgetPrivate &dd, QWidget* parent, Qt::WindowFlags f)
869{
870 Q_D(QWidget);
871 QT_TRY {
872 d->init(parent, f);
873 } QT_CATCH(...) {
874 QWidgetExceptionCleaner::cleanup(this, d_func());
876 }
877}
878
883{
884 return QInternal::Widget;
885}
886
887
888//### w is a "this" ptr, passed as a param because QWorkspace needs special logic
890{
891 bool customize = (flags & (Qt::CustomizeWindowHint
899
901
902 if ((type == Qt::Widget || type == Qt::SubWindow) && w && !w->parent()) {
904 flags |= Qt::Window;
905 }
906
908 // modify window flags to make them consistent.
909 // Only enable this on non-Mac platforms. Since the old way of doing this would
910 // interpret WindowSystemMenuHint as a close button and we can't change that behavior
911 // we can't just add this in.
913# ifdef Q_OS_WIN
914 && type != Qt::Dialog // QTBUG-2027, allow for menu-less dialogs.
915# endif
916 ) {
919 flags &= ~Qt::FramelessWindowHint;
920 }
921 } else if (customize && !(flags & Qt::FramelessWindowHint)) {
922 // if any of the window hints that affect the titlebar are set
923 // and the window is supposed to have frame, we add a titlebar
924 // and system menu by default.
927 }
928 if (!customize) { // don't modify window flags if the user explicitly set them.
930 if (type != Qt::Dialog && type != Qt::Sheet && type != Qt::Tool)
932 }
933 if (w->testAttribute(Qt::WA_TransparentForMouseEvents))
935}
936
937void QWidgetPrivate::init(QWidget *parentWidget, Qt::WindowFlags f)
938{
939 Q_Q(QWidget);
940 isWidget = true;
941 wasWidget = true;
942
943 Q_ASSERT_X(q != parentWidget, Q_FUNC_INFO, "Cannot parent a QWidget to itself");
944
945 if (Q_UNLIKELY(!qobject_cast<QApplication *>(QCoreApplication::instance())))
946 qFatal("QWidget: Cannot create a QWidget without QApplication");
947
949 if (allWidgets)
950 allWidgets->insert(q);
951
952 q->data = &data;
953
954#if QT_CONFIG(thread)
955 if (!parent) {
956 Q_ASSERT_X(q->thread() == qApp->thread(), "QWidget",
957 "Widgets must be created in the GUI thread.");
958 }
959#endif
960
961 data.fstrut_dirty = true;
962
963 data.winid = 0;
964 data.widget_attributes = 0;
965 data.window_flags = f;
966 data.window_state = 0;
967 data.focus_policy = 0;
968 data.context_menu_policy = Qt::DefaultContextMenu;
969 data.window_modality = Qt::NonModal;
970
971 data.sizehint_forced = 0;
972 data.is_closing = false;
973 data.in_show = 0;
974 data.in_set_window_state = 0;
975 data.in_destructor = false;
976
977 // Widgets with Qt::MSWindowsOwnDC (typically QGLWidget) must have a window handle.
978 if (f & Qt::MSWindowsOwnDC) {
980 q->setAttribute(Qt::WA_NativeWindow);
981 }
982
983 q->setAttribute(Qt::WA_QuitOnClose); // might be cleared in adjustQuitOnCloseAttribute()
985
987 q->setAttribute(Qt::WA_WState_Hidden);
988
989 //give potential windows a bigger "pre-initial" size; create() will give them a new size later
990 data.crect = parentWidget ? QRect(0,0,100,30) : QRect(0,0,640,480);
992
994 q->create();
995 else if (parentWidget)
996 q->setParent(parentWidget, data.window_flags);
997 else {
998 adjustFlags(data.window_flags, q);
1000 // opaque system background?
1001 const QBrush &background = q->palette().brush(QPalette::Window);
1002 setOpaque(q->isWindow() && background.style() != Qt::NoBrush && background.isOpaque());
1003 }
1004 data.fnt = QFont(data.fnt, q);
1005
1006 q->setAttribute(Qt::WA_PendingMoveEvent);
1007 q->setAttribute(Qt::WA_PendingResizeEvent);
1008
1011
1015
1016 extraPaintEngine = nullptr;
1017}
1018
1020{
1021 Q_Q(QWidget);
1022 q->create(0, true, true);
1023 for (int i = 0; i < children.size(); ++i) {
1025 if (child && !child->isHidden() && !child->isWindow() && !child->testAttribute(Qt::WA_WState_Created))
1026 child->d_func()->createRecursively();
1027 }
1028}
1029
1031{
1032 Q_Q(const QWidget);
1033 if (auto *backingStore = q->backingStore()) {
1035 return backingStore->handle()->rhi(window);
1036 } else {
1037 return nullptr;
1038 }
1039}
1040
1050{
1051 Q_Q(const QWidget);
1052 QWidget *parent = q->parentWidget();
1053 while (parent && !parent->windowHandle())
1054 parent = parent->parentWidget();
1055 return parent;
1056}
1057
1059{
1061 if (QTLWExtra *x = maybeTopData()) {
1062 if (x->window != nullptr || mode == WindowHandleMode::Direct)
1063 return x->window;
1064 }
1065 }
1067 // FIXME: Use closestParentWidgetWithWindowHandle instead
1068 if (auto nativeParent = q_func()->nativeParentWidget()) {
1069 if (auto window = nativeParent->windowHandle())
1070 return window;
1071 }
1072 }
1074 if (auto topLevel = q_func()->topLevelWidget()) {
1075 if (auto window = topLevel ->windowHandle())
1076 return window;
1077 }
1078 }
1079 return nullptr;
1080}
1081
1092
1094{
1095#if QT_CONFIG(graphicsview)
1096 // embedded widgets never have a screen associated, let QWidget::screen fall back to toplevel
1097 if (nearestGraphicsProxyWidget(q_func()))
1098 return nullptr;
1099#endif
1101 return window->screen();
1102 return nullptr;
1103}
1104
1105// finds the first rhiconfig in the hierarchy that has enable==true
1107{
1109 if (config.isEnabled()) {
1110 if (outConfig)
1111 *outConfig = config;
1112 if (outType)
1114 return true;
1115 }
1116 for (const QObject *child : w->children()) {
1117 if (const QWidget *childWidget = qobject_cast<const QWidget *>(child)) {
1118 if (q_evaluateRhiConfigRecursive(childWidget, outConfig, outType)) {
1119 static bool optOut = qEnvironmentVariableIsSet("QT_WIDGETS_NO_CHILD_RHI");
1120 // Native child widgets should not trigger RHI for its parent
1121 // hierarchy, but will still flush the native child using RHI.
1122 if (!optOut && childWidget->testAttribute(Qt::WA_NativeWindow))
1123 continue;
1124
1125 return true;
1126 }
1127 }
1128 }
1129 return false;
1130}
1131
1133{
1134 // First, check env.vars. or other means that force the usage of rhi-based
1135 // flushing with a specific graphics API. This takes precedence over what
1136 // the widgets themselves declare. This is global, applying to all
1137 // top-levels.
1138 if (QBackingStoreRhiSupport::checkForceRhi(outConfig, outType)) {
1139 qCDebug(lcWidgetPainting) << "Tree with root" << w << "evaluated to forced flushing with QRhi";
1140 return true;
1141 }
1142
1143 // Otherwise, check the widget hierarchy to see if there is a child (or
1144 // ourselves) that declare the need for rhi-based composition.
1145 if (q_evaluateRhiConfigRecursive(w, outConfig, outType)) {
1146 qCDebug(lcWidgetPainting) << "Tree with root" << w << "evaluates to flushing with QRhi";
1147 return true;
1148 }
1149
1150 return false;
1151}
1152
1153// ### fixme: Qt 6: Remove parameter window from QWidget::create()
1154
1166void QWidget::create(WId window, bool initializeWindow, bool destroyOldWindow)
1167{
1168 Q_UNUSED(initializeWindow);
1169 Q_UNUSED(destroyOldWindow);
1170
1171 Q_D(QWidget);
1172 if (Q_UNLIKELY(window))
1173 qWarning("QWidget::create(): Parameter 'window' does not have any effect.");
1175 return;
1176
1177 if (d->data.in_destructor)
1178 return;
1179
1181 Qt::WindowFlags &flags = data->window_flags;
1182
1183 if ((type == Qt::Widget || type == Qt::SubWindow) && !parentWidget()) {
1184 type = Qt::Window;
1185 flags |= Qt::Window;
1186 }
1187
1188 if (QWidget *parent = parentWidget()) {
1189 if (type & Qt::Window) {
1190 if (!parent->testAttribute(Qt::WA_WState_Created))
1191 parent->createWinId();
1192 } else if (testAttribute(Qt::WA_NativeWindow) && !parent->internalWinId()
1194 // We're about to create a native child widget that doesn't have a native parent;
1195 // enforce a native handle for the parent unless the Qt::WA_DontCreateNativeAncestors
1196 // attribute is set.
1197 d->createWinId();
1198 // Nothing more to do.
1201 return;
1202 }
1203 }
1204
1205
1206 static const bool paintOnScreenEnv = qEnvironmentVariableIntValue("QT_ONSCREEN_PAINT") > 0;
1207 if (paintOnScreenEnv)
1209
1212
1213 d->updateIsOpaque();
1214
1215 setAttribute(Qt::WA_WState_Created); // set created flag
1216 d->create();
1217
1218 // A real toplevel window needs a paint manager
1219 if (isWindow() && windowType() != Qt::Desktop)
1220 d->topData()->repaintManager.reset(new QWidgetRepaintManager(this));
1221
1222 d->setModal_sys();
1223
1226
1227 // need to force the resting of the icon after changing parents
1229 d->setWindowIcon_sys();
1230
1231 if (isWindow() && !d->topData()->iconText.isEmpty())
1232 d->setWindowIconText_helper(d->topData()->iconText);
1233 if (isWindow() && !d->topData()->caption.isEmpty())
1234 d->setWindowTitle_helper(d->topData()->caption);
1235 if (isWindow() && !d->topData()->filePath.isEmpty())
1236 d->setWindowFilePath_helper(d->topData()->filePath);
1237 if (windowType() != Qt::Desktop) {
1238 d->updateSystemBackground();
1239
1241 d->setWindowIcon_sys();
1242 }
1243
1244 // Frame strut update needed in cases where there are native widgets such as QGLWidget,
1245 // as those force native window creation on their ancestors before they are shown.
1246 // If the strut is not updated, any subsequent move of the top level window before show
1247 // will cause window frame to be ignored when positioning the window.
1248 // Note that this only helps on platforms that handle window creation synchronously.
1249 d->updateFrameStrut();
1250}
1251
1253{
1254 QObjectList children = parentWidget->children();
1255 for (int i = 0; i < children.size(); i++) {
1256 if (children.at(i)->isWidgetType()) {
1257 const QWidget *childWidget = qobject_cast<const QWidget *>(children.at(i));
1258 if (childWidget) { // should not be necessary
1259 if (childWidget->testAttribute(Qt::WA_NativeWindow)) {
1260 if (!childWidget->internalWinId())
1261 childWidget->winId();
1262 if (childWidget->windowHandle()) {
1263 if (childWidget->isWindow()) {
1264 childWidget->windowHandle()->setTransientParent(parentWidget->window()->windowHandle());
1265 } else {
1266 childWidget->windowHandle()->setParent(childWidget->nativeParentWidget()->windowHandle());
1267 }
1268 }
1269 } else {
1271 }
1272 }
1273 }
1274 }
1275
1276}
1277
1279{
1280 Q_Q(QWidget);
1281
1282 if (!q->testAttribute(Qt::WA_NativeWindow) && !q->isWindow())
1283 return; // we only care about real toplevels
1284
1286 // topData() ensures the extra is created but does not ensure 'window' is non-null
1287 // in case the extra was already valid.
1288 if (!win) {
1291 win = topData()->window;
1292 }
1293
1294 const auto dynamicPropertyNames = q->dynamicPropertyNames();
1295 for (const QByteArray &propertyName : dynamicPropertyNames) {
1296 if (!qstrncmp(propertyName, "_q_platform_", 12))
1297 win->setProperty(propertyName, q->property(propertyName));
1298 }
1299
1300 Qt::WindowFlags &flags = data.window_flags;
1301
1302#if defined(QT_PLATFORM_UIKIT)
1303 if (q->testAttribute(Qt::WA_ContentsMarginsRespectsSafeArea))
1305#endif
1306
1307 if (q->testAttribute(Qt::WA_ShowWithoutActivating))
1308 win->setProperty("_q_showWithoutActivating", QVariant(true));
1309 if (q->testAttribute(Qt::WA_MacAlwaysShowToolWindow))
1310 win->setProperty("_q_macAlwaysShowToolWindow", QVariant(true));
1311 win->setFlags(flags);
1313 if (q->testAttribute(Qt::WA_Moved)
1315 win->setGeometry(q->geometry());
1316 else
1317 win->resize(q->size());
1318 if (win->isTopLevel()) {
1319 QScreen *targetScreen = topData()->initialScreen;
1320 topData()->initialScreen = nullptr;
1321 if (!targetScreen) {
1322 targetScreen = q->windowType() != Qt::Desktop
1323 ? q->screen() : nullptr;
1324 }
1325 win->setScreen(targetScreen);
1326 }
1327
1328 QSurfaceFormat format = win->requestedFormat();
1329 if ((flags & Qt::Window) && win->surfaceType() != QSurface::OpenGLSurface
1331 format.setAlphaBufferSize(8);
1332 }
1333 win->setFormat(format);
1334
1335 if (QWidget *nativeParent = q->nativeParentWidget()) {
1336 if (nativeParent->windowHandle()) {
1337 if (flags & Qt::Window) {
1338 win->setTransientParent(nativeParent->window()->windowHandle());
1339 win->setParent(nullptr);
1340 } else {
1341 win->setTransientParent(nullptr);
1342 win->setParent(nativeParent->windowHandle());
1343 }
1344 }
1345 }
1346
1347 qt_window_private(win)->positionPolicy = topData()->posIncludesFrame ?
1349
1350 if (q->windowType() != Qt::Desktop || q->testAttribute(Qt::WA_NativeWindow)) {
1351 win->create();
1352 // Enable nonclient-area events for QDockWidget and other NonClientArea-mouse event processing.
1353 if (QPlatformWindow *platformWindow = win->handle())
1354 platformWindow->setFrameStrutEventsEnabled(true);
1355 }
1356
1357 data.window_flags = win->flags();
1358
1359#if QT_CONFIG(xcb)
1360 if (!topData()->role.isNull()) {
1361 if (auto *xcbWindow = dynamic_cast<QXcbWindow*>(win->handle()))
1362 xcbWindow->setWindowRole(topData()->role);
1363 }
1364#endif
1365
1366 QBackingStore *store = q->backingStore();
1367 usesRhiFlush = false;
1368
1369 if (q->windowType() == Qt::Desktop) {
1370 q->setAttribute(Qt::WA_PaintOnScreen, true);
1371 } else {
1372 if (!store && q->isWindow())
1373 q->setBackingStore(new QBackingStore(win));
1374
1377 if (usesRhiFlush && q->backingStore()) {
1378 // Trigger creation of support infrastructure up front,
1379 // now that we have a specific RHI configuration.
1380 q->backingStore()->handle()->createRhi(win, rhiConfig);
1381 }
1382 }
1383
1385
1386 if (win->handle()) {
1387 WId id = win->winId();
1388 // See the QPlatformWindow::winId() documentation
1389 Q_ASSERT(id != WId(0));
1390 setWinId(id);
1391 }
1392 setNetWmWindowTypes(true); // do nothing if none of WA_X11NetWmWindowType* is set
1393
1394 // Check children and create windows for them if necessary
1396
1397 if (extra && !extra->mask.isEmpty())
1398 setMask_sys(extra->mask);
1399
1400 if (data.crect.width() == 0 || data.crect.height() == 0) {
1401 q->setAttribute(Qt::WA_OutsideWSRange, true);
1402 } else if (q->isVisible()) {
1403 // If widget is already shown, set window visible, too
1404 win->setNativeWindowVisibility(true);
1405 }
1406}
1407
1408#ifdef Q_OS_WIN
1409static const char activeXNativeParentHandleProperty[] = "_q_embedded_native_parent_handle";
1410#endif
1411
1413{
1414 Q_Q(QWidget);
1415 if (!extra->topextra->window && (q->testAttribute(Qt::WA_NativeWindow) || q->isWindow())) {
1416 extra->topextra->window = new QWidgetWindow(q);
1417 if (extra->minw || extra->minh)
1418 extra->topextra->window->setMinimumSize(QSize(extra->minw, extra->minh));
1419 if (extra->maxw != QWIDGETSIZE_MAX || extra->maxh != QWIDGETSIZE_MAX)
1420 extra->topextra->window->setMaximumSize(QSize(extra->maxw, extra->maxh));
1421 if (extra->topextra->opacity != 255 && q->isWindow())
1422 extra->topextra->window->setOpacity(qreal(extra->topextra->opacity) / qreal(255));
1423
1424 const bool isTipLabel = q->inherits("QTipLabel");
1425 const bool isAlphaWidget = !isTipLabel && q->inherits("QAlphaWidget");
1426#ifdef Q_OS_WIN
1427 // Pass on native parent handle for Widget embedded into Active X.
1428 const QVariant activeXNativeParentHandle = q->property(activeXNativeParentHandleProperty);
1429 if (activeXNativeParentHandle.isValid())
1430 extra->topextra->window->setProperty(activeXNativeParentHandleProperty, activeXNativeParentHandle);
1431 if (isTipLabel || isAlphaWidget)
1432 extra->topextra->window->setProperty("_q_windowsDropShadow", QVariant(true));
1433#endif
1434 if (isTipLabel || isAlphaWidget || q->inherits("QRollEffect"))
1435 qt_window_private(extra->topextra->window)->setAutomaticPositionAndResizeEnabled(false);
1436
1438 }
1439
1440}
1441
1450{
1451 Q_D(QWidget);
1452 d->data.in_destructor = true;
1453
1454#if defined (QT_CHECK_STATE)
1456 qWarning("QWidget: %s (%s) deleted while being painted", className(), name());
1457#endif
1458
1459#ifndef QT_NO_GESTURES
1461 // \forall Qt::GestureType type : ungrabGesture(type) (inlined)
1462 for (auto it = d->gestureContext.keyBegin(), end = d->gestureContext.keyEnd(); it != end; ++it)
1463 manager->cleanupCachedGestures(this, *it);
1464 }
1465 d->gestureContext.clear();
1466#endif
1467
1468#ifndef QT_NO_ACTION
1469 // remove all actions from this widget
1470 for (auto action : std::as_const(d->actions)) {
1471 QActionPrivate *apriv = action->d_func();
1472 apriv->associatedObjects.removeAll(this);
1473 }
1474 d->actions.clear();
1475#endif
1476
1477#ifndef QT_NO_SHORTCUT
1478 // Remove all shortcuts grabbed by this
1479 // widget, unless application is closing
1481 QGuiApplicationPrivate::instance()->shortcutMap.removeShortcut(0, this, QKeySequence());
1482#endif
1483
1484 // delete layout while we still are a valid widget
1485 delete d->layout;
1486 d->layout = nullptr;
1487
1488 // Remove this from focus list
1490
1491 QT_TRY {
1492#if QT_CONFIG(graphicsview)
1493 const QWidget* w = this;
1494 while (w->d_func()->extra && w->d_func()->extra->focus_proxy)
1495 w = w->d_func()->extra->focus_proxy;
1496 QWidget *window = w->window();
1497 QWExtra *e = window ? window->d_func()->extra.get() : nullptr ;
1498 if (!e || !e->proxyWidget || (w->parentWidget() && w->parentWidget()->d_func()->focus_child == this))
1499#endif
1500 clearFocus();
1501 } QT_CATCH(...) {
1502 // swallow this problem because we are in a destructor
1503 }
1504
1505 d->setDirtyOpaqueRegion();
1506
1507 if (isWindow() && isVisible() && internalWinId()) {
1508 QT_TRY {
1509 d->close();
1510 } QT_CATCH(...) {
1511 // if we're out of memory, at least hide the window.
1512 QT_TRY {
1513 hide();
1514 } QT_CATCH(...) {
1515 // and if that also doesn't work, then give up
1516 }
1517 }
1518 } else if (isVisible()) {
1519 qApp->d_func()->sendSyntheticEnterLeave(this);
1520 }
1521
1522 if (QWidgetRepaintManager *repaintManager = d->maybeRepaintManager()) {
1523 repaintManager->removeDirtyWidget(this);
1525 repaintManager->removeStaticWidget(this);
1526 }
1527
1528 delete d->needsFlush;
1529 d->needsFlush = nullptr;
1530
1531 // The next 20 lines are duplicated from QObject, but required here
1532 // since QWidget deletes is children itself
1533 bool blocked = d->blockSig;
1534 d->blockSig = 0; // unblock signals so we always emit destroyed()
1535
1536 if (d->isSignalConnected(0)) {
1537 QT_TRY {
1538 emit destroyed(this);
1539 } QT_CATCH(...) {
1540 // all the signal/slots connections are still in place - if we don't
1541 // quit now, we will crash pretty soon.
1542 qWarning("Detected an unexpected exception in ~QWidget while emitting destroyed().");
1543 QT_RETHROW;
1544 }
1545 }
1546
1547 if (d->declarativeData) {
1548 d->wasDeleted = true; // needed, so that destroying the declarative data does the right thing
1550 QAbstractDeclarativeData::destroyed(d->declarativeData, this);
1551 d->declarativeData = nullptr; // don't activate again in ~QObject
1552 d->wasDeleted = false;
1553 }
1554
1555 d->blockSig = blocked;
1556
1557 if (!d->children.isEmpty())
1558 d->deleteChildren();
1559
1561
1562 QT_TRY {
1563 destroy(); // platform-dependent cleanup
1564 } QT_CATCH(...) {
1565 // if this fails we can't do anything about it but at least we are not allowed to throw.
1566 }
1568
1569 if (QWidgetPrivate::allWidgets) // might have been deleted by ~QApplication
1570 QWidgetPrivate::allWidgets->remove(this);
1571
1572 QT_TRY {
1575 } QT_CATCH(const std::exception&) {
1576 // if this fails we can't do anything about it but at least we are not allowed to throw.
1577 }
1578
1579#if QT_CONFIG(graphicseffect)
1580 delete d->graphicsEffect;
1581#endif
1582
1583 d->isWidget = false;
1584}
1585
1586int QWidgetPrivate::instanceCounter = 0; // Current number of widget instances
1587int QWidgetPrivate::maxInstances = 0; // Maximum number of widget instances
1588
1589void QWidgetPrivate::setWinId(WId id) // set widget identifier
1590{
1591 Q_Q(QWidget);
1592 if (mapper && data.winid) {
1593 mapper->remove(data.winid);
1594 }
1595
1596 const WId oldWinId = data.winid;
1597
1598 data.winid = id;
1599 if (mapper && id) {
1600 mapper->insert(data.winid, q);
1601 }
1602
1603 if (oldWinId != id) {
1606 }
1607}
1608
1610{
1611 if (!extra)
1612 createExtra();
1613 if (!extra->topextra) {
1614 extra->topextra = std::make_unique<QTLWExtra>();
1615 QTLWExtra* x = extra->topextra.get();
1616 x->backingStore = nullptr;
1617 x->sharedPainter = nullptr;
1618 x->incw = x->inch = 0;
1619 x->basew = x->baseh = 0;
1620 x->frameStrut.setCoords(0, 0, 0, 0);
1621 x->normalGeometry = QRect(0,0,-1,-1);
1622 x->savedFlags = { };
1623 x->opacity = 255;
1624 x->posIncludesFrame = 0;
1625 x->sizeAdjusted = false;
1626 x->embedded = 0;
1627 x->window = nullptr;
1628 x->initialScreen = nullptr;
1629
1630#ifdef QWIDGET_EXTRA_DEBUG
1631 static int count = 0;
1632 qDebug() << "tlextra" << ++count;
1633#endif
1634 }
1635}
1636
1643{
1644 if (!extra) { // if not exists
1645 extra = std::make_unique<QWExtra>();
1646 extra->glContext = nullptr;
1647#if QT_CONFIG(graphicsview)
1648 extra->proxyWidget = nullptr;
1649#endif
1650 extra->minw = 0;
1651 extra->minh = 0;
1652 extra->maxw = QWIDGETSIZE_MAX;
1653 extra->maxh = QWIDGETSIZE_MAX;
1654 extra->customDpiX = 0;
1655 extra->customDpiY = 0;
1656 extra->explicitMinSize = 0;
1657 extra->explicitMaxSize = 0;
1658 extra->autoFillBackground = 0;
1659 extra->nativeChildrenForced = 0;
1660 extra->inRenderWithPainter = 0;
1661 extra->hasWindowContainer = false;
1662 extra->hasMask = 0;
1664#ifdef QWIDGET_EXTRA_DEBUG
1665 static int count = 0;
1666 qDebug() << "extra" << ++count;
1667#endif
1668 }
1669}
1670
1674
1681{
1682 if (extra) { // if exists
1684#ifndef QT_NO_STYLE_STYLESHEET
1685 // dereference the stylesheet style
1687 proxy->deref();
1688#endif
1689 if (extra->topextra)
1691
1692 // extra->xic destroyed in QWidget::destroy()
1693 extra.reset();
1694 }
1695}
1696
1700
1702{
1703 Q_Q(QWidget);
1704 if (extra && extra->topextra) {
1705 if (extra->hasWindowContainer)
1707
1708 delete extra->topextra->window;
1709 extra->topextra->window = nullptr;
1710 }
1711}
1712
1713/*
1714 Returns \c region of widgets above this which overlap with
1715 \a rect, which is in parent's coordinate system (same as crect).
1716*/
1717
1718QRegion QWidgetPrivate::overlappedRegion(const QRect &rect, bool breakAfterFirst) const
1719{
1720 Q_Q(const QWidget);
1721
1722 const QWidget *w = q;
1723 QRect r = rect;
1724 QPoint p;
1725 QRegion region;
1726 while (w) {
1727 if (w->isWindow())
1728 break;
1729 QWidgetPrivate *pd = w->parentWidget()->d_func();
1730 bool above = false;
1731 for (int i = 0; i < pd->children.size(); ++i) {
1732 QWidget *sibling = qobject_cast<QWidget *>(pd->children.at(i));
1733 if (!sibling || !sibling->isVisible() || sibling->isWindow())
1734 continue;
1735 if (!above) {
1736 above = (sibling == w);
1737 continue;
1738 }
1739
1740 const QRect siblingRect = sibling->d_func()->effectiveRectFor(sibling->data->crect);
1741 if (qRectIntersects(siblingRect, r)) {
1742 const auto &siblingExtra = sibling->d_func()->extra;
1743 if (siblingExtra && siblingExtra->hasMask && !sibling->d_func()->graphicsEffect
1744 && !siblingExtra->mask.translated(sibling->data->crect.topLeft()).intersects(r)) {
1745 continue;
1746 }
1747 region += siblingRect.translated(-p);
1748 if (breakAfterFirst)
1749 break;
1750 }
1751 }
1752 w = w->parentWidget();
1753 r.translate(pd->data.crect.topLeft());
1754 p += pd->data.crect.topLeft();
1755 }
1756 return region;
1757}
1758
1760{
1761 if (shouldPaintOnScreen()) {
1763 dirty = QRegion();
1764 } else if (QWidgetRepaintManager *repaintManager = maybeRepaintManager()) {
1765 repaintManager->sync();
1766 }
1767}
1768
1770{
1771 if (shouldPaintOnScreen())
1772 paintOnScreen(region);
1773 else if (QWidgetRepaintManager *repaintManager = maybeRepaintManager()) {
1774 repaintManager->sync(q_func(), region);
1775 }
1776}
1777
1779{
1780 if (data.in_destructor)
1781 return;
1782
1784 return;
1785
1786 Q_Q(QWidget);
1787 if (q->testAttribute(Qt::WA_StaticContents)) {
1788 if (!extra)
1789 createExtra();
1790 extra->staticContentsSize = data.crect.size();
1791 }
1792
1793 QPaintEngine *engine = q->paintEngine();
1794
1795 // QGLWidget does not support partial updates if:
1796 // 1) The context is double buffered
1797 // 2) The context is single buffered and auto-fill background is enabled.
1798 const bool noPartialUpdateSupport = (engine && (engine->type() == QPaintEngine::OpenGL
1799 || engine->type() == QPaintEngine::OpenGL2))
1800 && (usesDoubleBufferedGLContext || q->autoFillBackground());
1801 QRegion toBePainted(noPartialUpdateSupport ? q->rect() : rgn);
1802
1803 toBePainted &= clipRect();
1804 clipToEffectiveMask(toBePainted);
1805 if (toBePainted.isEmpty())
1806 return; // Nothing to repaint.
1807
1809
1810 if (Q_UNLIKELY(q->paintingActive()))
1811 qWarning("QWidget::repaint: It is dangerous to leave painters active on a widget outside of the PaintEvent");
1812}
1813
1815{
1816 Q_Q(QWidget);
1817
1818 if (enable && !q->isWindow() && q->parentWidget() && !q->parentWidget()->updatesEnabled())
1819 return; // nothing we can do
1820
1821 if (enable != q->testAttribute(Qt::WA_UpdatesDisabled))
1822 return; // nothing to do
1823
1824 q->setAttribute(Qt::WA_UpdatesDisabled, !enable);
1825 if (enable)
1826 q->update();
1827
1829 for (int i = 0; i < children.size(); ++i) {
1831 if (w && !w->isWindow() && !w->testAttribute(attribute))
1832 w->d_func()->setUpdatesEnabled_helper(enable);
1833 }
1834}
1835
1844{
1845 Q_Q(QWidget);
1846 // Propagate a new inherited mask to all children.
1847#if QT_CONFIG(graphicsview)
1848 if (!q->parentWidget() && extra && extra->proxyWidget) {
1849 QGraphicsProxyWidget *p = extra->proxyWidget;
1850 inheritedPaletteResolveMask = p->d_func()->inheritedPaletteResolveMask | p->palette().resolveMask();
1851 } else
1852#endif // QT_CONFIG(graphicsview)
1853 if (q->isWindow() && !q->testAttribute(Qt::WA_WindowPropagation)) {
1855 }
1856
1857 directPaletteResolveMask = data.pal.resolveMask();
1859
1860 const bool useStyleSheetPropagationInWidgetStyles =
1862
1865 for (int i = 0; i < children.size(); ++i) {
1867 if (w && (!w->testAttribute(Qt::WA_StyleSheet) || useStyleSheetPropagationInWidgetStyles)
1868 && (!w->isWindow() || w->testAttribute(Qt::WA_WindowPropagation))) {
1869 QWidgetPrivate *wd = w->d_func();
1871 wd->resolvePalette();
1872 }
1873 }
1874}
1875
1876/*
1877 Returns the widget's clipping rectangle.
1878*/
1880{
1881 Q_Q(const QWidget);
1882 const QWidget * w = q;
1883 if (!w->isVisible())
1884 return QRect();
1885 QRect r = effectiveRectFor(q->rect());
1886 int ox = 0;
1887 int oy = 0;
1888 while (w
1889 && w->isVisible()
1890 && !w->isWindow()
1891 && w->parentWidget()) {
1892 ox -= w->x();
1893 oy -= w->y();
1894 w = w->parentWidget();
1895 r &= QRect(ox, oy, w->width(), w->height());
1896 }
1897 return r;
1898}
1899
1900/*
1901 Returns the widget's clipping region (without siblings).
1902*/
1904{
1905 Q_Q(const QWidget);
1906 if (!q->isVisible())
1907 return QRegion();
1908 QRegion r(q->rect());
1909 const QWidget * w = q;
1910 const QWidget *ignoreUpTo;
1911 int ox = 0;
1912 int oy = 0;
1913 while (w
1914 && w->isVisible()
1915 && !w->isWindow()
1916 && w->parentWidget()) {
1917 ox -= w->x();
1918 oy -= w->y();
1919 ignoreUpTo = w;
1920 w = w->parentWidget();
1921 r &= QRegion(ox, oy, w->width(), w->height());
1922
1923 int i = 0;
1924 while(w->d_func()->children.at(i++) != static_cast<const QObject *>(ignoreUpTo))
1925 ;
1926 for ( ; i < w->d_func()->children.size(); ++i) {
1927 if (QWidget *sibling = qobject_cast<QWidget *>(w->d_func()->children.at(i))) {
1928 if (sibling->isVisible() && !sibling->isWindow()) {
1929 QRect siblingRect(ox+sibling->x(), oy+sibling->y(),
1930 sibling->width(), sibling->height());
1931 if (qRectIntersects(siblingRect, q->rect()))
1932 r -= QRegion(siblingRect);
1933 }
1934 }
1935 }
1936 }
1937 return r;
1938}
1939
1940void QWidgetPrivate::setSystemClip(QPaintEngine *paintEngine, qreal devicePixelRatio, const QRegion &region)
1941{
1942// Transform the system clip region from device-independent pixels to device pixels
1943 QTransform scaleTransform;
1944 scaleTransform.scale(devicePixelRatio, devicePixelRatio);
1945
1946 paintEngine->d_func()->baseSystemClip = region;
1947 paintEngine->d_func()->setSystemTransform(scaleTransform);
1948
1949}
1950
1951#if QT_CONFIG(graphicseffect)
1952void QWidgetPrivate::invalidateGraphicsEffectsRecursively()
1953{
1954 Q_Q(QWidget);
1955 QWidget *w = q;
1956 do {
1957 if (w->graphicsEffect()) {
1958 QWidgetEffectSourcePrivate *sourced =
1959 static_cast<QWidgetEffectSourcePrivate *>(w->graphicsEffect()->source()->d_func());
1960 if (!sourced->updateDueToGraphicsEffect)
1961 w->graphicsEffect()->source()->d_func()->invalidateCache();
1962 }
1963 w = w->parentWidget();
1964 } while (w);
1965}
1966#endif // QT_CONFIG(graphicseffect)
1967
1969{
1970 Q_Q(QWidget);
1971
1972 dirtyOpaqueChildren = true;
1973
1974#if QT_CONFIG(graphicseffect)
1975 invalidateGraphicsEffectsRecursively();
1976#endif // QT_CONFIG(graphicseffect)
1977
1978 if (q->isWindow())
1979 return;
1980
1981 QWidget *parent = q->parentWidget();
1982 if (!parent)
1983 return;
1984
1985 // TODO: instead of setting dirtyflag, manipulate the dirtyregion directly?
1986 QWidgetPrivate *pd = parent->d_func();
1987 if (!pd->dirtyOpaqueChildren)
1989}
1990
1992{
1994 return opaqueChildren;
1995
1996 QWidgetPrivate *that = const_cast<QWidgetPrivate*>(this);
1997 that->opaqueChildren = QRegion();
1998
1999 for (int i = 0; i < children.size(); ++i) {
2001 if (!child || !child->isVisible() || child->isWindow())
2002 continue;
2003
2004 const QPoint offset = child->geometry().topLeft();
2005 QWidgetPrivate *childd = child->d_func();
2006 QRegion r = childd->isOpaque ? child->rect() : childd->getOpaqueChildren();
2007 if (childd->extra && childd->extra->hasMask)
2008 r &= childd->extra->mask;
2009 if (r.isEmpty())
2010 continue;
2011 r.translate(offset);
2012 that->opaqueChildren += r;
2013 }
2014
2015 that->opaqueChildren &= q_func()->rect();
2016 that->dirtyOpaqueChildren = false;
2017
2018 return that->opaqueChildren;
2019}
2020
2022{
2023 if (children.isEmpty() || clipRect.isEmpty())
2024 return;
2025
2026 const QRegion &r = getOpaqueChildren();
2027 if (!r.isEmpty())
2028 source -= (r & clipRect);
2029}
2030
2031//subtract any relatives that are higher up than me --- this is too expensive !!!
2032void QWidgetPrivate::subtractOpaqueSiblings(QRegion &sourceRegion, bool *hasDirtySiblingsAbove,
2033 bool alsoNonOpaque) const
2034{
2035 Q_Q(const QWidget);
2036 static int disableSubtractOpaqueSiblings = qEnvironmentVariableIntValue("QT_NO_SUBTRACTOPAQUESIBLINGS");
2037 if (disableSubtractOpaqueSiblings || q->isWindow())
2038 return;
2039
2040 QRect clipBoundingRect;
2041 bool dirtyClipBoundingRect = true;
2042
2043 QRegion parentClip;
2044 bool dirtyParentClip = true;
2045
2046 QPoint parentOffset = data.crect.topLeft();
2047
2048 const QWidget *w = q;
2049
2050 while (w) {
2051 if (w->isWindow())
2052 break;
2053 QWidgetPrivate *pd = w->parentWidget()->d_func();
2054 const int myIndex = pd->children.indexOf(const_cast<QWidget *>(w));
2055 const QRect widgetGeometry = w->d_func()->effectiveRectFor(w->data->crect);
2056 for (int i = myIndex + 1; i < pd->children.size(); ++i) {
2057 QWidget *sibling = qobject_cast<QWidget *>(pd->children.at(i));
2058 if (!sibling || !sibling->isVisible() || sibling->isWindow())
2059 continue;
2060
2061 const QRect siblingGeometry = sibling->d_func()->effectiveRectFor(sibling->data->crect);
2062 if (!qRectIntersects(siblingGeometry, widgetGeometry))
2063 continue;
2064
2065 if (dirtyClipBoundingRect) {
2066 clipBoundingRect = sourceRegion.boundingRect();
2067 dirtyClipBoundingRect = false;
2068 }
2069
2070 if (!qRectIntersects(siblingGeometry, clipBoundingRect.translated(parentOffset)))
2071 continue;
2072
2073 if (dirtyParentClip) {
2074 parentClip = sourceRegion.translated(parentOffset);
2075 dirtyParentClip = false;
2076 }
2077
2078 const QPoint siblingPos(sibling->data->crect.topLeft());
2079 const QRect siblingClipRect(sibling->d_func()->clipRect());
2080 QRegion siblingDirty(parentClip);
2081 siblingDirty &= (siblingClipRect.translated(siblingPos));
2082 const bool hasMask = sibling->d_func()->extra && sibling->d_func()->extra->hasMask
2083 && !sibling->d_func()->graphicsEffect;
2084 if (hasMask)
2085 siblingDirty &= sibling->d_func()->extra->mask.translated(siblingPos);
2086 if (siblingDirty.isEmpty())
2087 continue;
2088
2089 if (sibling->d_func()->isOpaque || alsoNonOpaque) {
2090 if (hasMask) {
2091 siblingDirty.translate(-parentOffset);
2092 sourceRegion -= siblingDirty;
2093 } else {
2094 sourceRegion -= siblingGeometry.translated(-parentOffset);
2095 }
2096 } else {
2097 if (hasDirtySiblingsAbove)
2098 *hasDirtySiblingsAbove = true;
2099 if (sibling->d_func()->children.isEmpty())
2100 continue;
2101 QRegion opaqueSiblingChildren(sibling->d_func()->getOpaqueChildren());
2102 opaqueSiblingChildren.translate(-parentOffset + siblingPos);
2103 sourceRegion -= opaqueSiblingChildren;
2104 }
2105 if (sourceRegion.isEmpty())
2106 return;
2107
2108 dirtyClipBoundingRect = true;
2109 dirtyParentClip = true;
2110 }
2111
2112 w = w->parentWidget();
2113 parentOffset += pd->data.crect.topLeft();
2114 dirtyParentClip = true;
2115 }
2116}
2117
2119{
2120 Q_Q(const QWidget);
2121
2122 const QWidget *w = q;
2123 QPoint offset;
2124
2125#if QT_CONFIG(graphicseffect)
2126 if (graphicsEffect) {
2127 w = q->parentWidget();
2128 offset -= data.crect.topLeft();
2129 }
2130#endif // QT_CONFIG(graphicseffect)
2131
2132 while (w) {
2133 const QWidgetPrivate *wd = w->d_func();
2134 if (wd->extra && wd->extra->hasMask)
2135 region &= (w != q) ? wd->extra->mask.translated(offset) : wd->extra->mask;
2136 if (w->isWindow())
2137 return;
2138 offset -= wd->data.crect.topLeft();
2139 w = w->parentWidget();
2140 }
2141}
2142
2144{
2145#if defined(QT_NO_BACKINGSTORE)
2146 return true;
2147#else
2148 Q_Q(const QWidget);
2149 if (q->testAttribute(Qt::WA_PaintOnScreen)
2150 || (!q->isWindow() && q->window()->testAttribute(Qt::WA_PaintOnScreen))) {
2151 return true;
2152 }
2153
2154 return false;
2155#endif
2156}
2157
2159{
2160 // hw: todo: only needed if opacity actually changed
2162
2163#if QT_CONFIG(graphicseffect)
2164 if (graphicsEffect) {
2165 // ### We should probably add QGraphicsEffect::isOpaque at some point.
2166 setOpaque(false);
2167 return;
2168 }
2169#endif // QT_CONFIG(graphicseffect)
2170
2171 Q_Q(QWidget);
2172 if (q->testAttribute(Qt::WA_OpaquePaintEvent) || q->testAttribute(Qt::WA_PaintOnScreen)) {
2173 setOpaque(true);
2174 return;
2175 }
2176
2177 const QPalette &pal = q->palette();
2178
2179 if (q->autoFillBackground()) {
2180 const QBrush &autoFillBrush = pal.brush(q->backgroundRole());
2181 if (autoFillBrush.style() != Qt::NoBrush && autoFillBrush.isOpaque()) {
2182 setOpaque(true);
2183 return;
2184 }
2185 }
2186
2187 if (q->isWindow() && !q->testAttribute(Qt::WA_NoSystemBackground)) {
2188 const QBrush &windowBrush = q->palette().brush(QPalette::Window);
2189 if (windowBrush.style() != Qt::NoBrush && windowBrush.isOpaque()) {
2190 setOpaque(true);
2191 return;
2192 }
2193 }
2194 setOpaque(false);
2195}
2196
2198{
2199 if (isOpaque != opaque) {
2200 isOpaque = opaque;
2202 }
2203}
2204
2206{
2207 Q_Q(QWidget);
2208 if (QWindow *window = q->windowHandle()) {
2209 QSurfaceFormat format = window->format();
2210 const int oldAlpha = format.alphaBufferSize();
2211 const int newAlpha = q->testAttribute(Qt::WA_TranslucentBackground) ? 8 : -1;
2212 if (oldAlpha != newAlpha) {
2213 // QTBUG-85714: Do this only when the QWindow has not yet been create()'ed yet.
2214 //
2215 // If that is not the case, then the setFormat() is not just futile
2216 // but downright dangerous. Futile because the format matters only
2217 // when creating the native window, no point in changing it
2218 // afterwards. Dangerous because a QOpenGLContext or something else
2219 // may eventually query the QWindow's format(), in order to ensure
2220 // compatibility (in terms of native concepts such as pixel format,
2221 // EGLConfig, etc.), and if we change it here, then the returned
2222 // format does not describe reality anymore. (reality being the
2223 // settings with which the native resource was created).
2224 //
2225 // Whereas if one does a destroy()-create() then this all here
2226 // won't matter because the format is updated in
2227 // QWidgetPrivate::create() again.
2228 //
2229 if (!window->handle()) {
2230 format.setAlphaBufferSize(newAlpha);
2231 window->setFormat(format);
2232 }
2233 }
2234 }
2235}
2236
2237static inline void fillRegion(QPainter *painter, const QRegion &rgn, const QBrush &brush)
2238{
2240
2241 if (brush.style() == Qt::TexturePattern) {
2242 const QRect rect(rgn.boundingRect());
2243 painter->setClipRegion(rgn);
2244 painter->drawTiledPixmap(rect, brush.texture(), rect.topLeft());
2245 } else if (brush.gradient()
2246 && (brush.gradient()->coordinateMode() == QGradient::ObjectBoundingMode
2247 || brush.gradient()->coordinateMode() == QGradient::ObjectMode)) {
2248 painter->save();
2249 painter->setClipRegion(rgn);
2251 painter->restore();
2252 } else {
2253 for (const QRect &rect : rgn)
2255 }
2256}
2257
2259{
2260#if QT_CONFIG(scrollarea)
2261 Q_Q(const QWidget);
2262 //If we are painting the viewport of a scrollarea, we must apply an offset to the brush in case we are drawing a texture
2263 if (brush.style() == Qt::NoBrush || brush.style() == Qt::SolidPattern)
2264 return false;
2265 QAbstractScrollArea *scrollArea = qobject_cast<QAbstractScrollArea *>(parent);
2266 if (scrollArea && scrollArea->viewport() == q) {
2267 QObjectData *scrollPrivate = static_cast<QWidget *>(scrollArea)->d_ptr.data();
2268 QAbstractScrollAreaPrivate *priv = static_cast<QAbstractScrollAreaPrivate *>(scrollPrivate);
2269 painter->setBrushOrigin(-priv->contentsOffset());
2270 }
2271#endif // QT_CONFIG(scrollarea)
2272 return true;
2273}
2274
2275void QWidgetPrivate::paintBackground(QPainter *painter, const QRegion &rgn, DrawWidgetFlags flags) const
2276{
2277 Q_Q(const QWidget);
2278
2279 bool brushOriginSet = false;
2280 const QBrush autoFillBrush = q->palette().brush(q->backgroundRole());
2281
2282 if ((flags & DrawAsRoot) && !(q->autoFillBackground() && autoFillBrush.isOpaque())) {
2283 const QBrush bg = q->palette().brush(QPalette::Window);
2284 if (!brushOriginSet)
2285 brushOriginSet = updateBrushOrigin(painter, bg);
2286 if (!(flags & DontSetCompositionMode)) {
2287 //copy alpha straight in
2290 fillRegion(painter, rgn, bg);
2291 painter->setCompositionMode(oldMode);
2292 } else {
2293 fillRegion(painter, rgn, bg);
2294 }
2295 }
2296
2297 if (q->autoFillBackground()) {
2298 if (!brushOriginSet)
2299 brushOriginSet = updateBrushOrigin(painter, autoFillBrush);
2300 fillRegion(painter, rgn, autoFillBrush);
2301 }
2302
2303 if (q->testAttribute(Qt::WA_StyledBackground)) {
2304 painter->setClipRegion(rgn);
2306 opt.initFrom(q);
2307 q->style()->drawPrimitive(QStyle::PE_Widget, &opt, painter, q);
2308 }
2309}
2310
2311/*
2312 \internal
2313 This function is called when a widget is hidden or destroyed.
2314 It resets some application global pointers that should only refer active,
2315 visible widgets.
2316*/
2317
2318extern QWidget *qt_button_down;
2319
2321{
2322 Q_Q(QWidget);
2323 // If this was the active application window, reset it
2326 // If the is the active mouse press widget, reset it
2327 if (q == qt_button_down)
2328 qt_button_down = nullptr;
2329}
2330
2331
2342{
2343 return QWidgetPrivate::mapper ? QWidgetPrivate::mapper->value(id, 0) : nullptr;
2344}
2345
2346
2347
2372{
2373 if (!data->in_destructor
2375 {
2376 QWidget *that = const_cast<QWidget*>(this);
2378 that->d_func()->createWinId();
2379 return that->data->winid;
2380 }
2381 return data->winid;
2382}
2383
2385{
2386 Q_Q(QWidget);
2387
2388 const bool forceNativeWindow = q->testAttribute(Qt::WA_NativeWindow);
2389 if (!q->testAttribute(Qt::WA_WState_Created) || (forceNativeWindow && !q->internalWinId())) {
2390 if (!q->isWindow()) {
2391 QWidget *parent = q->parentWidget();
2392 QWidgetPrivate *pd = parent->d_func();
2393 if (forceNativeWindow && !q->testAttribute(Qt::WA_DontCreateNativeAncestors))
2394 parent->setAttribute(Qt::WA_NativeWindow);
2395 if (!parent->internalWinId()) {
2396 pd->createWinId();
2397 }
2398
2399 for (int i = 0; i < pd->children.size(); ++i) {
2401 if (w && !w->isWindow() && (!w->testAttribute(Qt::WA_WState_Created)
2402 || (!w->internalWinId() && w->testAttribute(Qt::WA_NativeWindow)))) {
2403 w->create();
2404 }
2405 }
2406 } else {
2407 q->create();
2408 }
2409 }
2410}
2411
2420{
2421 Q_Q(QWidget);
2422 if (!q->isWindow())
2423 return false;
2424 // Find the screen for pos and make the widget understand it is on that screen.
2426}
2427
2435{
2436 Q_Q(QWidget);
2437 if (!screen || !q->isWindow())
2438 return false;
2439 const QScreen *currentScreen = windowHandle() ? windowHandle()->screen() : nullptr;
2440 if (currentScreen != screen) {
2442 if (windowHandle())
2443 windowHandle()->setScreen(screen);
2444 return true;
2445 }
2446 return false;
2447}
2448
2456{
2457 Q_D(QWidget);
2458 d->createWinId();
2459}
2460
2477{
2478 const WId id = internalWinId();
2480 return id;
2481 if (const QWidget *realParent = nativeParentWidget())
2482 return realParent->internalWinId();
2483 return 0;
2484}
2485
2498{
2499 Q_D(const QWidget);
2500 return d->windowHandle();
2501}
2502
2511{
2512 Q_D(const QWidget);
2513 if (auto associatedScreen = d->associatedScreen())
2514 return associatedScreen;
2515 if (auto topLevel = window()) {
2516 if (auto topData = qt_widget_private(topLevel)->topData()) {
2517 if (topData->initialScreen)
2518 return topData->initialScreen;
2519 }
2520 if (auto screenByPos = QGuiApplication::screenAt(topLevel->geometry().center()))
2521 return screenByPos;
2522 }
2524}
2525
2539{
2540 Q_D(QWidget);
2541 d->setScreen(screen);
2542}
2543
2544#ifndef QT_NO_STYLE_STYLESHEET
2545
2562{
2563 Q_D(const QWidget);
2564 if (!d->extra)
2565 return QString();
2566 return d->extra->styleSheet;
2567}
2568
2569void QWidget::setStyleSheet(const QString& styleSheet)
2570{
2571 Q_D(QWidget);
2572 if (data->in_destructor)
2573 return;
2574 d->createExtra();
2575
2576 QStyleSheetStyle *proxy = qt_styleSheet(d->extra->style);
2577 d->extra->styleSheet = styleSheet;
2578 if (styleSheet.isEmpty()) { // stylesheet removed
2579 if (!proxy)
2580 return;
2581
2582 d->inheritStyle();
2583 return;
2584 }
2585
2586 if (proxy) { // style sheet update
2587 bool repolish = d->polished;
2588 if (!repolish) {
2589 const auto childWidgets = findChildren<QWidget*>();
2590 for (auto child : childWidgets) {
2591 repolish = child->d_func()->polished;
2592 if (repolish)
2593 break;
2594 }
2595 }
2596 if (repolish)
2597 proxy->repolish(this);
2598 return;
2599 }
2600
2602 d->setStyle_helper(new QStyleSheetStyle(d->extra->style), true);
2603 } else {
2604 d->setStyle_helper(new QStyleSheetStyle(nullptr), true);
2605 }
2606}
2607
2608#endif // QT_NO_STYLE_STYLESHEET
2609
2615{
2616 Q_D(const QWidget);
2617
2618 if (d->extra && d->extra->style)
2619 return d->extra->style;
2620 return QApplication::style();
2621}
2622
2645{
2646 Q_D(QWidget);
2647 setAttribute(Qt::WA_SetStyle, style != nullptr);
2648 d->createExtra();
2649#ifndef QT_NO_STYLE_STYLESHEET
2650 if (QStyleSheetStyle *styleSheetStyle = qt_styleSheet(style)) {
2651 //if for some reason someone try to set a QStyleSheetStyle, ref it
2652 //(this may happen for example in QButtonDialogBox which propagates its style)
2653 styleSheetStyle->ref();
2654 d->setStyle_helper(style, false);
2655 } else if (qt_styleSheet(d->extra->style) || !qApp->styleSheet().isEmpty()) {
2656 // if we have an application stylesheet or have a proxy already, propagate
2657 d->setStyle_helper(new QStyleSheetStyle(style), true);
2658 } else
2659#endif
2660 d->setStyle_helper(style, false);
2661}
2662
2663void QWidgetPrivate::setStyle_helper(QStyle *newStyle, bool propagate)
2664{
2665 Q_Q(QWidget);
2666 QStyle *oldStyle = q->style();
2667
2668 createExtra();
2669
2670#ifndef QT_NO_STYLE_STYLESHEET
2671 QPointer<QStyle> origStyle = extra->style;
2672#endif
2673 extra->style = newStyle;
2674
2675 // repolish
2676 if (polished && q->windowType() != Qt::Desktop) {
2677 oldStyle->unpolish(q);
2678 q->style()->polish(q);
2679 }
2680
2681 if (propagate) {
2682 // We copy the list because the order may be modified
2683 const QObjectList childrenList = children;
2684 for (int i = 0; i < childrenList.size(); ++i) {
2685 QWidget *c = qobject_cast<QWidget*>(childrenList.at(i));
2686 if (c)
2687 c->d_func()->inheritStyle();
2688 }
2689 }
2690
2691#ifndef QT_NO_STYLE_STYLESHEET
2692 if (!qt_styleSheet(newStyle)) {
2693 if (const QStyleSheetStyle* cssStyle = qt_styleSheet(origStyle)) {
2694 cssStyle->clearWidgetFont(q);
2695 }
2696 }
2697#endif
2698
2701
2702#ifndef QT_NO_STYLE_STYLESHEET
2703 // dereference the old stylesheet style
2704 if (QStyleSheetStyle *proxy = qt_styleSheet(origStyle))
2705 proxy->deref();
2706#endif
2707}
2708
2709// Inherits style from the current parent and propagates it as necessary
2711{
2712#ifndef QT_NO_STYLE_STYLESHEET
2713 Q_Q(QWidget);
2714
2715 QStyle *extraStyle = extra ? (QStyle*)extra->style : nullptr;
2716
2717 QStyleSheetStyle *proxy = qt_styleSheet(extraStyle);
2718
2719 if (!q->styleSheet().isEmpty()) {
2720 Q_ASSERT(proxy);
2721 proxy->repolish(q);
2722 return;
2723 }
2724
2725 QStyle *origStyle = proxy ? proxy->base : extraStyle;
2726 QWidget *parent = q->parentWidget();
2727 QStyle *parentStyle = (parent && parent->d_func()->extra) ? (QStyle*)parent->d_func()->extra->style : nullptr;
2728 // If we have stylesheet on app or parent has stylesheet style, we need
2729 // to be running a proxy
2730 if (!qApp->styleSheet().isEmpty() || qt_styleSheet(parentStyle)) {
2731 QStyle *newStyle = parentStyle;
2732 if (q->testAttribute(Qt::WA_SetStyle) && qt_styleSheet(origStyle) == nullptr)
2733 newStyle = new QStyleSheetStyle(origStyle);
2734 else if (auto *styleSheetStyle = qt_styleSheet(origStyle))
2735 newStyle = styleSheetStyle;
2736 else if (QStyleSheetStyle *newProxy = qt_styleSheet(parentStyle))
2737 newProxy->ref();
2738
2739 setStyle_helper(newStyle, true);
2740 return;
2741 }
2742
2743 // So, we have no stylesheet on parent/app and we have an empty stylesheet
2744 // we just need our original style back
2745 if (origStyle == extraStyle) // is it any different?
2746 return;
2747
2748 // We could have inherited the proxy from our parent (which has a custom style)
2749 // In such a case we need to start following the application style (i.e revert
2750 // the propagation behavior of QStyleSheetStyle)
2751 if (!q->testAttribute(Qt::WA_SetStyle))
2752 origStyle = nullptr;
2753
2754 setStyle_helper(origStyle, true);
2755#endif // QT_NO_STYLE_STYLESHEET
2756}
2757
2758
2811{
2812 return static_cast<Qt::WindowModality>(data->window_modality);
2813}
2814
2816{
2817 data->window_modality = windowModality;
2818 // setModal_sys() will be called by setAttribute()
2819 setAttribute(Qt::WA_ShowModal, (data->window_modality != Qt::NonModal));
2821}
2822
2824{
2825 Q_Q(QWidget);
2826 if (q->windowHandle())
2827 q->windowHandle()->setModality(q->windowModality());
2828}
2829
2853{ return data->window_state & Qt::WindowMinimized; }
2854
2864{
2865 bool isMin = isMinimized();
2866 if (isMin && isVisible())
2867 return;
2868
2870
2871 if (!isMin)
2873 setVisible(true);
2874}
2875
2893{ return data->window_state & Qt::WindowMaximized; }
2894
2895
2896
2904Qt::WindowStates QWidget::windowState() const
2905{
2906 return Qt::WindowStates(data->window_state);
2907}
2908
2916void QWidget::overrideWindowState(Qt::WindowStates newstate)
2917{
2918 QWindowStateChangeEvent e(Qt::WindowStates(data->window_state), true);
2919 data->window_state = newstate;
2921}
2922
2953void QWidget::setWindowState(Qt::WindowStates newstate)
2954{
2955 Q_D(QWidget);
2956 Qt::WindowStates oldstate = windowState();
2957 if (newstate.testFlag(Qt::WindowMinimized)) // QTBUG-46763
2958 newstate.setFlag(Qt::WindowActive, false);
2959 if (oldstate == newstate)
2960 return;
2962 create();
2963
2964 data->window_state = newstate;
2965 data->in_set_window_state = 1;
2966 if (isWindow()) {
2967 // Ensure the initial size is valid, since we store it as normalGeometry below.
2969 adjustSize();
2970
2971 d->createTLExtra();
2973 d->topData()->normalGeometry = geometry();
2974
2976 windowHandle()->setWindowStates(newstate & ~Qt::WindowActive);
2977 }
2978 data->in_set_window_state = 0;
2979
2980 if (newstate & Qt::WindowActive)
2982
2983 QWindowStateChangeEvent e(oldstate);
2985}
2986
2999{ return data->window_state & Qt::WindowFullScreen; }
3000
3038{
3040
3043 setVisible(true);
3044#if !defined Q_OS_QNX // On QNX this window will be activated anyway from libscreen
3045 // activating it here before libscreen activates it causes problems
3047#endif
3048}
3049
3068
3085
3106bool QWidget::isEnabledTo(const QWidget *ancestor) const
3107{
3108 const QWidget * w = this;
3109 while (!w->testAttribute(Qt::WA_ForceDisabled)
3110 && !w->isWindow()
3111 && w->parentWidget()
3112 && w->parentWidget() != ancestor)
3113 w = w->parentWidget();
3115}
3116
3117#ifndef QT_NO_ACTION
3134{
3135 insertAction(nullptr, action);
3136}
3137
3143void QWidget::addActions(const QList<QAction *> &actions)
3144{
3145 for(int i = 0; i < actions.size(); i++)
3146 insertAction(nullptr, actions.at(i));
3147}
3148
3159{
3160 if (Q_UNLIKELY(!action)) {
3161 qWarning("QWidget::insertAction: Attempt to insert null action");
3162 return;
3163 }
3164
3165 Q_D(QWidget);
3166 if (d->actions.contains(action))
3167 removeAction(action);
3168
3169 int pos = d->actions.indexOf(before);
3170 if (pos < 0) {
3171 before = nullptr;
3172 pos = d->actions.size();
3173 }
3174 d->actions.insert(pos, action);
3175
3176 QActionPrivate *apriv = action->d_func();
3177 apriv->associatedObjects.append(this);
3178
3179 QActionEvent e(QEvent::ActionAdded, action, before);
3181}
3182
3192void QWidget::insertActions(QAction *before, const QList<QAction*> &actions)
3193{
3194 for(int i = 0; i < actions.size(); ++i)
3195 insertAction(before, actions.at(i));
3196}
3197
3203{
3204 if (!action)
3205 return;
3206
3207 Q_D(QWidget);
3208
3209 QActionPrivate *apriv = action->d_func();
3210 apriv->associatedObjects.removeAll(this);
3211
3212 if (d->actions.removeAll(action)) {
3215 }
3216}
3217
3223QList<QAction*> QWidget::actions() const
3224{
3225 Q_D(const QWidget);
3226 return d->actions;
3227}
3228
3246{
3247 QAction *ret = new QAction(text, this);
3248 addAction(ret);
3249 return ret;
3250}
3251
3253{
3254 QAction *ret = new QAction(icon, text, this);
3255 addAction(ret);
3256 return ret;
3257}
3258
3259#if QT_CONFIG(shortcut)
3261{
3263 ret->setShortcut(shortcut);
3264 return ret;
3265}
3266
3268{
3270 ret->setShortcut(shortcut);
3271 return ret;
3272}
3273#endif
3274
3293QAction *QWidget::addAction(const QString &text, const QObject *receiver, const char* member,
3295{
3296 QAction *action = addAction(text);
3297 QObject::connect(action, SIGNAL(triggered(bool)), receiver, member, type);
3298 return action;
3299}
3300
3302 const QObject *receiver, const char* member,
3304{
3305 QAction *action = addAction(icon, text);
3306 QObject::connect(action, SIGNAL(triggered(bool)), receiver, member, type);
3307 return action;
3308}
3309
3310#if QT_CONFIG(shortcut)
3312 const QObject *receiver, const char* member,
3314{
3315 QAction *action = addAction(text, receiver, member, type);
3316 action->setShortcut(shortcut);
3317 return action;
3318}
3319
3321 const QObject *receiver, const char* member,
3323{
3324 QAction *action = addAction(icon, text, receiver, member, type);
3325 action->setShortcut(shortcut);
3326 return action;
3327}
3328#endif // QT_CONFIG(shortcut)
3329
3351#endif // QT_NO_ACTION
3352
3375{
3376 Q_D(QWidget);
3378 d->setEnabled_helper(enable);
3379}
3380
3382{
3383 Q_Q(QWidget);
3384
3385 if (enable && !q->isWindow() && q->parentWidget() && !q->parentWidget()->isEnabled())
3386 return; // nothing we can do
3387
3388 if (enable != q->testAttribute(Qt::WA_Disabled))
3389 return; // nothing to do
3390
3391 q->setAttribute(Qt::WA_Disabled, !enable);
3393
3394 if (!enable && q->window()->focusWidget() == q) {
3395 bool parentIsEnabled = (!q->parentWidget() || q->parentWidget()->isEnabled());
3396 if (!parentIsEnabled || !q->focusNextChild())
3397 q->clearFocus();
3398 }
3399
3401 for (int i = 0; i < children.size(); ++i) {
3403 if (w && !w->testAttribute(attribute))
3404 w->d_func()->setEnabled_helper(enable);
3405 }
3406#ifndef QT_NO_CURSOR
3407 if (q->testAttribute(Qt::WA_SetCursor) || q->isWindow()) {
3408 // enforce the windows behavior of clearing the cursor on
3409 // disabled widgets
3410 qt_qpa_set_cursor(q, false);
3411 }
3412#endif
3413#ifndef QT_NO_IM
3414 if (q->testAttribute(Qt::WA_InputMethodEnabled) && q->hasFocus()) {
3415 QWidget *focusWidget = effectiveFocusWidget();
3416
3417 if (enable) {
3418 if (focusWidget->testAttribute(Qt::WA_InputMethodEnabled))
3420 } else {
3421 QGuiApplication::inputMethod()->commit();
3423 }
3424 }
3425#endif //QT_NO_IM
3428}
3429
3448{
3450}
3451
3453{
3455
3456}
3457
3466void QWidget::setDisabled(bool disable)
3467{
3468 setEnabled(!disable);
3469}
3470
3485{
3486 Q_D(const QWidget);
3487 if (isWindow() && ! (windowType() == Qt::Popup)) {
3488 QRect fs = d->frameStrut();
3489 return QRect(data->crect.x() - fs.left(),
3490 data->crect.y() - fs.top(),
3491 data->crect.width() + fs.left() + fs.right(),
3492 data->crect.height() + fs.top() + fs.bottom());
3493 }
3494 return data->crect;
3495}
3496
3510int QWidget::x() const
3511{
3512 Q_D(const QWidget);
3513 if (isWindow() && ! (windowType() == Qt::Popup))
3514 return data->crect.x() - d->frameStrut().left();
3515 return data->crect.x();
3516}
3517
3530int QWidget::y() const
3531{
3532 Q_D(const QWidget);
3533 if (isWindow() && ! (windowType() == Qt::Popup))
3534 return data->crect.y() - d->frameStrut().top();
3535 return data->crect.y();
3536}
3537
3566{
3567 Q_D(const QWidget);
3568 QPoint result = data->crect.topLeft();
3569 if (isWindow() && ! (windowType() == Qt::Popup))
3570 if (!d->maybeTopData() || !d->maybeTopData()->posIncludesFrame)
3571 result -= d->frameStrut().topLeft();
3572 return result;
3573}
3574
3685{
3686 Q_D(const QWidget);
3687 if (!isWindow())
3688 return QRect();
3689
3690 if (!isMaximized() && !isFullScreen())
3691 return geometry();
3692
3693 return d->topData()->normalGeometry;
3694}
3695
3696
3710{
3711 Q_D(const QWidget);
3712 QRect r(0, 0, 0, 0);
3713 for (int i = 0; i < d->children.size(); ++i) {
3714 QWidget *w = qobject_cast<QWidget *>(d->children.at(i));
3715 if (w && !w->isWindow() && !w->isHidden())
3716 r |= w->geometry();
3717 }
3718 return r;
3719}
3720
3734{
3735 Q_D(const QWidget);
3736 QRegion r;
3737 for (int i = 0; i < d->children.size(); ++i) {
3738 QWidget *w = qobject_cast<QWidget *>(d->children.at(i));
3739 if (w && !w->isWindow() && !w->isHidden()) {
3740 QRegion mask = w->mask();
3741 if (mask.isEmpty())
3742 r |= w->geometry();
3743 else
3744 r |= mask.translated(w->pos());
3745 }
3746 }
3747 return r;
3748}
3749
3750
3769{
3770 Q_D(const QWidget);
3771 return d->extra ? QSize(d->extra->minw, d->extra->minh) : QSize(0, 0);
3772}
3773
3791{
3792 Q_D(const QWidget);
3793 return d->extra ? QSize(d->extra->maxw, d->extra->maxh)
3795}
3796
3797
3870{
3871 Q_D(const QWidget);
3872 return (d->extra && d->extra->topextra)
3873 ? QSize(d->extra->topextra->incw, d->extra->topextra->inch)
3874 : QSize(0, 0);
3875}
3876
3891{
3892 Q_D(const QWidget);
3893 return (d->extra && d->extra->topextra)
3894 ? QSize(d->extra->topextra->basew, d->extra->topextra->baseh)
3895 : QSize(0, 0);
3896}
3897
3899{
3900 Q_Q(QWidget);
3901
3902 int mw = minw, mh = minh;
3903 if (mw == QWIDGETSIZE_MAX)
3904 mw = 0;
3905 if (mh == QWIDGETSIZE_MAX)
3906 mh = 0;
3907 if (Q_UNLIKELY(minw > QWIDGETSIZE_MAX || minh > QWIDGETSIZE_MAX)) {
3908 qWarning("QWidget::setMinimumSize: (%s/%s) "
3909 "The largest allowed size is (%d,%d)",
3910 q->objectName().toLocal8Bit().data(), q->metaObject()->className(), QWIDGETSIZE_MAX,
3912 minw = mw = qMin<int>(minw, QWIDGETSIZE_MAX);
3913 minh = mh = qMin<int>(minh, QWIDGETSIZE_MAX);
3914 }
3915 if (Q_UNLIKELY(minw < 0 || minh < 0)) {
3916 qWarning("QWidget::setMinimumSize: (%s/%s) Negative sizes (%d,%d) "
3917 "are not possible",
3918 q->objectName().toLocal8Bit().data(), q->metaObject()->className(), minw, minh);
3919 minw = mw = qMax(minw, 0);
3920 minh = mh = qMax(minh, 0);
3921 }
3922 createExtra();
3923 if (extra->minw == mw && extra->minh == mh)
3924 return false;
3925 extra->minw = mw;
3926 extra->minh = mh;
3927 extra->explicitMinSize = (mw ? Qt::Horizontal : 0) | (mh ? Qt::Vertical : 0);
3928 return true;
3929}
3930
3932{
3933 Q_Q(QWidget);
3934 if (extra && q->windowHandle()) {
3935 QWindow *win = q->windowHandle();
3937
3938 winp->minimumSize = QSize(extra->minw, extra->minh);
3939 winp->maximumSize = QSize(extra->maxw, extra->maxh);
3940
3941 if (extra->topextra) {
3942 winp->baseSize = QSize(extra->topextra->basew, extra->topextra->baseh);
3943 winp->sizeIncrement = QSize(extra->topextra->incw, extra->topextra->inch);
3944 }
3945
3946 if (winp->platformWindow) {
3948 winp->platformWindow->propagateSizeHints();
3949 }
3950 }
3951}
3952
3961void QWidget::setMinimumSize(int minw, int minh)
3962{
3963 Q_D(QWidget);
3964 if (!d->setMinimumSize_helper(minw, minh))
3965 return;
3966
3967 if (isWindow())
3968 d->setConstraints_sys();
3969 if (minw > width() || minh > height()) {
3970 bool resized = testAttribute(Qt::WA_Resized);
3971 bool maximized = isMaximized();
3972 resize(qMax(minw,width()), qMax(minh,height()));
3973 setAttribute(Qt::WA_Resized, resized); //not a user resize
3974 if (maximized)
3975 data->window_state = data->window_state | Qt::WindowMaximized;
3976 }
3977#if QT_CONFIG(graphicsview)
3978 if (d->extra) {
3979 if (d->extra->proxyWidget)
3980 d->extra->proxyWidget->setMinimumSize(minw, minh);
3981 }
3982#endif
3983 d->updateGeometry_helper(d->extra->minw == d->extra->maxw && d->extra->minh == d->extra->maxh);
3984}
3985
3987{
3988 Q_Q(QWidget);
3989 if (Q_UNLIKELY(maxw > QWIDGETSIZE_MAX || maxh > QWIDGETSIZE_MAX)) {
3990 qWarning("QWidget::setMaximumSize: (%s/%s) "
3991 "The largest allowed size is (%d,%d)",
3992 q->objectName().toLocal8Bit().data(), q->metaObject()->className(), QWIDGETSIZE_MAX,
3994 maxw = qMin<int>(maxw, QWIDGETSIZE_MAX);
3995 maxh = qMin<int>(maxh, QWIDGETSIZE_MAX);
3996 }
3997 if (Q_UNLIKELY(maxw < 0 || maxh < 0)) {
3998 qWarning("QWidget::setMaximumSize: (%s/%s) Negative sizes (%d,%d) "
3999 "are not possible",
4000 q->objectName().toLocal8Bit().data(), q->metaObject()->className(), maxw, maxh);
4001 maxw = qMax(maxw, 0);
4002 maxh = qMax(maxh, 0);
4003 }
4004 createExtra();
4005 if (extra->maxw == maxw && extra->maxh == maxh)
4006 return false;
4007 extra->maxw = maxw;
4008 extra->maxh = maxh;
4009 extra->explicitMaxSize = (maxw != QWIDGETSIZE_MAX ? Qt::Horizontal : 0) |
4010 (maxh != QWIDGETSIZE_MAX ? Qt::Vertical : 0);
4011 return true;
4012}
4013
4021void QWidget::setMaximumSize(int maxw, int maxh)
4022{
4023 Q_D(QWidget);
4024 if (!d->setMaximumSize_helper(maxw, maxh))
4025 return;
4026
4027 if (isWindow())
4028 d->setConstraints_sys();
4029 if (maxw < width() || maxh < height()) {
4030 bool resized = testAttribute(Qt::WA_Resized);
4031 resize(qMin(maxw,width()), qMin(maxh,height()));
4032 setAttribute(Qt::WA_Resized, resized); //not a user resize
4033 }
4034
4035#if QT_CONFIG(graphicsview)
4036 if (d->extra) {
4037 if (d->extra->proxyWidget)
4038 d->extra->proxyWidget->setMaximumSize(maxw, maxh);
4039 }
4040#endif
4041
4042 d->updateGeometry_helper(d->extra->minw == d->extra->maxw && d->extra->minh == d->extra->maxh);
4043}
4044
4052{
4053 Q_D(QWidget);
4054 d->createTLExtra();
4055 QTLWExtra* x = d->topData();
4056 if (x->incw == w && x->inch == h)
4057 return;
4058 x->incw = w;
4059 x->inch = h;
4060 if (isWindow())
4061 d->setConstraints_sys();
4062}
4063
4070void QWidget::setBaseSize(int basew, int baseh)
4071{
4072 Q_D(QWidget);
4073 d->createTLExtra();
4074 QTLWExtra* x = d->topData();
4075 if (x->basew == basew && x->baseh == baseh)
4076 return;
4077 x->basew = basew;
4078 x->baseh = baseh;
4079 if (isWindow())
4080 d->setConstraints_sys();
4081}
4082
4099{
4100 setFixedSize(s.width(), s.height());
4101}
4102
4103
4112{
4113 Q_D(QWidget);
4114 bool minSizeSet = d->setMinimumSize_helper(w, h);
4115 bool maxSizeSet = d->setMaximumSize_helper(w, h);
4116 if (!minSizeSet && !maxSizeSet)
4117 return;
4118
4119 if (isWindow())
4120 d->setConstraints_sys();
4121 else
4122 d->updateGeometry_helper(true);
4123
4124 if (w != QWIDGETSIZE_MAX || h != QWIDGETSIZE_MAX)
4125 resize(w, h);
4126}
4127
4129{
4130 Q_D(QWidget);
4131 d->createExtra();
4132 uint expl = d->extra->explicitMinSize | (w ? Qt::Horizontal : 0);
4134 d->extra->explicitMinSize = expl;
4135}
4136
4138{
4139 Q_D(QWidget);
4140 d->createExtra();
4141 uint expl = d->extra->explicitMinSize | (h ? Qt::Vertical : 0);
4143 d->extra->explicitMinSize = expl;
4144}
4145
4147{
4148 Q_D(QWidget);
4149 d->createExtra();
4150 uint expl = d->extra->explicitMaxSize | (w == QWIDGETSIZE_MAX ? 0 : Qt::Horizontal);
4152 d->extra->explicitMaxSize = expl;
4153}
4154
4156{
4157 Q_D(QWidget);
4158 d->createExtra();
4159 uint expl = d->extra->explicitMaxSize | (h == QWIDGETSIZE_MAX ? 0 : Qt::Vertical);
4161 d->extra->explicitMaxSize = expl;
4162}
4163
4172{
4173 Q_D(QWidget);
4174 d->createExtra();
4175 uint explMin = d->extra->explicitMinSize | Qt::Horizontal;
4176 uint explMax = d->extra->explicitMaxSize | Qt::Horizontal;
4179 d->extra->explicitMinSize = explMin;
4180 d->extra->explicitMaxSize = explMax;
4181}
4182
4183
4192{
4193 Q_D(QWidget);
4194 d->createExtra();
4195 uint explMin = d->extra->explicitMinSize | Qt::Vertical;
4196 uint explMax = d->extra->explicitMaxSize | Qt::Vertical;
4199 d->extra->explicitMinSize = explMin;
4200 d->extra->explicitMaxSize = explMax;
4201}
4202
4203
4213QPointF QWidget::mapTo(const QWidget *parent, const QPointF &pos) const
4214{
4215 QPointF p = pos;
4216 if (parent) {
4217 const QWidget * w = this;
4218 while (w != parent) {
4219 Q_ASSERT_X(w, "QWidget::mapTo(const QWidget *parent, const QPointF &pos)",
4220 "parent must be in parent hierarchy");
4221 p = w->mapToParent(p);
4222 w = w->parentWidget();
4223 }
4224 }
4225 return p;
4226}
4227
4231QPoint QWidget::mapTo(const QWidget *parent, const QPoint &pos) const
4232{
4233 return mapTo(parent, QPointF(pos)).toPoint();
4234}
4235
4245QPointF QWidget::mapFrom(const QWidget *parent, const QPointF &pos) const
4246{
4247 QPointF p(pos);
4248 if (parent) {
4249 const QWidget * w = this;
4250 while (w != parent) {
4251 Q_ASSERT_X(w, "QWidget::mapFrom(const QWidget *parent, const QPoint &pos)",
4252 "parent must be in parent hierarchy");
4253
4254 p = w->mapFromParent(p);
4255 w = w->parentWidget();
4256 }
4257 }
4258 return p;
4259}
4260
4264QPoint QWidget::mapFrom(const QWidget *parent, const QPoint &pos) const
4265{
4266 return mapFrom(parent, QPointF(pos)).toPoint();
4267}
4268
4280{
4281 return pos + QPointF(data->crect.topLeft());
4282}
4283
4288{
4289 return pos + data->crect.topLeft();
4290}
4291
4303{
4304 return pos - QPointF(data->crect.topLeft());
4305}
4306
4311{
4312 return pos - data->crect.topLeft();
4313}
4314
4315
4330{
4331 QWidget *w = const_cast<QWidget *>(this);
4332 QWidget *p = w->parentWidget();
4333 while (!w->isWindow() && p) {
4334 w = p;
4335 p = p->parentWidget();
4336 }
4337 return w;
4338}
4339
4350{
4352 while (parent && !parent->internalWinId())
4353 parent = parent->parentWidget();
4354 return parent;
4355}
4356
4377{
4378
4379 const QWidget *w = this;
4380 do {
4381 QPalette::ColorRole role = w->d_func()->bg_role;
4382 if (role != QPalette::NoRole)
4383 return role;
4384 if (w->isWindow() || w->windowType() == Qt::SubWindow)
4385 break;
4386 w = w->parentWidget();
4387 } while (w);
4388 return QPalette::Window;
4389}
4390
4408{
4409 Q_D(QWidget);
4410 d->bg_role = role;
4411 d->updateSystemBackground();
4412 d->propagatePaletteChange();
4413 d->updateIsOpaque();
4414}
4415
4428{
4429 Q_D(const QWidget);
4431 if (rl != QPalette::NoRole)
4432 return rl;
4434 switch (backgroundRole()) {
4435 case QPalette::Button:
4436 role = QPalette::ButtonText;
4437 break;
4438 case QPalette::Base:
4439 role = QPalette::Text;
4440 break;
4441 case QPalette::Dark:
4442 case QPalette::Shadow:
4443 role = QPalette::Light;
4444 break;
4447 break;
4449 role = QPalette::ToolTipText;
4450 break;
4451 default:
4452 ;
4453 }
4454 return role;
4455}
4456
4473{
4474 Q_D(QWidget);
4475 d->fg_role = role;
4476 d->updateSystemBackground();
4477 d->propagatePaletteChange();
4478}
4479
4531{
4532 if (!isEnabled()) {
4534 } else if ((!isVisible() || isActiveWindow())
4535#if defined(Q_OS_WIN)
4536 && !QApplicationPrivate::isBlockedByModal(const_cast<QWidget *>(this))
4537#endif
4538 ) {
4539 data->pal.setCurrentColorGroup(QPalette::Active);
4540 } else {
4541 data->pal.setCurrentColorGroup(QPalette::Inactive);
4542 }
4543 return data->pal;
4544}
4545
4547{
4548 Q_D(QWidget);
4550
4551 // Determine which palette is inherited from this widget's ancestors and
4552 // QApplication::palette, resolve this against \a palette (attributes from
4553 // the inherited palette are copied over this widget's palette). Then
4554 // propagate this palette to this widget's children.
4555 QPalette naturalPalette = d->naturalWidgetPalette(d->inheritedPaletteResolveMask);
4556 QPalette resolvedPalette = palette.resolve(naturalPalette);
4557 d->setPalette_helper(resolvedPalette);
4558}
4559
4570{
4571 Q_Q(const QWidget);
4572
4573 const bool useStyleSheetPropagationInWidgetStyles =
4575
4576 QPalette naturalPalette = QApplication::palette(q);
4577 if ((!q->testAttribute(Qt::WA_StyleSheet) || useStyleSheetPropagationInWidgetStyles)
4578 && (!q->isWindow() || q->testAttribute(Qt::WA_WindowPropagation)
4579#if QT_CONFIG(graphicsview)
4580 || (extra && extra->proxyWidget)
4581#endif // QT_CONFIG(graphicsview)
4582 )) {
4583 if (QWidget *p = q->parentWidget()) {
4584 if (!p->testAttribute(Qt::WA_StyleSheet) || useStyleSheetPropagationInWidgetStyles) {
4585 if (!naturalPalette.isCopyOf(QGuiApplication::palette())) {
4586 QPalette inheritedPalette = p->palette();
4587 inheritedPalette.setResolveMask(inheritedMask);
4588 naturalPalette = inheritedPalette.resolve(naturalPalette);
4589 } else {
4590 naturalPalette = p->palette();
4591 }
4592 }
4593 }
4594#if QT_CONFIG(graphicsview)
4595 else if (extra && extra->proxyWidget) {
4596 QPalette inheritedPalette = extra->proxyWidget->palette();
4597 inheritedPalette.setResolveMask(inheritedMask);
4598 naturalPalette = inheritedPalette.resolve(naturalPalette);
4599 }
4600#endif // QT_CONFIG(graphicsview)
4601 }
4602 naturalPalette.setResolveMask(0);
4603 return naturalPalette;
4604}
4614{
4616 QPalette resolvedPalette = data.pal.resolve(naturalPalette);
4617 setPalette_helper(resolvedPalette);
4618}
4619
4621{
4622 Q_Q(QWidget);
4623 if (data.pal == palette && data.pal.resolveMask() == palette.resolveMask())
4624 return;
4625 data.pal = palette;
4629 q->update();
4631}
4632
4636
4684{
4685 Q_D(QWidget);
4686
4687#ifndef QT_NO_STYLE_STYLESHEET
4688 const QStyleSheetStyle* style;
4689 if (d->extra && (style = qt_styleSheet(d->extra->style)))
4690 style->saveWidgetFont(this, font);
4691#endif
4692
4694
4695 // Determine which font is inherited from this widget's ancestors and
4696 // QApplication::font, resolve this against \a font (attributes from the
4697 // inherited font are copied over). Then propagate this font to this
4698 // widget's children.
4699 QFont naturalFont = d->naturalWidgetFont(d->inheritedFontResolveMask);
4700 QFont resolvedFont = font.resolve(naturalFont);
4701 d->setFont_helper(resolvedFont);
4702}
4703
4704/*
4705 \internal
4706
4707 Returns the font that the widget \a w inherits from its ancestors and
4708 QApplication::font. \a inheritedMask is the combination of the widget's
4709 ancestors font request masks (i.e., which attributes from the parent
4710 widget's font are implicitly imposed on this widget by the user). Note
4711 that this font does not take into account the font set on \a w itself.
4712
4713 ### Stylesheet has a different font propagation mechanism. When a stylesheet
4714 is applied, fonts are not propagated anymore
4715*/
4717{
4718 Q_Q(const QWidget);
4719
4720 const bool useStyleSheetPropagationInWidgetStyles =
4722
4723 QFont naturalFont = QApplication::font(q);
4724 if ((!q->testAttribute(Qt::WA_StyleSheet) || useStyleSheetPropagationInWidgetStyles)
4725 && (!q->isWindow() || q->testAttribute(Qt::WA_WindowPropagation)
4726#if QT_CONFIG(graphicsview)
4727 || (extra && extra->proxyWidget)
4728#endif // QT_CONFIG(graphicsview)
4729 )) {
4730 if (QWidget *p = q->parentWidget()) {
4731 if (!p->testAttribute(Qt::WA_StyleSheet) || useStyleSheetPropagationInWidgetStyles) {
4732 if (!naturalFont.isCopyOf(QApplication::font())) {
4733 if (inheritedMask != 0) {
4734 QFont inheritedFont = p->font();
4735 inheritedFont.setResolveMask(inheritedMask);
4736 naturalFont = inheritedFont.resolve(naturalFont);
4737 } // else nothing to do (naturalFont = naturalFont)
4738 } else {
4739 naturalFont = p->font();
4740 }
4741 }
4742 }
4743#if QT_CONFIG(graphicsview)
4744 else if (extra && extra->proxyWidget) {
4745 if (inheritedMask != 0) {
4746 QFont inheritedFont = extra->proxyWidget->font();
4747 inheritedFont.setResolveMask(inheritedMask);
4748 naturalFont = inheritedFont.resolve(naturalFont);
4749 } // else nothing to do (naturalFont = naturalFont)
4750 }
4751#endif // QT_CONFIG(graphicsview)
4752 }
4753 naturalFont.setResolveMask(0);
4754 return naturalFont;
4755}
4756
4763{
4764 QFont localfont = data.fnt;
4766 return localfont;
4767}
4768
4778{
4780 QFont resolvedFont = localFont().resolve(naturalFont);
4781 setFont_helper(resolvedFont);
4782}
4783
4794{
4795 Q_Q(QWidget);
4796#ifndef QT_NO_STYLE_STYLESHEET
4797 const QStyleSheetStyle* cssStyle;
4798 cssStyle = extra ? qt_styleSheet(extra->style) : nullptr;
4799 const bool useStyleSheetPropagationInWidgetStyles =
4801#endif
4802
4803 data.fnt = QFont(font, q);
4804
4805 // Combine new mask with natural mask and propagate to children.
4806#if QT_CONFIG(graphicsview)
4807 if (!q->parentWidget() && extra && extra->proxyWidget) {
4808 QGraphicsProxyWidget *p = extra->proxyWidget;
4809 inheritedFontResolveMask = p->d_func()->inheritedFontResolveMask | p->font().resolveMask();
4810 } else
4811#endif // QT_CONFIG(graphicsview)
4812 if (q->isWindow() && !q->testAttribute(Qt::WA_WindowPropagation)) {
4814 }
4815 uint newMask = data.fnt.resolveMask() | inheritedFontResolveMask;
4816 // Set the font as also having resolved inherited traits, so the result of reading QWidget::font()
4817 // isn't all weak information, but save the original mask to be able to let new changes on the
4818 // parent widget font propagate correctly.
4819 directFontResolveMask = data.fnt.resolveMask();
4820 data.fnt.setResolveMask(newMask);
4821
4822 for (int i = 0; i < children.size(); ++i) {
4824 if (w) {
4825 if (0) {
4826#ifndef QT_NO_STYLE_STYLESHEET
4827 } else if (!useStyleSheetPropagationInWidgetStyles && w->testAttribute(Qt::WA_StyleSheet)) {
4828 // Style sheets follow a different font propagation scheme.
4829 if (cssStyle)
4830 cssStyle->updateStyleSheetFont(w);
4831#endif
4832 } else if ((!w->isWindow() || w->testAttribute(Qt::WA_WindowPropagation))) {
4833 // Propagate font changes.
4834 QWidgetPrivate *wd = w->d_func();
4835 wd->inheritedFontResolveMask = newMask;
4836 wd->resolveFont();
4837 }
4838 }
4839 }
4840
4841#ifndef QT_NO_STYLE_STYLESHEET
4842 if (!useStyleSheetPropagationInWidgetStyles && cssStyle) {
4843 cssStyle->updateStyleSheetFont(q);
4844 }
4845#endif
4846
4849}
4850
4852{
4853 Q_Q(QWidget);
4854
4855 if ( (direction == Qt::RightToLeft) == q->testAttribute(Qt::WA_RightToLeft))
4856 return;
4857 q->setAttribute(Qt::WA_RightToLeft, (direction == Qt::RightToLeft));
4858 if (!children.isEmpty()) {
4859 for (int i = 0; i < children.size(); ++i) {
4861 if (w && !w->isWindow() && !w->testAttribute(Qt::WA_SetLayoutDirection))
4862 w->d_func()->setLayoutDirection_helper(direction);
4863 }
4864 }
4867}
4868
4870{
4871 Q_Q(const QWidget);
4872 if (!q->testAttribute(Qt::WA_SetLayoutDirection))
4873 setLayoutDirection_helper(q->isWindow() ? QGuiApplication::layoutDirection() : q->parentWidget()->layoutDirection());
4874}
4875
4896{
4897 Q_D(QWidget);
4898
4901 return;
4902 }
4903
4905 d->setLayoutDirection_helper(direction);
4906}
4907
4912
4914{
4915 Q_D(QWidget);
4917 d->resolveLayoutDirection();
4918}
4919
4963#ifndef QT_NO_CURSOR
4965{
4966 Q_D(const QWidget);
4968 return (d->extra && d->extra->curs)
4969 ? *d->extra->curs
4971 if (isWindow() || !parentWidget())
4972 return QCursor(Qt::ArrowCursor);
4973 return parentWidget()->cursor();
4974}
4975
4977{
4978 Q_D(QWidget);
4980 || (d->extra && d->extra->curs))
4981 {
4982 d->createExtra();
4983 d->extra->curs = std::make_unique<QCursor>(cursor);
4984 }
4986 d->setCursor_sys(cursor);
4987
4990}
4991
4993{
4995 Q_Q(QWidget);
4996 qt_qpa_set_cursor(q, false);
4997}
4998
5000{
5001 Q_D(QWidget);
5002 if (d->extra)
5003 d->extra->curs.reset();
5004 if (!isWindow())
5006 d->unsetCursor_sys();
5007
5010}
5011
5013{
5014 Q_Q(QWidget);
5015 qt_qpa_set_cursor(q, false);
5016}
5017
5018static inline void applyCursor(QWidget *w, const QCursor &c)
5019{
5020 if (QWindow *window = w->windowHandle())
5021 window->setCursor(c);
5022}
5023
5024static inline void unsetCursor(QWidget *w)
5025{
5026 if (QWindow *window = w->windowHandle())
5027 window->unsetCursor();
5028}
5029
5030void qt_qpa_set_cursor(QWidget *w, bool force)
5031{
5032 if (!w->testAttribute(Qt::WA_WState_Created))
5033 return;
5034
5035 static QPointer<QWidget> lastUnderMouse = nullptr;
5036 if (force) {
5037 lastUnderMouse = w;
5038 } else if (lastUnderMouse) {
5039 const WId lastWinId = lastUnderMouse->effectiveWinId();
5040 const WId winId = w->effectiveWinId();
5041 if (lastWinId && lastWinId == winId)
5042 w = lastUnderMouse;
5043 } else if (!w->internalWinId()) {
5044 return; // The mouse is not under this widget, and it's not native, so don't change it.
5045 }
5046
5047 while (!w->internalWinId() && w->parentWidget() && !w->isWindow()
5048 && !w->testAttribute(Qt::WA_SetCursor))
5049 w = w->parentWidget();
5050
5051 QWidget *nativeParent = w;
5052 if (!w->internalWinId())
5053 nativeParent = w->nativeParentWidget();
5054 if (!nativeParent || !nativeParent->internalWinId())
5055 return;
5056
5057 if (w->isWindow() || w->testAttribute(Qt::WA_SetCursor)) {
5058 if (w->isEnabled())
5059 applyCursor(nativeParent, w->cursor());
5060 else
5061 // Enforce the windows behavior of clearing the cursor on
5062 // disabled widgets.
5063 unsetCursor(nativeParent);
5064 } else {
5065 unsetCursor(nativeParent);
5066 }
5067}
5068#endif
5069
5108void QWidget::render(QPaintDevice *target, const QPoint &targetOffset,
5109 const QRegion &sourceRegion, RenderFlags renderFlags)
5110{
5111 QPainter p(target);
5112 render(&p, targetOffset, sourceRegion, renderFlags);
5113}
5114
5128void QWidget::render(QPainter *painter, const QPoint &targetOffset,
5129 const QRegion &sourceRegion, RenderFlags renderFlags)
5130{
5131 if (Q_UNLIKELY(!painter)) {
5132 qWarning("QWidget::render: Null pointer to painter");
5133 return;
5134 }
5135
5136 if (Q_UNLIKELY(!painter->isActive())) {
5137 qWarning("QWidget::render: Cannot render with an inactive painter");
5138 return;
5139 }
5140
5141 const qreal opacity = painter->opacity();
5142 if (qFuzzyIsNull(opacity))
5143 return; // Fully transparent.
5144
5145 Q_D(QWidget);
5146 const bool inRenderWithPainter = d->extra && d->extra->inRenderWithPainter;
5147 const QRegion toBePainted = !inRenderWithPainter ? d->prepareToRender(sourceRegion, renderFlags)
5148 : sourceRegion;
5149 if (toBePainted.isEmpty())
5150 return;
5151
5152 if (!d->extra)
5153 d->createExtra();
5154 d->extra->inRenderWithPainter = true;
5155
5158 QPaintEnginePrivate *enginePriv = engine->d_func();
5159 Q_ASSERT(enginePriv);
5160 QPaintDevice *target = engine->paintDevice();
5162
5163 // Render via a pixmap when dealing with non-opaque painters or printers.
5164 if (!inRenderWithPainter && (opacity < 1.0 || (target->devType() == QInternal::Printer))) {
5165 d->render_helper(painter, targetOffset, toBePainted, renderFlags);
5166 d->extra->inRenderWithPainter = inRenderWithPainter;
5167 return;
5168 }
5169
5170 // Set new shared painter.
5171 QPainter *oldPainter = d->sharedPainter();
5172 d->setSharedPainter(painter);
5173
5174 // Save current system clip, viewport and transform,
5175 const QTransform oldTransform = enginePriv->systemTransform;
5176 const QRegion oldSystemClip = enginePriv->systemClip;
5177 const QRegion oldBaseClip = enginePriv->baseSystemClip;
5178 const QRegion oldSystemViewport = enginePriv->systemViewport;
5179 const Qt::LayoutDirection oldLayoutDirection = painter->layoutDirection();
5180
5181 // This ensures that all painting triggered by render() is clipped to the current engine clip.
5182 if (painter->hasClipping()) {
5183 const QRegion painterClip = painter->deviceTransform().map(painter->clipRegion());
5184 enginePriv->setSystemViewport(oldSystemClip.isEmpty() ? painterClip : oldSystemClip & painterClip);
5185 } else {
5186 enginePriv->setSystemViewport(oldSystemClip);
5187 }
5189
5190 d->render(target, targetOffset, toBePainted, renderFlags);
5191
5192 // Restore system clip, viewport and transform.
5193 enginePriv->baseSystemClip = oldBaseClip;
5194 enginePriv->setSystemTransformAndViewport(oldTransform, oldSystemViewport);
5195 enginePriv->systemStateChanged();
5196 painter->setLayoutDirection(oldLayoutDirection);
5197
5198 // Restore shared painter.
5199 d->setSharedPainter(oldPainter);
5200
5201 d->extra->inRenderWithPainter = inRenderWithPainter;
5202}
5203
5205{
5206 QResizeEvent e(target->size(), QSize());
5208
5209 const QObjectList children = target->children();
5210 for (int i = 0; i < children.size(); ++i) {
5211 if (!children.at(i)->isWidgetType())
5212 continue;
5213 QWidget *child = static_cast<QWidget*>(children.at(i));
5214 if (!child->isWindow() && child->testAttribute(Qt::WA_PendingResizeEvent))
5216 }
5217}
5218
5231QPixmap QWidget::grab(const QRect &rectangle)
5232{
5233 Q_D(QWidget);
5235 sendResizeEvents(this);
5236
5237 const QWidget::RenderFlags renderFlags = QWidget::DrawWindowBackground | QWidget::DrawChildren | QWidget::IgnoreMask;
5238
5239 const bool oldDirtyOpaqueChildren = d->dirtyOpaqueChildren;
5240 QRect r(rectangle);
5241 if (r.width() < 0 || r.height() < 0) {
5242 // For grabbing widgets that haven't been shown yet,
5243 // we trigger the layouting mechanism to determine the widget's size.
5244 r = d->prepareToRender(QRegion(), renderFlags).boundingRect();
5245 r.setTopLeft(rectangle.topLeft());
5246 }
5247
5248 if (!r.intersects(rect()))
5249 return QPixmap();
5250
5251 const qreal dpr = devicePixelRatio();
5252 QPixmap res((QSizeF(r.size()) * dpr).toSize());
5253 res.setDevicePixelRatio(dpr);
5254 if (!d->isOpaque)
5255 res.fill(Qt::transparent);
5256 d->render(&res, QPoint(), QRegion(r), renderFlags);
5257
5258 d->dirtyOpaqueChildren = oldDirtyOpaqueChildren;
5259 return res;
5260}
5261
5272#if QT_CONFIG(graphicseffect)
5273QGraphicsEffect *QWidget::graphicsEffect() const
5274{
5275 Q_D(const QWidget);
5276 return d->graphicsEffect;
5277}
5278#endif // QT_CONFIG(graphicseffect)
5279
5302#if QT_CONFIG(graphicseffect)
5303void QWidget::setGraphicsEffect(QGraphicsEffect *effect)
5304{
5305 Q_D(QWidget);
5306 if (d->graphicsEffect == effect)
5307 return;
5308
5309 if (d->graphicsEffect) {
5310 d->invalidateBackingStore(rect());
5311 delete d->graphicsEffect;
5312 d->graphicsEffect = nullptr;
5313 }
5314
5315 if (effect) {
5316 // Set new effect.
5319 d->graphicsEffect = effect;
5320 effect->d_func()->setGraphicsEffectSource(source);
5321 update();
5322 }
5323
5324 d->updateIsOpaque();
5325}
5326#endif // QT_CONFIG(graphicseffect)
5327
5329{
5330 if (data.in_show)
5331 return true;
5332
5333 Q_Q(const QWidget);
5334 if (q->isHidden())
5335 return false;
5336
5337 // The widget will be shown if any of its ancestors are about to show.
5338 QWidget *parent = q->parentWidget();
5339 return parent ? parent->d_func()->isAboutToShow() : false;
5340}
5341
5342QRegion QWidgetPrivate::prepareToRender(const QRegion &region, QWidget::RenderFlags renderFlags)
5343{
5344 Q_Q(QWidget);
5345 const bool isVisible = q->isVisible();
5346
5347 // Make sure the widget is laid out correctly.
5348 if (!isVisible && !isAboutToShow()) {
5349 QWidget *topLevel = q->window();
5350 (void)topLevel->d_func()->topData(); // Make sure we at least have top-data.
5351 topLevel->ensurePolished();
5352
5353 // Invalidate the layout of hidden ancestors (incl. myself) and pretend
5354 // they're not explicitly hidden.
5355 QWidget *widget = q;
5356 QWidgetList hiddenWidgets;
5357 while (widget) {
5358 if (widget->isHidden()) {
5360 hiddenWidgets.append(widget);
5361 if (!widget->isWindow() && widget->parentWidget()->d_func()->layout)
5362 widget->d_func()->updateGeometry_helper(true);
5363 }
5365 }
5366
5367 // Activate top-level layout.
5368 if (topLevel->d_func()->layout)
5369 topLevel->d_func()->layout->activate();
5370
5371 // Adjust size if necessary.
5372 QTLWExtra *topLevelExtra = topLevel->d_func()->maybeTopData();
5373 if (topLevelExtra && !topLevelExtra->sizeAdjusted
5374 && !topLevel->testAttribute(Qt::WA_Resized)) {
5375 topLevel->adjustSize();
5376 topLevel->setAttribute(Qt::WA_Resized, false);
5377 }
5378
5379 // Activate child layouts.
5380 topLevel->d_func()->activateChildLayoutsRecursively();
5381
5382 // We're not cheating with WA_WState_Hidden anymore.
5383 for (int i = 0; i < hiddenWidgets.size(); ++i) {
5384 QWidget *widget = hiddenWidgets.at(i);
5386 if (!widget->isWindow() && widget->parentWidget()->d_func()->layout)
5387 widget->parentWidget()->d_func()->layout->invalidate();
5388 }
5389 } else if (isVisible) {
5390 q->window()->d_func()->sendPendingMoveAndResizeEvents(true, true);
5391 }
5392
5393 // Calculate the region to be painted.
5394 QRegion toBePainted = !region.isEmpty() ? region : QRegion(q->rect());
5395 if (!(renderFlags & QWidget::IgnoreMask) && extra && extra->hasMask)
5396 toBePainted &= extra->mask;
5397 return toBePainted;
5398}
5399
5400void QWidgetPrivate::render_helper(QPainter *painter, const QPoint &targetOffset, const QRegion &toBePainted,
5401 QWidget::RenderFlags renderFlags)
5402{
5404 Q_ASSERT(!toBePainted.isEmpty());
5405
5406 Q_Q(QWidget);
5407 const QTransform originalTransform = painter->worldTransform();
5408 const bool useDeviceCoordinates = originalTransform.isScaling();
5409 if (!useDeviceCoordinates) {
5410 // Render via a pixmap.
5411 const QRect rect = toBePainted.boundingRect();
5412 const QSize size = rect.size();
5413 if (size.isNull())
5414 return;
5415
5416 const qreal pixmapDevicePixelRatio = painter->device()->devicePixelRatio();
5417 QPixmap pixmap(size * pixmapDevicePixelRatio);
5418 pixmap.setDevicePixelRatio(pixmapDevicePixelRatio);
5419
5420 if (!(renderFlags & QWidget::DrawWindowBackground) || !isOpaque)
5421 pixmap.fill(Qt::transparent);
5422 q->render(&pixmap, QPoint(), toBePainted, renderFlags);
5423
5424 const bool restore = !(painter->renderHints() & QPainter::SmoothPixmapTransform);
5426
5427 painter->drawPixmap(targetOffset, pixmap);
5428
5429 if (restore)
5431
5432 } else {
5433 // Render via a pixmap in device coordinates (to avoid pixmap scaling).
5434 QTransform transform = originalTransform;
5435 transform.translate(targetOffset.x(), targetOffset.y());
5436
5439
5440 // Calculate device rect.
5441 const QRectF rect(toBePainted.boundingRect());
5442 QRect deviceRect = transform.mapRect(QRectF(0, 0, rect.width(), rect.height())).toAlignedRect();
5443 deviceRect &= QRect(0, 0, device->width(), device->height());
5444
5446 pixmap.fill(Qt::transparent);
5447
5448 // Create a pixmap device coordinate painter.
5449 QPainter pixmapPainter(&pixmap);
5450 pixmapPainter.setRenderHints(painter->renderHints());
5452 pixmapPainter.setTransform(transform);
5453
5454 q->render(&pixmapPainter, QPoint(), toBePainted, renderFlags);
5455 pixmapPainter.end();
5456
5457 // And then draw the pixmap.
5460 painter->setTransform(originalTransform);
5461 }
5462}
5463
5464void QWidgetPrivate::drawWidget(QPaintDevice *pdev, const QRegion &rgn, const QPoint &offset, DrawWidgetFlags flags,
5465 QPainter *sharedPainter, QWidgetRepaintManager *repaintManager)
5466{
5467 if (rgn.isEmpty())
5468 return;
5469
5470 Q_Q(QWidget);
5471
5472 qCInfo(lcWidgetPainting) << "Drawing" << rgn << "of" << q << "at" << offset
5473 << "into paint device" << pdev << "with" << flags;
5474
5475 const bool asRoot = flags & DrawAsRoot;
5476 bool onScreen = shouldPaintOnScreen();
5477
5478#if QT_CONFIG(graphicseffect)
5481 QWidgetEffectSourcePrivate *sourced = static_cast<QWidgetEffectSourcePrivate *>
5482 (source->d_func());
5483 if (!sourced->context) {
5484 const QRegion effectRgn((flags & UseEffectRegionBounds) ? rgn.boundingRect() : rgn);
5485 QWidgetPaintContext context(pdev, effectRgn, offset, flags, sharedPainter, repaintManager);
5486 sourced->context = &context;
5487 if (!sharedPainter) {
5488 setSystemClip(pdev->paintEngine(), pdev->devicePixelRatio(), effectRgn.translated(offset));
5489 QPainter p(pdev);
5490 p.translate(offset);
5491 context.painter = &p;
5493 setSystemClip(pdev->paintEngine(), 1, QRegion());
5494 } else {
5495 context.painter = sharedPainter;
5496 if (sharedPainter->worldTransform() != sourced->lastEffectTransform) {
5497 sourced->invalidateCache();
5498 sourced->lastEffectTransform = sharedPainter->worldTransform();
5499 }
5506 }
5507 sourced->context = nullptr;
5508
5509 if (repaintManager)
5510 repaintManager->markNeedsFlush(q, effectRgn, offset);
5511
5512 return;
5513 }
5514 }
5515#endif // QT_CONFIG(graphicseffect)
5516 flags = flags & ~UseEffectRegionBounds;
5517
5518 const bool alsoOnScreen = flags & DrawPaintOnScreen;
5519 const bool recursive = flags & DrawRecursive;
5520 const bool alsoInvisible = flags & DrawInvisible;
5521
5523
5524 QRegion toBePainted(rgn);
5525 if (asRoot && !alsoInvisible)
5526 toBePainted &= clipRect(); //(rgn & visibleRegion());
5528 subtractOpaqueChildren(toBePainted, q->rect());
5529
5530 if (!toBePainted.isEmpty()) {
5531 if (!onScreen || alsoOnScreen) {
5532 //update the "in paint event" flag
5533 if (Q_UNLIKELY(q->testAttribute(Qt::WA_WState_InPaintEvent)))
5534 qWarning("QWidget::repaint: Recursive repaint detected");
5535 q->setAttribute(Qt::WA_WState_InPaintEvent);
5536
5537 //clip away the new area
5538 QPaintEngine *paintEngine = pdev->paintEngine();
5539 if (paintEngine) {
5540 setRedirected(pdev, -offset);
5541
5542 if (sharedPainter)
5543 setSystemClip(pdev->paintEngine(), pdev->devicePixelRatio(), toBePainted);
5544 else
5545 paintEngine->d_func()->systemRect = q->data->crect;
5546
5547 //paint the background
5548 if ((asRoot || q->autoFillBackground() || onScreen || q->testAttribute(Qt::WA_StyledBackground))
5549 && !q->testAttribute(Qt::WA_OpaquePaintEvent) && !q->testAttribute(Qt::WA_NoSystemBackground)) {
5551 QPainter p(q);
5552 p.setRenderHint(QPainter::SmoothPixmapTransform);
5553 paintBackground(&p, toBePainted, (asRoot || onScreen) ? (flags | DrawAsRoot) : DrawWidgetFlags());
5555 }
5556
5557 if (!sharedPainter)
5558 setSystemClip(pdev->paintEngine(), pdev->devicePixelRatio(), toBePainted.translated(offset));
5559
5560 if (!onScreen && !asRoot && !isOpaque && q->testAttribute(Qt::WA_TintedBackground)) {
5562 QPainter p(q);
5563 QColor tint = q->palette().window().color();
5564 tint.setAlphaF(.6f);
5565 p.fillRect(toBePainted.boundingRect(), tint);
5567 }
5568 }
5569
5570#if 0
5571 qDebug() << "painting" << q << "opaque ==" << isOpaque();
5572 qDebug() << "clipping to" << toBePainted << "location == " << offset
5573 << "geometry ==" << QRect(q->mapTo(q->window(), QPoint(0, 0)), q->size());
5574#endif
5575
5576 bool skipPaintEvent = false;
5577 if (renderToTexture) {
5578 // This widget renders into a texture which is composed later. We just need to
5579 // punch a hole in the backingstore, so the texture will be visible.
5581 if (!q->testAttribute(Qt::WA_AlwaysStackOnTop) && repaintManager) {
5582 QPainter p(q);
5583 p.setCompositionMode(QPainter::CompositionMode_Source);
5584 p.fillRect(q->rect(), Qt::transparent);
5585 } else if (!repaintManager) {
5586 // We are not drawing to a backingstore: fall back to QImage
5588 // grabFramebuffer() always sets the format to RGB32
5589 // regardless of whether it is transparent or not.
5590 if (img.format() == QImage::Format_RGB32)
5591 img.reinterpretAsFormat(QImage::Format_ARGB32_Premultiplied);
5592 QPainter p(q);
5593 p.drawImage(q->rect(), img);
5594 skipPaintEvent = true;
5595 }
5599 else
5600 skipPaintEvent = true;
5601 }
5602
5603 if (!skipPaintEvent) {
5604 //actually send the paint event
5605 sendPaintEvent(toBePainted);
5606 }
5607
5608 if (repaintManager)
5609 repaintManager->markNeedsFlush(q, toBePainted, offset);
5610
5611 //restore
5612 if (paintEngine) {
5614 if (!sharedPainter)
5615 paintEngine->d_func()->systemRect = QRect();
5616 else
5617 paintEngine->d_func()->currentClipDevice = nullptr;
5618
5619 setSystemClip(pdev->paintEngine(), 1, QRegion());
5620 }
5621 q->setAttribute(Qt::WA_WState_InPaintEvent, false);
5622 if (Q_UNLIKELY(q->paintingActive()))
5623 qWarning("QWidget::repaint: It is dangerous to leave painters active on a widget outside of the PaintEvent");
5624
5625 if (paintEngine && paintEngine->autoDestruct()) {
5626 delete paintEngine;
5627 }
5628 } else if (q->isWindow()) {
5629 QPaintEngine *engine = pdev->paintEngine();
5630 if (engine) {
5631 QPainter p(pdev);
5632 p.setClipRegion(toBePainted);
5633 const QBrush bg = q->palette().brush(QPalette::Window);
5634 if (bg.style() == Qt::TexturePattern)
5635 p.drawTiledPixmap(q->rect(), bg.texture());
5636 else
5637 p.fillRect(q->rect(), bg);
5638
5639 if (engine->autoDestruct())
5640 delete engine;
5641 }
5642 }
5643 }
5644
5645 if (recursive && !children.isEmpty()) {
5647 sharedPainter, repaintManager);
5648 }
5649}
5650
5652{
5653 Q_Q(QWidget);
5654 QPaintEvent e(toBePainted);
5655 QCoreApplication::sendSpontaneousEvent(q, &e);
5656
5657 if (renderToTexture)
5659}
5660
5662 const QRegion &sourceRegion, QWidget::RenderFlags renderFlags)
5663{
5664 if (Q_UNLIKELY(!target)) {
5665 qWarning("QWidget::render: null pointer to paint device");
5666 return;
5667 }
5668
5669 const bool inRenderWithPainter = extra && extra->inRenderWithPainter;
5670 QRegion paintRegion = !inRenderWithPainter
5671 ? prepareToRender(sourceRegion, renderFlags)
5672 : sourceRegion;
5673 if (paintRegion.isEmpty())
5674 return;
5675
5676 QPainter *oldSharedPainter = inRenderWithPainter ? sharedPainter() : nullptr;
5677
5678 // Use the target's shared painter if set (typically set when doing
5679 // "other->render(widget);" in the widget's paintEvent.
5680 if (target->devType() == QInternal::Widget) {
5681 QWidgetPrivate *targetPrivate = static_cast<QWidget *>(target)->d_func();
5682 if (targetPrivate->extra && targetPrivate->extra->inRenderWithPainter) {
5683 QPainter *targetPainter = targetPrivate->sharedPainter();
5684 if (targetPainter && targetPainter->isActive())
5685 setSharedPainter(targetPainter);
5686 }
5687 }
5688
5689 // Use the target's redirected device if set and adjust offset and paint
5690 // region accordingly. This is typically the case when people call render
5691 // from the paintEvent.
5692 QPoint offset = targetOffset;
5693 offset -= paintRegion.boundingRect().topLeft();
5694 QPoint redirectionOffset;
5695 QPaintDevice *redirected = nullptr;
5696
5697 if (target->devType() == QInternal::Widget)
5698 redirected = static_cast<QWidget *>(target)->d_func()->redirected(&redirectionOffset);
5699
5700 if (redirected) {
5702 offset -= redirectionOffset;
5703 }
5704
5705 if (!inRenderWithPainter) { // Clip handled by shared painter (in qpainter.cpp).
5706 if (QPaintEngine *targetEngine = target->paintEngine()) {
5707 const QRegion targetSystemClip = targetEngine->systemClip();
5708 if (!targetSystemClip.isEmpty())
5709 paintRegion &= targetSystemClip.translated(-offset);
5710 }
5711 }
5712
5713 // Set backingstore flags.
5714 DrawWidgetFlags flags = DrawPaintOnScreen | DrawInvisible;
5715 if (renderFlags & QWidget::DrawWindowBackground)
5716 flags |= DrawAsRoot;
5717
5718 if (renderFlags & QWidget::DrawChildren)
5720 else
5722
5724
5725 // Render via backingstore.
5726 drawWidget(target, paintRegion, offset, flags, sharedPainter());
5727
5728 // Restore shared painter.
5729 if (oldSharedPainter)
5730 setSharedPainter(oldSharedPainter);
5731}
5732
5734 const QPoint &offset, DrawWidgetFlags flags
5735 , QPainter *sharedPainter, QWidgetRepaintManager *repaintManager)
5736{
5737 QWidget *w = nullptr;
5739 bool dirtyBoundingRect = true;
5740 const bool exludeOpaqueChildren = (flags & DontDrawOpaqueChildren);
5741 const bool excludeNativeChildren = (flags & DontDrawNativeChildren);
5742
5743 do {
5744 QWidget *x = qobject_cast<QWidget*>(siblings.at(index));
5745 if (x && !(exludeOpaqueChildren && x->d_func()->isOpaque) && !x->isHidden() && !x->isWindow()
5746 && !(excludeNativeChildren && x->internalWinId())) {
5747 if (dirtyBoundingRect) {
5748 boundingRect = rgn.boundingRect();
5749 dirtyBoundingRect = false;
5750 }
5751
5752 if (qRectIntersects(boundingRect, x->d_func()->effectiveRectFor(x->data->crect))) {
5753 w = x;
5754 break;
5755 }
5756 }
5757 --index;
5758 } while (index >= 0);
5759
5760 if (!w)
5761 return;
5762
5763 QWidgetPrivate *wd = w->d_func();
5764 const QPoint widgetPos(w->data->crect.topLeft());
5765 const bool hasMask = wd->extra && wd->extra->hasMask && !wd->graphicsEffect;
5766 if (index > 0) {
5767 QRegion wr(rgn);
5768 if (wd->isOpaque)
5769 wr -= hasMask ? wd->extra->mask.translated(widgetPos) : w->data->crect;
5770 paintSiblingsRecursive(pdev, siblings, --index, wr, offset, flags,
5771 sharedPainter, repaintManager);
5772 }
5773
5774 if (w->updatesEnabled()
5775#if QT_CONFIG(graphicsview)
5776 && (!w->d_func()->extra || !w->d_func()->extra->proxyWidget)
5777#endif // QT_CONFIG(graphicsview)
5778 ) {
5779 QRegion wRegion(rgn);
5780 wRegion &= wd->effectiveRectFor(w->data->crect);
5781 wRegion.translate(-widgetPos);
5782 if (hasMask)
5783 wRegion &= wd->extra->mask;
5784 wd->drawWidget(pdev, wRegion, offset + widgetPos, flags, sharedPainter, repaintManager);
5785 }
5786}
5787
5788#if QT_CONFIG(graphicseffect)
5789QRectF QWidgetEffectSourcePrivate::boundingRect(Qt::CoordinateSystem system) const
5790{
5791 if (system != Qt::DeviceCoordinates)
5792 return m_widget->rect();
5793
5794 if (Q_UNLIKELY(!context)) {
5795 // Device coordinates without context not yet supported.
5796 qWarning("QGraphicsEffectSource::boundingRect: Not yet implemented, lacking device context");
5797 return QRectF();
5798 }
5799
5800 return context->painter->worldTransform().mapRect(m_widget->rect());
5801}
5802
5803void QWidgetEffectSourcePrivate::draw(QPainter *painter)
5804{
5805 if (!context || context->painter != painter) {
5806 m_widget->render(painter);
5807 return;
5808 }
5809
5810 // The region saved in the context is neither clipped to the rect
5811 // nor the mask, so we have to clip it here before calling drawWidget.
5812 QRegion toBePainted = context->rgn;
5813 toBePainted &= m_widget->rect();
5814 QWidgetPrivate *wd = qt_widget_private(m_widget);
5815 if (wd->extra && wd->extra->hasMask)
5816 toBePainted &= wd->extra->mask;
5817
5818 wd->drawWidget(context->pdev, toBePainted, context->offset, context->flags,
5819 context->sharedPainter, context->repaintManager);
5820}
5821
5822QPixmap QWidgetEffectSourcePrivate::pixmap(Qt::CoordinateSystem system, QPoint *offset,
5824{
5825 const bool deviceCoordinates = (system == Qt::DeviceCoordinates);
5826 if (Q_UNLIKELY(!context && deviceCoordinates)) {
5827 // Device coordinates without context not yet supported.
5828 qWarning("QGraphicsEffectSource::pixmap: Not yet implemented, lacking device context");
5829 return QPixmap();
5830 }
5831
5832 QPoint pixmapOffset;
5833 QRectF sourceRect = m_widget->rect();
5834
5835 if (deviceCoordinates) {
5836 const QTransform &painterTransform = context->painter->worldTransform();
5837 sourceRect = painterTransform.mapRect(sourceRect);
5838 pixmapOffset = painterTransform.map(pixmapOffset);
5839 }
5840
5841 QRect effectRect;
5842
5844 effectRect = m_widget->graphicsEffect()->boundingRectFor(sourceRect).toAlignedRect();
5846 effectRect = sourceRect.adjusted(-1, -1, 1, 1).toAlignedRect();
5847 else
5848 effectRect = sourceRect.toAlignedRect();
5849
5850 if (offset)
5851 *offset = effectRect.topLeft();
5852
5853 pixmapOffset -= effectRect.topLeft();
5854
5855 qreal dpr(1.0);
5856 if (const auto *paintDevice = context->painter->device())
5857 dpr = paintDevice->devicePixelRatio();
5858 else
5859 qWarning("QWidgetEffectSourcePrivate::pixmap: Painter not active");
5860 QPixmap pixmap(effectRect.size() * dpr);
5861 pixmap.setDevicePixelRatio(dpr);
5862
5863 pixmap.fill(Qt::transparent);
5864 m_widget->render(&pixmap, pixmapOffset, QRegion(), QWidget::DrawChildren);
5865 return pixmap;
5866}
5867#endif // QT_CONFIG(graphicseffect)
5868
5869#if QT_CONFIG(graphicsview)
5878QGraphicsProxyWidget *QWidgetPrivate::nearestGraphicsProxyWidget(const QWidget *origin)
5879{
5880 if (origin) {
5881 const auto &extra = origin->d_func()->extra;
5882 if (extra && extra->proxyWidget)
5883 return extra->proxyWidget;
5884 return nearestGraphicsProxyWidget(origin->parentWidget());
5885 }
5886 return nullptr;
5887}
5888#endif
5889
5906{
5907 Q_Q(QWidget);
5908 if (locale == loc && !forceUpdate)
5909 return;
5910
5911 locale = loc;
5912
5913 if (!children.isEmpty()) {
5914 for (int i = 0; i < children.size(); ++i) {
5916 if (!w)
5917 continue;
5918 if (w->testAttribute(Qt::WA_SetLocale))
5919 continue;
5920 if (w->isWindow() && !w->testAttribute(Qt::WA_WindowPropagation))
5921 continue;
5922 w->d_func()->setLocale_helper(loc, forceUpdate);
5923 }
5924 }
5927}
5928
5929void QWidget::setLocale(const QLocale &locale)
5930{
5931 Q_D(QWidget);
5932
5934 d->setLocale_helper(locale);
5935}
5936
5938{
5939 Q_D(const QWidget);
5940
5941 return d->locale;
5942}
5943
5945{
5946 Q_Q(const QWidget);
5947
5948 if (!q->testAttribute(Qt::WA_SetLocale)) {
5949 QWidget *parent = q->parentWidget();
5950 setLocale_helper(!parent || (q->isWindow() && !q->testAttribute(Qt::WA_WindowPropagation))
5951 ? QLocale() : parent->locale());
5952 }
5953}
5954
5956{
5957 Q_D(QWidget);
5959 d->resolveLocale();
5960}
5961
5986{
5987 Q_D(const QWidget);
5988 if (d->extra && d->extra->topextra) {
5989 if (!d->extra->topextra->caption.isEmpty())
5990 return d->extra->topextra->caption;
5991 if (!d->extra->topextra->filePath.isEmpty())
5992 return QFileInfo(d->extra->topextra->filePath).fileName() + "[*]"_L1;
5993 }
5994 return QString();
5995}
5996
6009{
6011
6012 QString cap = title;
6013 if (cap.isEmpty())
6014 return cap;
6015
6016 const auto placeHolder = "[*]"_L1;
6017 int index = cap.indexOf(placeHolder);
6018
6019 // here the magic begins
6020 while (index != -1) {
6021 index += placeHolder.size();
6022 int count = 1;
6023 while (cap.indexOf(placeHolder, index) == index) {
6024 ++count;
6025 index += placeHolder.size();
6026 }
6027
6028 if (count%2) { // odd number of [*] -> replace last one
6029 int lastIndex = cap.lastIndexOf(placeHolder, index - 1);
6032 cap.replace(lastIndex, 3, QWidget::tr("*"));
6033 else
6034 cap.remove(lastIndex, 3);
6035 }
6036
6037 index = cap.indexOf(placeHolder, index);
6038 }
6039
6040 cap.replace("[*][*]"_L1, placeHolder);
6041
6042 return cap;
6043}
6044
6051
6053{
6054 Q_Q(QWidget);
6055 if (!q->isWindow())
6056 return;
6057
6058 if (QWindow *window = q->windowHandle())
6059 window->setTitle(caption);
6060
6061}
6062
6069
6071{
6072#if QT_CONFIG(xcb)
6073 Q_Q(QWidget);
6074 // ### The QWidget property is deprecated, but the XCB window function is not.
6075 // It should remain available for the rare application that needs it.
6076 if (QWindow *window = q->windowHandle()) {
6077 if (auto *xcbWindow = dynamic_cast<QXcbWindow*>(window->handle()))
6078 xcbWindow->setWindowIconText(iconText);
6079 }
6080#else
6081 Q_UNUSED(iconText);
6082#endif
6083}
6084
6098{
6099 if (QWidget::windowIconText() == iconText)
6100 return;
6101
6102 Q_D(QWidget);
6103 d->topData()->iconText = iconText;
6104 d->setWindowIconText_helper(iconText);
6105
6108
6109 emit windowIconTextChanged(iconText);
6110}
6111
6122{
6123 if (QWidget::windowTitle() == title && !title.isEmpty() && !title.isNull())
6124 return;
6125
6126#if QT_CONFIG(accessibility)
6127 QString oldAccessibleName;
6128 const QAccessibleInterface *accessible = QAccessible::queryAccessibleInterface(this);
6129 if (accessible)
6130 oldAccessibleName = accessible->text(QAccessible::Name);
6131#endif
6132
6133 Q_D(QWidget);
6134 d->topData()->caption = title;
6135 d->setWindowTitle_helper(title);
6136
6139
6141
6142#if QT_CONFIG(accessibility)
6143 if (accessible && accessible->text(QAccessible::Name) != oldAccessibleName) {
6144 QAccessibleEvent event(this, QAccessible::NameChanged);
6145 QAccessible::updateAccessibility(&event);
6146 }
6147#endif
6148}
6149
6150
6166{
6167 const QWidget *w = this;
6168 while (w) {
6169 const QWidgetPrivate *d = w->d_func();
6170 if (d->extra && d->extra->topextra && d->extra->topextra->icon)
6171 return *d->extra->topextra->icon;
6172 w = w->parentWidget();
6173 }
6174 return QApplication::windowIcon();
6175}
6176
6178{
6179 Q_Q(QWidget);
6181
6182 // Do not send the event if the widget is a top level.
6183 // In that case, setWindowIcon_sys does it, and event propagation from
6184 // QWidgetWindow to the top level QWidget ensures that the event reaches
6185 // the top level anyhow
6186 if (!q->windowHandle())
6188 for (int i = 0; i < children.size(); ++i) {
6190 if (w && !w->isWindow())
6192 }
6193}
6194
6205{
6206 Q_D(QWidget);
6207
6209 d->createTLExtra();
6210
6211 if (!d->extra->topextra->icon)
6212 d->extra->topextra->icon = std::make_unique<QIcon>(icon);
6213 else
6214 *d->extra->topextra->icon = icon;
6215
6216 d->setWindowIcon_sys();
6217 d->setWindowIcon_helper();
6218
6220}
6221
6223{
6224 Q_Q(QWidget);
6225 if (QWindow *window = q->windowHandle())
6226 window->setIcon(q->windowIcon());
6227}
6228
6245{
6246 Q_D(const QWidget);
6247 return (d->extra && d->extra->topextra) ? d->extra->topextra->iconText : QString();
6248}
6249
6275{
6276 Q_D(const QWidget);
6277 return (d->extra && d->extra->topextra) ? d->extra->topextra->filePath : QString();
6278}
6279
6281{
6282 if (filePath == windowFilePath())
6283 return;
6284
6285 Q_D(QWidget);
6286
6287 d->createTLExtra();
6288 d->extra->topextra->filePath = filePath;
6289 d->setWindowFilePath_helper(filePath);
6290}
6291
6293{
6294 if (extra->topextra && extra->topextra->caption.isEmpty()) {
6295#ifdef Q_OS_MAC
6297#else
6298 Q_Q(QWidget);
6299 Q_UNUSED(filePath);
6300 setWindowTitle_helper(q->windowTitle());
6301#endif
6302 }
6303#ifdef Q_OS_MAC
6304 setWindowFilePath_sys(filePath);
6305#endif
6306}
6307
6309{
6310 Q_Q(QWidget);
6311 if (!q->isWindow())
6312 return;
6313
6314 if (QWindow *window = q->windowHandle())
6315 window->setFilePath(filePath);
6316}
6317
6325{
6326 Q_D(const QWidget);
6327 return (d->extra && d->extra->topextra) ? d->extra->topextra->role : QString();
6328}
6329
6335{
6336#if QT_CONFIG(xcb)
6337 Q_D(QWidget);
6338 d->createTLExtra();
6339 d->topData()->role = role;
6340 if (windowHandle()) {
6341 if (auto *xcbWindow = dynamic_cast<QXcbWindow*>(windowHandle()->handle()))
6342 xcbWindow->setWindowRole(role);
6343 }
6344#else
6345 Q_UNUSED(role);
6346#endif
6347}
6348
6399{
6400 Q_D(QWidget);
6401 if (!w && !d->extra)
6402 return;
6403
6404 for (QWidget* fp = w; fp; fp = fp->focusProxy()) {
6405 if (Q_UNLIKELY(fp == this)) {
6406 qWarning("QWidget: %s (%s) already in focus proxy chain", metaObject()->className(), objectName().toLocal8Bit().constData());
6407 return;
6408 }
6409 }
6410
6411 const bool moveFocusToProxy = (QApplicationPrivate::focus_widget == this);
6412
6413 d->createExtra();
6414 d->extra->focus_proxy = w;
6415
6416 if (w && isAncestorOf(w)) {
6417 // If the focus proxy is a child of this (so this is a compound widget), then
6418 // we need to make sure that this widget is immediately in front of its own children
6419 // in the focus chain. Otherwise focusNextPrev_helper might jump over unrelated
6420 // widgets that are positioned between this compound widget, and its proxy in
6421 // the focus chain.
6422 const QWidget *parentOfW = w->parentWidget();
6423 Q_ASSERT(parentOfW); // can't be nullptr since we are an ancestor of w
6424 QWidget *firstChild = nullptr;
6425 const auto childList = children();
6426 for (QObject *child : childList) {
6427 if ((firstChild = qobject_cast<QWidget *>(child)))
6428 break;
6429 }
6430 Q_ASSERT(firstChild); // can't be nullptr since w is a child
6431 d->insertIntoFocusChainBefore(firstChild);
6432 } else if (w && w->isAncestorOf(this)) {
6433 // If the focus proxy is a parent, 'this' has to be inserted directly after its parent in the focus chain
6434 // remove it from the chain and insert this into the focus chain after its parent
6435
6436 // is this the case already?
6437 QWidget *parentsNext = w->nextInFocusChain();
6438 if (parentsNext == this) {
6439 // nothing to do.
6441 } else {
6442 d->QWidgetPrivate::insertIntoFocusChainAfter(w);
6443 }
6444 }
6445
6446 if (moveFocusToProxy)
6448}
6449
6450
6458{
6459 Q_D(const QWidget);
6460 return d->extra ? d->extra->focus_proxy.data() : nullptr;
6461}
6462
6463
6477{
6478 const QWidget* w = this;
6479 while (w->d_func()->extra && w->d_func()->extra->focus_proxy)
6480 w = w->d_func()->extra->focus_proxy;
6481#if QT_CONFIG(graphicsview)
6482 if (QWidget *window = w->window()) {
6483 const auto &e = window->d_func()->extra;
6484 if (e && e->proxyWidget && e->proxyWidget->hasFocus() && window->focusWidget() == w)
6485 return true;
6486 }
6487#endif // QT_CONFIG(graphicsview)
6488 return (QApplication::focusWidget() == w);
6489}
6490
6527{
6528 if (!isEnabled())
6529 return;
6530
6531 QWidget *f = d_func()->deepestFocusProxy();
6532 if (!f)
6533 f = this;
6534
6536 return;
6537
6538#if QT_CONFIG(graphicsview)
6539 QWidget *previousProxyFocus = nullptr;
6540 if (const auto &topData = window()->d_func()->extra) {
6541 if (topData->proxyWidget && topData->proxyWidget->hasFocus()) {
6542 previousProxyFocus = topData->proxyWidget->widget()->focusWidget();
6543 if (previousProxyFocus && previousProxyFocus->focusProxy())
6544 previousProxyFocus = previousProxyFocus->focusProxy();
6545 if (previousProxyFocus == f && !topData->proxyWidget->d_func()->proxyIsGivingFocus)
6546 return;
6547 }
6548 }
6549#endif
6550
6551#if QT_CONFIG(graphicsview)
6552 // Update proxy state
6553 if (const auto &topData = window()->d_func()->extra) {
6554 if (topData->proxyWidget && !topData->proxyWidget->hasFocus()) {
6555 f->d_func()->updateFocusChild();
6556 topData->proxyWidget->d_func()->focusFromWidgetToProxy = 1;
6557 topData->proxyWidget->setFocus(reason);
6558 topData->proxyWidget->d_func()->focusFromWidgetToProxy = 0;
6559 }
6560 }
6561#endif
6562
6563 if (f->isActiveWindow()) {
6565 if (prev) {
6566 if (reason != Qt::PopupFocusReason && reason != Qt::MenuBarFocusReason
6568 QGuiApplication::inputMethod()->commit();
6569 }
6570
6571 if (reason != Qt::NoFocusReason) {
6572 QFocusEvent focusAboutToChange(QEvent::FocusAboutToChange, reason);
6573 QCoreApplication::sendEvent(prev, &focusAboutToChange);
6574 }
6575 }
6576
6577 f->d_func()->updateFocusChild();
6578
6580#if QT_CONFIG(accessibility)
6581 // menus update the focus manually and this would create bogus events
6582 if (!(f->inherits("QMenuBar") || f->inherits("QMenu") || f->inherits("QMenuItem")))
6583 {
6584 QAccessibleEvent event(f, QAccessible::Focus);
6585 QAccessible::updateAccessibility(&event);
6586 }
6587#endif
6588#if QT_CONFIG(graphicsview)
6589 if (const auto &topData = window()->d_func()->extra) {
6590 if (topData->proxyWidget) {
6591 if (previousProxyFocus && previousProxyFocus != f) {
6592 // Send event to self
6594 QPointer<QWidget> that = previousProxyFocus;
6595 QCoreApplication::sendEvent(previousProxyFocus, &event);
6596 if (that)
6597 QCoreApplication::sendEvent(that->style(), &event);
6598 }
6599 if (!isHidden()) {
6600#if QT_CONFIG(graphicsview)
6601 // Update proxy state
6602 if (const auto &topData = window()->d_func()->extra)
6603 if (topData->proxyWidget && topData->proxyWidget->hasFocus())
6604 topData->proxyWidget->d_func()->updateProxyInputMethodAcceptanceFromWidget();
6605#endif
6606 // Send event to self
6608 QPointer<QWidget> that = f;
6610 if (that)
6611 QCoreApplication::sendEvent(that->style(), &event);
6612 }
6613 }
6614 }
6615#endif
6616 } else {
6617 f->d_func()->updateFocusChild();
6618 }
6619}
6620
6621
6629{
6630 Q_Q(const QWidget);
6631
6632 QWidget *focusProxy = q->focusProxy();
6633 if (!focusProxy)
6634 return nullptr;
6635
6636 while (QWidget *nextFocusProxy = focusProxy->focusProxy())
6637 focusProxy = nextFocusProxy;
6638
6639 return focusProxy;
6640}
6641
6642static inline bool isEmbedded(const QWindow *w)
6643{
6644 const auto platformWindow = w->handle();
6645 return platformWindow && platformWindow->isEmbedded();
6646}
6647
6649{
6650 Q_Q(QWidget);
6651 // Embedded native widget may have taken the focus; get it back to toplevel
6652 // if that is the case (QTBUG-25852), unless widget is a window container.
6653 if (extra && extra->hasWindowContainer)
6654 return;
6655 // Do not activate in case the popup menu opens another application (QTBUG-70810)
6656 // unless the application is embedded (QTBUG-71991).
6657 if (QWindow *nativeWindow = q->testAttribute(Qt::WA_WState_Created) ? q->window()->windowHandle() : nullptr) {
6661 || isEmbedded(nativeWindow))) {
6662 nativeWindow->requestActivate();
6663 }
6664 }
6665}
6666
6667// updates focus_child on parent widgets to point into this widget
6669{
6670 Q_Q(QWidget);
6671
6672 QWidget *w = q;
6673 if (q->isHidden()) {
6674 while (w && w->isHidden()) {
6675 w->d_func()->focus_child = q;
6676 w = w->isWindow() ? nullptr : w->parentWidget();
6677 }
6678 } else {
6679 while (w) {
6680 w->d_func()->focus_child = q;
6681 w = w->isWindow() ? nullptr : w->parentWidget();
6682 }
6683 }
6684
6685 if (QTLWExtra *extra = q->window()->d_func()->maybeTopData()) {
6686 if (extra->window)
6687 emit extra->window->focusObjectChanged(q);
6688 }
6689}
6690
6714{
6715 if (hasFocus()) {
6717 QGuiApplication::inputMethod()->commit();
6718
6719 QFocusEvent focusAboutToChange(QEvent::FocusAboutToChange);
6720 QCoreApplication::sendEvent(this, &focusAboutToChange);
6721 }
6722
6723 QTLWExtra *extra = window()->d_func()->maybeTopData();
6724 QObject *originalFocusObject = nullptr;
6725 if (extra && extra->window) {
6726 originalFocusObject = extra->window->focusObject();
6727 // the window's focus object might already be nullptr if we are in the destructor, but we still
6728 // need to update QGuiApplication and input context if we have a focus widget.
6729 if (!originalFocusObject)
6730 originalFocusObject = focusWidget();
6731 }
6732
6733 QWidget *w = this;
6734 while (w) {
6735 // Just like setFocus(), we update (clear) the focus_child of our parents
6736 if (w->d_func()->focus_child == this)
6737 w->d_func()->focus_child = nullptr;
6738 w = w->parentWidget();
6739 }
6740
6741 // We've potentially cleared the focus_child of our parents, so we need
6742 // to report this to the rest of Qt. Note that the focus_child is not the same
6743 // thing as the application's focusWidget, which is why this piece of code is
6744 // not inside a hasFocus() block.
6745 if (originalFocusObject && originalFocusObject != extra->window->focusObject())
6746 emit extra->window->focusObjectChanged(extra->window->focusObject());
6747
6748#if QT_CONFIG(graphicsview)
6749 const auto &topData = d_func()->extra;
6750 if (topData && topData->proxyWidget)
6751 topData->proxyWidget->clearFocus();
6752#endif
6753
6754 if (hasFocus()) {
6755 // Update proxy state
6757#if QT_CONFIG(accessibility)
6758 QAccessibleEvent event(this, QAccessible::Focus);
6759 QAccessible::updateAccessibility(&event);
6760#endif
6761 }
6762}
6763
6764
6808{
6809 QWidget* p = parentWidget();
6810 bool isSubWindow = (windowType() == Qt::SubWindow);
6811 if (!isWindow() && !isSubWindow && p)
6812 return p->focusNextPrevChild(next);
6813#if QT_CONFIG(graphicsview)
6814 Q_D(QWidget);
6815 if (d->extra && d->extra->proxyWidget)
6816 return d->extra->proxyWidget->focusNextPrevChild(next);
6817#endif
6818
6819 bool wrappingOccurred = false;
6821 &wrappingOccurred);
6822 if (!w) return false;
6823
6825
6826 /* If we are about to wrap the focus chain, give the platform
6827 * implementation a chance to alter the wrapping behavior. This is
6828 * especially needed when the window is embedded in a window created by
6829 * another process.
6830 */
6831 if (wrappingOccurred) {
6833 if (window != nullptr) {
6835
6836 if (winp->platformWindow != nullptr) {
6838 event.ignore();
6839 winp->platformWindow->windowEvent(&event);
6840 if (event.isAccepted()) return true;
6841 }
6842 }
6843 }
6844
6845 w->setFocus(reason);
6846 return true;
6847}
6848
6859{
6860 return const_cast<QWidget *>(d_func()->focus_child);
6861}
6862
6864{
6865 Q_Q(QWidget);
6867 return proxy ? proxy : q;
6868}
6869
6876{
6877 Q_D(const QWidget);
6878 return d->nextPrevElementInFocusChain(QWidgetPrivate::FocusDirection::Next);
6879}
6880
6890{
6891 Q_D(const QWidget);
6892 return d->nextPrevElementInFocusChain(QWidgetPrivate::FocusDirection::Previous);
6893}
6894
6911{
6912 QWidget *tlw = window();
6913 if (tlw == QApplication::activeWindow() || (isVisible() && (tlw->windowType() == Qt::Popup)))
6914 return true;
6915
6916#if QT_CONFIG(graphicsview)
6917 if (const auto &tlwExtra = tlw->d_func()->extra) {
6918 if (isVisible() && tlwExtra->proxyWidget)
6919 return tlwExtra->proxyWidget->isActiveWindow();
6920 }
6921#endif
6922
6923 if (style()->styleHint(QStyle::SH_Widget_ShareActivation, nullptr, this)) {
6924 if (tlw->windowType() == Qt::Tool &&
6925 !tlw->isModal() &&
6926 (!tlw->parentWidget() || tlw->parentWidget()->isActiveWindow()))
6927 return true;
6929 while(w && tlw->windowType() == Qt::Tool &&
6930 !w->isModal() && w->parentWidget()) {
6931 w = w->parentWidget()->window();
6932 if (w == tlw)
6933 return true;
6934 }
6935 }
6936
6937 // Check for an active window container
6939 while (ww) {
6940 QWidgetWindow *qww = qobject_cast<QWidgetWindow *>(ww);
6941 QWindowContainer *qwc = qww ? qobject_cast<QWindowContainer *>(qww->widget()) : 0;
6942 if (qwc && qwc->topLevelWidget() == tlw)
6943 return true;
6944 ww = ww->parent();
6945 }
6946 }
6947
6948 // Check if platform adaptation thinks the window is active. This is necessary for
6949 // example in case of ActiveQt servers that are embedded into another application.
6950 // Those are separate processes that are not part of the parent application Qt window/widget
6951 // hierarchy, so they need to rely on native methods to determine if they are part of the
6952 // active window.
6953 if (const QWindow *w = tlw->windowHandle()) {
6954 if (w->handle())
6955 return w->handle()->isActive();
6956 }
6957
6958 return false;
6959}
6960
7012{
7013 if (!first || !second || first == second
7015 || second->focusPolicy() == Qt::NoFocus)
7016 return;
7017
7018 if (Q_UNLIKELY(first->window() != second->window())) {
7019 qWarning("QWidget::setTabOrder: 'first' and 'second' must be in the same window");
7020 return;
7021 }
7022
7023 const auto determineLastFocusChild = [](QWidget *target, QWidget *noFurtherThan)
7024 {
7025 // Since we need to repeat the same logic for both 'first' and 'second', we add a function that
7026 // determines the last focus child for a widget, taking proxies and compound widgets into account.
7027 // If the target is not a compound widget (it doesn't have a focus proxy that points to a child),
7028 // 'lastFocusChild' will be set to the target itself.
7029 QWidget *lastFocusChild = target;
7030
7031 QWidget *focusProxy = target->d_func()->deepestFocusProxy();
7032 if (!focusProxy) {
7033 // QTBUG-81097: Another case is possible here. We can have a child
7034 // widget, that sets its focusProxy() to the parent (target).
7035 // An example of such widget is a QLineEdit, nested into
7036 // a QAbstractSpinBox. In this case such widget should be considered
7037 // the last focus child.
7038 for (auto *object : target->children()) {
7039 QWidget *w = qobject_cast<QWidget*>(object);
7040 if (w && w->focusProxy() == target) {
7041 lastFocusChild = w;
7042 break;
7043 }
7044 }
7045 } else if (target->isAncestorOf(focusProxy)) {
7046 lastFocusChild = focusProxy;
7047 for (QWidget *focusNext = lastFocusChild->nextInFocusChain();
7048 focusNext != focusProxy && target->isAncestorOf(focusNext) && focusNext->window() == focusProxy->window();
7049 focusNext = focusNext->nextInFocusChain()) {
7050 if (focusNext == noFurtherThan)
7051 break;
7052 if (focusNext->focusPolicy() != Qt::NoFocus)
7053 lastFocusChild = focusNext;
7054 }
7055 }
7056 return lastFocusChild;
7057 };
7058 // detect inflection in case we have compound widgets
7059 QWidget *lastFocusChildOfFirst = determineLastFocusChild(first, second);
7060 if (lastFocusChildOfFirst == second)
7061 lastFocusChildOfFirst = first;
7062 QWidget *lastFocusChildOfSecond = determineLastFocusChild(second, first);
7063 if (lastFocusChildOfSecond == first)
7064 lastFocusChildOfSecond = second;
7065
7066 // Return if only NoFocus widgets are between first and second
7067 QWidget *oldPrev = second->previousInFocusChain();
7068 QWidget *prevWithFocus = oldPrev;
7069 while (prevWithFocus->focusPolicy() == Qt::NoFocus)
7070 prevWithFocus = prevWithFocus->previousInFocusChain();
7071 if (prevWithFocus == first)
7072 return;
7073 const QWidgetList chain = QWidgetPrivate::takeFromFocusChain(second, lastFocusChildOfSecond);
7075}
7076
7077void QWidget::setTabOrder(std::initializer_list<QWidget *> widgets)
7078{
7079 QWidget *prev = nullptr;
7080 for (const auto &widget : widgets) {
7081 if (!prev) {
7082 prev = widget;
7083 } else {
7085 prev = widget;
7086 }
7087 }
7088}
7089
7090
7104{
7105 Q_Q(QWidget);
7106 if (oldtlw == q->window())
7107 return; // nothing to do
7108
7109 if (focus_child)
7111
7113}
7114
7123{
7124 Q_D(const QWidget);
7125 if (isWindow() && !(windowType() == Qt::Popup)) {
7126 QRect fs = d->frameStrut();
7127 return QSize(data->crect.width() + fs.left() + fs.right(),
7128 data->crect.height() + fs.top() + fs.bottom());
7129 }
7130 return data->crect.size();
7131}
7132
7141{
7142 Q_D(QWidget);
7145 if (isWindow())
7146 d->topData()->posIncludesFrame = false;
7147 d->setGeometry_sys(p.x() + geometry().x() - QWidget::x(),
7148 p.y() + geometry().y() - QWidget::y(),
7149 width(), height(), true);
7150 d->setDirtyOpaqueRegion();
7151 } else {
7152 // no frame yet: see also QWidgetPrivate::fixPosIncludesFrame(), QWindowPrivate::PositionPolicy.
7153 if (isWindow())
7154 d->topData()->posIncludesFrame = true;
7155 data->crect.moveTopLeft(p); // no frame yet
7157 }
7158
7159 if (d->extra && d->extra->hasWindowContainer)
7161}
7162
7163// move() was invoked with Qt::WA_WState_Created not set (frame geometry
7164// unknown), that is, crect has a position including the frame.
7165// If we can determine the frame strut, fix that and clear the flag.
7166// FIXME: This does not play well with window states other than
7167// Qt::WindowNoState, as we depend on calling setGeometry() on the
7168// platform window after fixing up the position so that the new
7169// geometry is reflected in the platform window, but when the frame
7170// comes in after the window has been shown (e.g. maximized), we're
7171// not in a position to do that kind of fixup.
7173{
7174 Q_Q(QWidget);
7175 if (QTLWExtra *te = maybeTopData()) {
7176 if (te->posIncludesFrame) {
7177 // For Qt::WA_DontShowOnScreen, assume a frame of 0 (for
7178 // example, in QGraphicsProxyWidget).
7179 if (q->testAttribute(Qt::WA_DontShowOnScreen)) {
7180 te->posIncludesFrame = 0;
7181 } else {
7182 if (q->windowHandle() && q->windowHandle()->handle()) {
7184 if (!q->data->fstrut_dirty) {
7185 data.crect.translate(te->frameStrut.x(), te->frameStrut.y());
7186 te->posIncludesFrame = 0;
7187 }
7188 } // windowHandle()
7189 } // !WA_DontShowOnScreen
7190 } // posIncludesFrame
7191 } // QTLWExtra
7192}
7193
7201{
7202 Q_D(QWidget);
7205 d->fixPosIncludesFrame();
7206 d->setGeometry_sys(geometry().x(), geometry().y(), s.width(), s.height(), false);
7207 d->setDirtyOpaqueRegion();
7208 } else {
7209 const auto oldRect = data->crect;
7210 data->crect.setSize(s.boundedTo(maximumSize()).expandedTo(minimumSize()));
7211 if (oldRect != data->crect)
7213 }
7214}
7215
7217{
7218 Q_D(QWidget);
7221 if (isWindow())
7222 d->topData()->posIncludesFrame = 0;
7224 d->setGeometry_sys(r.x(), r.y(), r.width(), r.height(), true);
7225 d->setDirtyOpaqueRegion();
7226 } else {
7227 const auto oldRect = data->crect;
7228 data->crect.setTopLeft(r.topLeft());
7229 data->crect.setSize(r.size().boundedTo(maximumSize()).expandedTo(minimumSize()));
7230 if (oldRect != data->crect) {
7233 }
7234 }
7235
7236 if (d->extra && d->extra->hasWindowContainer)
7238}
7239
7240void QWidgetPrivate::setGeometry_sys(int x, int y, int w, int h, bool isMove)
7241{
7242 Q_Q(QWidget);
7243 if (extra) { // any size restrictions?
7244 w = qMin(w,extra->maxw);
7245 h = qMin(h,extra->maxh);
7246 w = qMax(w,extra->minw);
7247 h = qMax(h,extra->minh);
7248 }
7249
7250 if (q->isWindow() && q->windowHandle()) {
7253 x = 0;
7254 y = 0;
7255 w = q->windowHandle()->width();
7256 h = q->windowHandle()->height();
7257 }
7258 }
7259
7260 QPoint oldp = q->geometry().topLeft();
7261 QSize olds = q->size();
7262 QRect r(x, y, w, h);
7263
7264 bool isResize = olds != r.size();
7265 if (!isMove)
7266 isMove = oldp != r.topLeft();
7267
7268
7269 // We only care about stuff that changes the geometry, or may
7270 // cause the window manager to change its state
7271 if (r.size() == olds && oldp == r.topLeft())
7272 return;
7273
7274 if (!data.in_set_window_state) {
7275 q->data->window_state &= ~Qt::WindowMaximized;
7276 q->data->window_state &= ~Qt::WindowFullScreen;
7277 if (q->isWindow())
7278 topData()->normalGeometry = QRect(0, 0, -1, -1);
7279 }
7280
7281 QPoint oldPos = q->pos();
7282 data.crect = r;
7283
7284 bool needsShow = false;
7285
7286 if (q->isWindow() || q->windowHandle()) {
7287 if (!(data.window_state & Qt::WindowFullScreen) && (w == 0 || h == 0)) {
7288 q->setAttribute(Qt::WA_OutsideWSRange, true);
7289 if (q->isVisible())
7290 hide_sys();
7291 data.crect = QRect(x, y, w, h);
7292 } else if (q->testAttribute(Qt::WA_OutsideWSRange)) {
7293 q->setAttribute(Qt::WA_OutsideWSRange, false);
7294 needsShow = true;
7295 }
7296 }
7297
7298 if (q->isVisible()) {
7299 if (!q->testAttribute(Qt::WA_DontShowOnScreen) && !q->testAttribute(Qt::WA_OutsideWSRange)) {
7300 if (QWindow *win = q->windowHandle()) {
7301 if (q->isWindow()) {
7302 if (isResize && !isMove)
7303 win->resize(w, h);
7304 else if (isMove && !isResize)
7305 win->setPosition(x, y);
7306 else
7307 win->setGeometry(q->geometry());
7308 } else {
7309 QPoint posInNativeParent = q->mapTo(q->nativeParentWidget(),QPoint());
7310 win->setGeometry(QRect(posInNativeParent,r.size()));
7311 }
7312
7313 if (needsShow)
7314 show_sys();
7315 }
7316
7317 if (!q->isWindow()) {
7318 if (renderToTexture) {
7319 QRegion updateRegion(q->geometry());
7320 updateRegion += QRect(oldPos, olds);
7321 q->parentWidget()->d_func()->invalidateBackingStore(updateRegion);
7322 } else if (isMove && !isResize) {
7323 moveRect(QRect(oldPos, olds), x - oldPos.x(), y - oldPos.y());
7324 } else {
7326 }
7327 }
7328 }
7329
7330 if (isMove) {
7331 QMoveEvent e(q->pos(), oldPos);
7333 }
7334 if (isResize) {
7335 QResizeEvent e(r.size(), olds);
7337 if (q->windowHandle())
7338 q->update();
7339 }
7340 } else { // not visible
7341 if (isMove && q->pos() != oldPos)
7342 q->setAttribute(Qt::WA_PendingMoveEvent, true);
7343 if (isResize)
7344 q->setAttribute(Qt::WA_PendingResizeEvent, true);
7345 }
7346
7347}
7348
7367{
7370 stream.setVersion(QDataStream::Qt_4_0);
7371 const quint32 magicNumber = 0x1D9D0CB;
7372 // Version history:
7373 // - Qt 4.2 - 4.8.6, 5.0 - 5.3 : Version 1.0
7374 // - Qt 4.8.6 - today, 5.4 - today: Version 2.0, save screen width in addition to check for high DPI scaling.
7375 // - Qt 5.12 - today : Version 3.0, save QWidget::geometry()
7376 quint16 majorVersion = 3;
7377 quint16 minorVersion = 0;
7378 const int screenNumber = QGuiApplication::screens().indexOf(screen());
7379 stream << magicNumber
7380 << majorVersion
7381 << minorVersion
7382 << frameGeometry()
7383 << normalGeometry()
7384 << qint32(screenNumber)
7387 << qint32(screen()->geometry().width()) // added in 2.0
7388 << geometry(); // added in 3.0
7389 return array;
7390}
7391
7415void QWidgetPrivate::checkRestoredGeometry(const QRect &availableGeometry, QRect *restoredGeometry,
7416 int frameHeight)
7417{
7418 // compare with restored geometry's height increased by frameHeight
7419 const int height = restoredGeometry->height() + frameHeight;
7420
7421 // Step 1: Resize if necessary:
7422 // make height / width 2px smaller than screen, because an exact match would be fullscreen
7423 if (availableGeometry.height() <= height)
7424 restoredGeometry->setHeight(availableGeometry.height() - 2 - frameHeight);
7425 if (availableGeometry.width() <= restoredGeometry->width())
7426 restoredGeometry->setWidth(availableGeometry.width() - 2);
7427
7428 // Step 2: Move if necessary:
7429 // Construct a rectangle from restored Geometry adjusted by frameHeight
7430 const QRect restored = restoredGeometry->adjusted(0, -frameHeight, 0, 0);
7431
7432 // Return if restoredGeometry (including frame) fits into screen
7433 if (availableGeometry.contains(restored))
7434 return;
7435
7436 // (size is correct, but at least one edge is off screen)
7437
7438 // Top out of bounds => move down
7439 if (restored.top() <= availableGeometry.top()) {
7440 restoredGeometry->moveTop(availableGeometry.top() + 1 + frameHeight);
7441 } else if (restored.bottom() >= availableGeometry.bottom()) {
7442 // Bottom out of bounds => move up
7443 restoredGeometry->moveBottom(availableGeometry.bottom() - 1);
7444 }
7445
7446 // Left edge out of bounds => move right
7447 if (restored.left() <= availableGeometry.left()) {
7448 restoredGeometry->moveLeft(availableGeometry.left() + 1);
7449 } else if (restored.right() >= availableGeometry.right()) {
7450 // Right edge out of bounds => move left
7451 restoredGeometry->moveRight(availableGeometry.right() - 1);
7452 }
7453}
7454
7479{
7480 if (geometry.size() < 4)
7481 return false;
7483 stream.setVersion(QDataStream::Qt_4_0);
7484
7485 const quint32 magicNumber = 0x1D9D0CB;
7486 quint32 storedMagicNumber;
7487 stream >> storedMagicNumber;
7488 if (storedMagicNumber != magicNumber)
7489 return false;
7490
7491 const quint16 currentMajorVersion = 3;
7492 quint16 majorVersion = 0;
7493 quint16 minorVersion = 0;
7494
7495 stream >> majorVersion >> minorVersion;
7496
7497 if (majorVersion > currentMajorVersion)
7498 return false;
7499 // (Allow all minor versions.)
7500
7501 QRect restoredFrameGeometry;
7502 QRect restoredGeometry;
7503 QRect restoredNormalGeometry;
7504 qint32 restoredScreenNumber;
7507 qint32 restoredScreenWidth = 0;
7508
7509 stream >> restoredFrameGeometry // Only used for sanity checks in version 0
7510 >> restoredNormalGeometry
7511 >> restoredScreenNumber
7512 >> maximized
7513 >> fullScreen;
7514
7515 if (majorVersion > 1)
7516 stream >> restoredScreenWidth;
7517 if (majorVersion > 2)
7518 stream >> restoredGeometry;
7519
7520 // ### Qt 6 - Perhaps it makes sense to dumb down the restoreGeometry() logic, see QTBUG-69104
7521
7522 if (restoredScreenNumber >= qMax(QGuiApplication::screens().size(), 1))
7523 restoredScreenNumber = 0;
7524 const QScreen *restoredScreen = QGuiApplication::screens().value(restoredScreenNumber, nullptr);
7525 const qreal screenWidthF = restoredScreen ? qreal(restoredScreen->geometry().width()) : 0;
7526 // Sanity check bailing out when large variations of screen sizes occur due to
7527 // high DPI scaling or different levels of DPI awareness.
7528 if (restoredScreenWidth) {
7529 const qreal factor = qreal(restoredScreenWidth) / screenWidthF;
7530 if (factor < 0.8 || factor > 1.25)
7531 return false;
7532 } else {
7533 // Saved by Qt 5.3 and earlier, try to prevent too large windows
7534 // unless the size will be adapted by maximized or fullscreen.
7535 if (!maximized && !fullScreen && qreal(restoredFrameGeometry.width()) / screenWidthF > 1.5)
7536 return false;
7537 }
7538
7539 const int frameHeight = QApplication::style()
7540 ? QApplication::style()->pixelMetric(QStyle::PM_TitleBarHeight, nullptr, this)
7541 : 20;
7542
7543 if (!restoredNormalGeometry.isValid())
7544 restoredNormalGeometry = QRect(QPoint(0, frameHeight), sizeHint());
7545 if (!restoredNormalGeometry.isValid()) {
7546 // use the widget's adjustedSize if the sizeHint() doesn't help
7547 restoredNormalGeometry.setSize(restoredNormalGeometry
7548 .size()
7549 .expandedTo(d_func()->adjustedSize()));
7550 }
7551
7552 const QRect availableGeometry = restoredScreen ? restoredScreen->availableGeometry()
7553 : QRect();
7554
7555 // Modify the restored geometry if we are about to restore to coordinates
7556 // that would make the window "lost". This happens if:
7557 // - The restored geometry is completely or partly oustside the available geometry
7558 // - The title bar is outside the available geometry.
7559
7560 QWidgetPrivate::checkRestoredGeometry(availableGeometry, &restoredGeometry, frameHeight);
7561 QWidgetPrivate::checkRestoredGeometry(availableGeometry, &restoredNormalGeometry, frameHeight);
7562
7563 if (maximized || fullScreen) {
7564 // set geometry before setting the window state to make
7565 // sure the window is maximized to the right screen.
7566 Qt::WindowStates ws = windowState();
7567#ifndef Q_OS_WIN
7568 setGeometry(restoredNormalGeometry);
7569#else
7570 if (ws & Qt::WindowFullScreen) {
7571 // Full screen is not a real window state on Windows.
7572 move(availableGeometry.topLeft());
7573 } else if (ws & Qt::WindowMaximized) {
7574 // Setting a geometry on an already maximized window causes this to be
7575 // restored into a broken, half-maximized state, non-resizable state (QTBUG-4397).
7576 // Move the window in normal state if needed.
7577 if (restoredScreen != screen()) {
7579 setGeometry(restoredNormalGeometry);
7580 }
7581 } else {
7582 setGeometry(restoredNormalGeometry);
7583 }
7584#endif // Q_OS_WIN
7585 if (maximized)
7586 ws |= Qt::WindowMaximized;
7587 if (fullScreen)
7589 setWindowState(ws);
7590 d_func()->topData()->normalGeometry = restoredNormalGeometry;
7591 } else {
7593
7594 // FIXME: Why fall back to restoredNormalGeometry if majorVersion <= 2?
7595 if (majorVersion > 2)
7596 setGeometry(restoredGeometry);
7597 else
7598 setGeometry(restoredNormalGeometry);
7599 }
7600 return true;
7601}
7602
7620{
7621 Q_D(QWidget);
7622 if (left == d->leftmargin && top == d->topmargin
7623 && right == d->rightmargin && bottom == d->bottommargin)
7624 return;
7625 d->leftmargin = left;
7626 d->topmargin = top;
7627 d->rightmargin = right;
7628 d->bottommargin = bottom;
7629
7630 d->updateContentsRect();
7631}
7632
7650{
7651 setContentsMargins(margins.left(), margins.top(),
7652 margins.right(), margins.bottom());
7653}
7654
7656{
7657 Q_Q(QWidget);
7658
7659 if (layout)
7660 layout->update(); //force activate; will do updateGeometry
7661 else
7662 q->updateGeometry();
7663
7664 if (q->isVisible()) {
7665 q->update();
7666 QResizeEvent e(q->data->crect.size(), q->data->crect.size());
7668 } else {
7669 q->setAttribute(Qt::WA_PendingResizeEvent, true);
7670 }
7671
7674}
7675
7684{
7685 Q_D(const QWidget);
7686 QMargins userMargins(d->leftmargin, d->topmargin, d->rightmargin, d->bottommargin);
7688 userMargins | d->safeAreaMargins() : userMargins;
7689}
7690
7697{
7698 return rect() - contentsMargins();
7699}
7700
7702{
7703 Q_Q(const QWidget);
7704 QWidget *nativeWidget = q->window();
7705 if (!nativeWidget->windowHandle())
7706 return QMargins();
7707
7708 QPlatformWindow *platformWindow = nativeWidget->windowHandle()->handle();
7709 if (!platformWindow)
7710 return QMargins();
7711
7712 QMargins safeAreaMargins = platformWindow->safeAreaMargins();
7713
7714 if (!q->isWindow()) {
7715 // In theory the native parent widget already has a contents rect reflecting
7716 // the safe area of that widget, but we can't be sure that the widget or child
7717 // widgets of that widget have respected the contents rect when setting their
7718 // geometry, so we need to manually compute the safe area.
7719
7720 // Unless the native widget doesn't have any margins, in which case there's
7721 // nothing for us to compute.
7722 if (safeAreaMargins.isNull())
7723 return QMargins();
7724
7725 // Or, if one of our ancestors are in a layout that does not have WA_LayoutOnEntireRect
7726 // set, and the widget respects the safe area, then we know that the layout has already
7727 // taken care of placing us inside the safe area, by taking the contents rect of its
7728 // parent widget into account.
7729 const QWidget *assumedSafeWidget = nullptr;
7730 for (const QWidget *w = q; w != nativeWidget; w = w->parentWidget()) {
7731 QWidget *parentWidget = w->parentWidget();
7733 continue; // Layout can't help us
7734
7735 if (parentWidget->testAttribute(Qt::WA_LayoutOnEntireRect))
7736 continue; // Layout not going to help us
7737
7738 QLayout *layout = parentWidget->layout();
7739 if (!layout)
7740 continue;
7741
7742 if (layout->geometry().isNull())
7743 continue; // Layout hasn't been activated yet
7744
7745 if (layout->indexOf(w) < 0)
7746 continue; // Widget is not in layout
7747
7748 assumedSafeWidget = w;
7749 break;
7750 }
7751
7752#if !defined(QT_DEBUG)
7753 if (assumedSafeWidget) {
7754 // We found a layout that we assume will take care of keeping us within the safe area
7755 // For debug builds we still map the safe area using the fallback logic, so that we
7756 // can detect any misbehaving layouts.
7757 return QMargins();
7758 }
7759#endif
7760
7761 // In all other cases we need to map the safe area of the native parent to the widget.
7762 // This depends on the widget being positioned and sized already, which means the initial
7763 // layout will be wrong, but the layout will then adjust itself.
7764 QPoint topLeftMargins = q->mapFrom(nativeWidget, QPoint(safeAreaMargins.left(), safeAreaMargins.top()));
7765 QRect widgetRect = q->isVisible() ? q->visibleRegion().boundingRect() : q->rect();
7766 QPoint bottomRightMargins = widgetRect.bottomRight() - q->mapFrom(nativeWidget,
7767 nativeWidget->rect().bottomRight() - QPoint(safeAreaMargins.right(), safeAreaMargins.bottom()));
7768
7769 // Margins should never be negative
7770 safeAreaMargins = QMargins(qMax(0, topLeftMargins.x()), qMax(0, topLeftMargins.y()),
7771 qMax(0, bottomRightMargins.x()), qMax(0, bottomRightMargins.y()));
7772
7773 if (!safeAreaMargins.isNull() && assumedSafeWidget) {
7774 QLayout *layout = assumedSafeWidget->parentWidget()->layout();
7775 qWarning() << layout << "is laying out" << assumedSafeWidget
7776 << "outside of the contents rect of" << layout->parentWidget();
7777 return QMargins(); // Return empty margin to visually highlight the error
7778 }
7779 }
7780
7781 return safeAreaMargins;
7782}
7783
7815{
7816 return (Qt::ContextMenuPolicy)data->context_menu_policy;
7817}
7818
7820{
7821 data->context_menu_policy = (uint) policy;
7822}
7823
7847{
7848 return (Qt::FocusPolicy)data->focus_policy;
7849}
7850
7852{
7853 data->focus_policy = (uint) policy;
7854 Q_D(QWidget);
7855 if (d->extra && d->extra->focus_proxy)
7856 d->extra->focus_proxy->setFocusPolicy(policy);
7857}
7858
7888{
7889 Q_D(QWidget);
7891 d->setUpdatesEnabled_helper(enable);
7892}
7893
7905{
7906 // Note: We don't call showNormal() as not to clobber Qt::Window(Max/Min)imized
7907
7908 if (!isWindow()) {
7909 setVisible(true);
7910 } else {
7911 const auto *platformIntegration = QGuiApplicationPrivate::platformIntegration();
7912 Qt::WindowState defaultState = platformIntegration->defaultWindowState(data->window_flags);
7913 if (defaultState == Qt::WindowFullScreen)
7915 else if (defaultState == Qt::WindowMaximized)
7916 showMaximized();
7917 else
7918 setVisible(true);
7919 }
7920}
7921
7928{
7929 Q_Q(QWidget);
7930 // polish if necessary
7931
7932 if (!q->testAttribute(Qt::WA_WState_Created))
7934 q->ensurePolished();
7935
7936 if (!q->isWindow() && q->parentWidget()->d_func()->layout && !q->parentWidget()->data->in_show)
7937 q->parentWidget()->d_func()->layout->activate();
7938 // activate our layout before we and our children become visible
7939 if (layout)
7940 layout->activate();
7941
7942 show_helper();
7943}
7944
7945void QWidgetPrivate::sendPendingMoveAndResizeEvents(bool recursive, bool disableUpdates)
7946{
7947 Q_Q(QWidget);
7948
7949 disableUpdates = disableUpdates && q->updatesEnabled();
7950 if (disableUpdates)
7951 q->setAttribute(Qt::WA_UpdatesDisabled);
7952
7953 if (q->testAttribute(Qt::WA_PendingMoveEvent)) {
7954 QMoveEvent e(data.crect.topLeft(), data.crect.topLeft());
7956 q->setAttribute(Qt::WA_PendingMoveEvent, false);
7957 }
7958
7959 if (q->testAttribute(Qt::WA_PendingResizeEvent)) {
7960 QResizeEvent e(data.crect.size(), QSize());
7962 q->setAttribute(Qt::WA_PendingResizeEvent, false);
7963 }
7964
7965 if (disableUpdates)
7966 q->setAttribute(Qt::WA_UpdatesDisabled, false);
7967
7968 if (!recursive)
7969 return;
7970
7971 for (int i = 0; i < children.size(); ++i) {
7972 if (QWidget *child = qobject_cast<QWidget *>(children.at(i)))
7973 child->d_func()->sendPendingMoveAndResizeEvents(recursive, disableUpdates);
7974 }
7975}
7976
7978{
7979 sendPendingMoveAndResizeEvents(false, true);
7980
7981 for (int i = 0; i < children.size(); ++i) {
7983 if (!child || child->isHidden() || child->isWindow())
7984 continue;
7985
7986 child->ensurePolished();
7987
7988 // Activate child's layout
7989 QWidgetPrivate *childPrivate = child->d_func();
7990 if (childPrivate->layout)
7991 childPrivate->layout->activate();
7992
7993 // Pretend we're visible.
7994 const bool wasVisible = child->isVisible();
7995 if (!wasVisible)
7996 child->setAttribute(Qt::WA_WState_Visible);
7997
7998 // Do the same for all my children.
7999 childPrivate->activateChildLayoutsRecursively();
8000
8001 // We're not cheating anymore.
8002 if (!wasVisible)
8003 child->setAttribute(Qt::WA_WState_Visible, false);
8004 }
8005}
8006
8008{
8009 Q_Q(QWidget);
8010 data.in_show = true; // qws optimization
8011 // make sure we receive pending move and resize events
8013
8014 // become visible before showing all children
8015 q->setAttribute(Qt::WA_WState_Visible);
8016
8017 // finally show all children recursively
8018 showChildren(false);
8019
8020
8021
8022 const bool isWindow = q->isWindow();
8023#if QT_CONFIG(graphicsview)
8024 bool isEmbedded = isWindow && q->graphicsProxyWidget() != nullptr;
8025#else
8026 bool isEmbedded = false;
8027#endif
8028
8029 // popup handling: new popups and tools need to be raised, and
8030 // existing popups must be closed. Also propagate the current
8031 // windows's KeyboardFocusChange status.
8032 if (isWindow && !isEmbedded) {
8033 if ((q->windowType() == Qt::Tool) || (q->windowType() == Qt::Popup) || q->windowType() == Qt::ToolTip) {
8034 q->raise();
8035 if (q->parentWidget() && q->parentWidget()->window()->testAttribute(Qt::WA_KeyboardFocusChange))
8036 q->setAttribute(Qt::WA_KeyboardFocusChange);
8037 } else {
8040 break;
8041 }
8042 }
8043 }
8044
8045 // Automatic embedding of child windows of widgets already embedded into
8046 // QGraphicsProxyWidget when they are shown the first time.
8047#if QT_CONFIG(graphicsview)
8048 if (isWindow) {
8050 QGraphicsProxyWidget *ancestorProxy = nearestGraphicsProxyWidget(q->parentWidget());
8051 if (ancestorProxy) {
8052 isEmbedded = true;
8053 ancestorProxy->d_func()->embedSubWindow(q);
8054 }
8055 }
8056 }
8057#else
8059#endif
8060
8061 // send the show event before showing the window
8062 QShowEvent showEvent;
8063 QCoreApplication::sendEvent(q, &showEvent);
8064
8065 show_sys();
8066
8067 if (!isEmbedded && q->windowType() == Qt::Popup)
8068 qApp->d_func()->openPopup(q);
8069
8070#if QT_CONFIG(accessibility)
8071 if (q->windowType() != Qt::ToolTip) { // Tooltips are read aloud twice in MS narrator.
8072 QAccessibleEvent event(q, QAccessible::ObjectShow);
8073 QAccessible::updateAccessibility(&event);
8074 }
8075#endif
8076
8079 q->setFocus(Qt::OtherFocusReason);
8080 }
8081
8082 // Process events when showing a Qt::SplashScreen widget before the event loop
8083 // is spinnning; otherwise it might not show up on particular platforms.
8084 // This makes QSplashScreen behave the same on all platforms.
8085 if (!qApp->d_func()->in_exec && q->windowType() == Qt::SplashScreen)
8087
8088 data.in_show = false; // reset qws optimization
8089}
8090
8092{
8093 Q_Q(QWidget);
8094
8095 auto window = qobject_cast<QWidgetWindow *>(windowHandle());
8096
8097 if (q->testAttribute(Qt::WA_DontShowOnScreen)) {
8098 invalidateBackingStore(q->rect());
8099 q->setAttribute(Qt::WA_Mapped);
8100 // add our window the modal window list (native dialogs)
8101 if (window && q->isWindow()
8102#if QT_CONFIG(graphicsview)
8103 && (!extra || !extra->proxyWidget)
8104#endif
8105 && q->windowModality() != Qt::NonModal) {
8107 }
8108 return;
8109 }
8110
8111 if (renderToTexture && !q->isWindow())
8112 QCoreApplication::postEvent(q->parentWidget(), new QUpdateLaterEvent(q->geometry()));
8113 else
8115
8116 if ((!q->isWindow() && !q->testAttribute(Qt::WA_NativeWindow))
8117 || q->testAttribute(Qt::WA_OutsideWSRange)) {
8118 return;
8119 }
8120
8121 if (window) {
8122 if (q->isWindow())
8124 QRect geomRect = q->geometry();
8125 if (!q->isWindow()) {
8126 QPoint topLeftOfWindow = q->mapTo(q->nativeParentWidget(),QPoint());
8127 geomRect.moveTopLeft(topLeftOfWindow);
8128 }
8129 const QRect windowRect = window->geometry();
8130 if (windowRect != geomRect) {
8131 if (q->testAttribute(Qt::WA_Moved)
8133 window->setGeometry(geomRect);
8134 else
8135 window->resize(geomRect.size());
8136 }
8137
8138#ifndef QT_NO_CURSOR
8139 qt_qpa_set_cursor(q, false); // Needed in case cursor was set before show
8140#endif
8141 invalidateBackingStore(q->rect());
8142 window->setNativeWindowVisibility(true);
8143 // Was the window moved by the Window system or QPlatformWindow::initialGeometry() ?
8144 if (window->isTopLevel()) {
8145 const QPoint crectTopLeft = q->data->crect.topLeft();
8146 const QPoint windowTopLeft = window->geometry().topLeft();
8147 if (crectTopLeft == QPoint(0, 0) && windowTopLeft != crectTopLeft)
8148 q->data->crect.moveTopLeft(windowTopLeft);
8149 }
8150 }
8151}
8152
8165{
8166 setVisible(false);
8167}
8168
8172{
8173 Q_Q(QWidget);
8174
8175 bool isEmbedded = false;
8176#if QT_CONFIG(graphicsview)
8177 isEmbedded = q->isWindow() && !bypassGraphicsProxyWidget(q) && nearestGraphicsProxyWidget(q->parentWidget()) != nullptr;
8178#else
8180#endif
8181
8182 if (!isEmbedded && (q->windowType() == Qt::Popup))
8183 qApp->d_func()->closePopup(q);
8184
8185 q->setAttribute(Qt::WA_Mapped, false);
8186 hide_sys();
8187
8188 bool wasVisible = q->testAttribute(Qt::WA_WState_Visible);
8189
8190 if (wasVisible) {
8191 q->setAttribute(Qt::WA_WState_Visible, false);
8192
8193 }
8194
8195 QHideEvent hideEvent;
8196 QCoreApplication::sendEvent(q, &hideEvent);
8197 hideChildren(false);
8198
8199 // next bit tries to move the focus if the focus widget is now
8200 // hidden.
8201 if (wasVisible) {
8202 qApp->d_func()->sendSyntheticEnterLeave(q);
8204 while (fw && !fw->isWindow()) {
8205 if (fw == q) {
8206 q->focusNextPrevChild(true);
8207 break;
8208 }
8209 fw = fw->parentWidget();
8210 }
8211 }
8212
8213 if (QWidgetRepaintManager *repaintManager = maybeRepaintManager())
8214 repaintManager->removeDirtyWidget(q);
8215
8216#if QT_CONFIG(accessibility)
8217 if (wasVisible) {
8218 QAccessibleEvent event(q, QAccessible::ObjectHide);
8219 QAccessible::updateAccessibility(&event);
8220 }
8221#endif
8222}
8223
8225{
8226 Q_Q(QWidget);
8227
8228 auto window = qobject_cast<QWidgetWindow *>(windowHandle());
8229
8230 if (q->testAttribute(Qt::WA_DontShowOnScreen)) {
8231 q->setAttribute(Qt::WA_Mapped, false);
8232 // remove our window from the modal window list (native dialogs)
8233 if (window && q->isWindow()
8234#if QT_CONFIG(graphicsview)
8235 && (!extra || !extra->proxyWidget)
8236#endif
8237 && q->windowModality() != Qt::NonModal) {
8239 }
8240 // do not return here, if window non-zero, we must hide it
8241 }
8242
8244
8245 if (!q->isWindow()) {
8246 QWidget *p = q->parentWidget();
8247 if (p &&p->isVisible()) {
8248 if (renderToTexture)
8249 p->d_func()->invalidateBackingStore(q->geometry());
8250 else
8251 invalidateBackingStore(q->rect());
8252 }
8253 } else {
8254 invalidateBackingStore(q->rect());
8255 }
8256
8257 if (window)
8258 window->setNativeWindowVisibility(false);
8259}
8260
8284void QWidget::setVisible(bool visible)
8285{
8286 Q_D(QWidget);
8287 qCDebug(lcWidgetShowHide) << "Setting visibility of" << this
8288 << "with attributes" << WidgetAttributes{this}
8289 << "to" << visible << "via QWidget";
8290
8292 return;
8293
8294 // Remember that setVisible was called explicitly
8296
8297 d->setVisible(visible);
8298}
8299
8300// This method is called from QWidgetWindow in response to QWindow::setVisible,
8301// and should match the semantics of QWindow::setVisible. QWidget::setVisible on
8302// the other hand keeps track of WA_WState_ExplicitShowHide in addition.
8304{
8305 Q_Q(QWidget);
8306 qCDebug(lcWidgetShowHide) << "Setting visibility of" << q
8307 << "with attributes" << WidgetAttributes{q}
8308 << "to" << visible << "via QWidgetPrivate";
8309
8310 if (visible) { // show
8311 // Designer uses a trick to make grabWidget work without showing
8312 if (!q->isWindow() && q->parentWidget() && q->parentWidget()->isVisible()
8313 && !q->parentWidget()->testAttribute(Qt::WA_WState_Created))
8314 q->parentWidget()->window()->d_func()->createRecursively();
8315
8316 //create toplevels but not children of non-visible parents
8317 QWidget *pw = q->parentWidget();
8318 if (!q->testAttribute(Qt::WA_WState_Created)
8319 && (q->isWindow() || pw->testAttribute(Qt::WA_WState_Created))) {
8320 q->create();
8321 }
8322
8323 bool wasResized = q->testAttribute(Qt::WA_Resized);
8324 Qt::WindowStates initialWindowState = q->windowState();
8325
8326 // polish if necessary
8327 q->ensurePolished();
8328
8329 // whether we need to inform the parent widget immediately
8330 bool needUpdateGeometry = !q->isWindow() && q->testAttribute(Qt::WA_WState_Hidden);
8331 // we are no longer hidden
8332 q->setAttribute(Qt::WA_WState_Hidden, false);
8333
8334 if (needUpdateGeometry)
8336
8337 // activate our layout before we and our children become visible
8338 if (layout)
8339 layout->activate();
8340
8341 if (!q->isWindow()) {
8342 QWidget *parent = q->parentWidget();
8343 while (parent && parent->isVisible() && parent->d_func()->layout && !parent->data->in_show) {
8344 parent->d_func()->layout->activate();
8345 if (parent->isWindow())
8346 break;
8347 parent = parent->parentWidget();
8348 }
8349 if (parent)
8350 parent->d_func()->setDirtyOpaqueRegion();
8351 }
8352
8353 // adjust size if necessary
8354 if (!wasResized
8355 && (q->isWindow() || !q->parentWidget()->d_func()->layout)) {
8356 if (q->isWindow()) {
8357 q->adjustSize();
8358 if (q->windowState() != initialWindowState)
8359 q->setWindowState(initialWindowState);
8360 } else {
8361 q->adjustSize();
8362 }
8363 q->setAttribute(Qt::WA_Resized, false);
8364 }
8365
8366 q->setAttribute(Qt::WA_KeyboardFocusChange, false);
8367
8368 if (q->isWindow() || q->parentWidget()->isVisible()) {
8369 show_helper();
8370
8371 qApp->d_func()->sendSyntheticEnterLeave(q);
8372 }
8373
8374 QEvent showToParentEvent(QEvent::ShowToParent);
8375 QCoreApplication::sendEvent(q, &showToParentEvent);
8376 } else { // hide
8379
8380 // hw: The test on getOpaqueRegion() needs to be more intelligent
8381 // currently it doesn't work if the widget is hidden (the region will
8382 // be clipped). The real check should be testing the cached region
8383 // (and dirty flag) directly.
8384 if (!q->isWindow() && q->parentWidget()) // && !d->getOpaqueRegion().isEmpty())
8385 q->parentWidget()->d_func()->setDirtyOpaqueRegion();
8386
8387 if (!q->testAttribute(Qt::WA_WState_Hidden)) {
8388 q->setAttribute(Qt::WA_WState_Hidden);
8389 hide_helper();
8390 }
8391
8392 // invalidate layout similar to updateGeometry()
8393 if (!q->isWindow() && q->parentWidget()) {
8394 if (q->parentWidget()->d_func()->layout)
8395 q->parentWidget()->d_func()->layout->invalidate();
8396 else if (q->parentWidget()->isVisible())
8398 }
8399
8400 QEvent hideToParentEvent(QEvent::HideToParent);
8401 QCoreApplication::sendEvent(q, &hideToParentEvent);
8402 }
8403}
8404
8408void QWidget::setHidden(bool hidden)
8409{
8410 setVisible(!hidden);
8411}
8412
8414{
8415 Q_Q(const QWidget);
8416 return q->isHidden() && q->testAttribute(Qt::WA_WState_ExplicitShowHide);
8417}
8418
8420{
8421 Q_Q(QWidget);
8422 if (!isExplicitlyHidden())
8423 q->setVisible(true);
8424}
8425
8426void QWidgetPrivate::showChildren(bool spontaneous)
8427{
8428 Q_Q(QWidget);
8429 qCDebug(lcWidgetShowHide) << "Showing children of" << q
8430 << "spontaneously" << spontaneous;
8431
8432 QList<QObject*> childList = children;
8433 for (int i = 0; i < childList.size(); ++i) {
8434 QWidget *widget = qobject_cast<QWidget*>(childList.at(i));
8435 if (!widget)
8436 continue;
8437 qCDebug(lcWidgetShowHide) << "Considering" << widget
8438 << "with attributes" << WidgetAttributes{widget};
8442 continue;
8443 if (spontaneous) {
8445 widget->d_func()->showChildren(true);
8446 QShowEvent e;
8447 QApplication::sendSpontaneousEvent(widget, &e);
8448 } else {
8450 widget->d_func()->show_recursive();
8451 else
8452 widget->d_func()->setVisible(true);
8453 }
8454 }
8455}
8456
8457void QWidgetPrivate::hideChildren(bool spontaneous)
8458{
8459 Q_Q(QWidget);
8460 qCDebug(lcWidgetShowHide) << "Hiding children of" << q
8461 << "spontaneously" << spontaneous;
8462
8463 QList<QObject*> childList = children;
8464 for (int i = 0; i < childList.size(); ++i) {
8465 QWidget *widget = qobject_cast<QWidget*>(childList.at(i));
8466 if (!widget)
8467 continue;
8468 qCDebug(lcWidgetShowHide) << "Considering" << widget
8469 << "with attributes" << WidgetAttributes{widget};
8470 if (widget->isWindow() || !widget->isVisible())
8471 continue;
8472
8473 if (spontaneous)
8475 else
8477 widget->d_func()->hideChildren(spontaneous);
8478 QHideEvent e;
8479 if (spontaneous) {
8480 QApplication::sendSpontaneousEvent(widget, &e);
8481 } else {
8483 if (widget->internalWinId()
8485 // hide_sys() on an ancestor won't have any affect on this
8486 // widget, so it needs an explicit hide_sys() of its own
8487 widget->d_func()->hide_sys();
8488 }
8489 }
8490 qApp->d_func()->sendSyntheticEnterLeave(widget);
8491#if QT_CONFIG(accessibility)
8492 if (!spontaneous) {
8493 QAccessibleEvent event(widget, QAccessible::ObjectHide);
8494 QAccessible::updateAccessibility(&event);
8495 }
8496#endif
8497 }
8498
8499 // If the window of this widget is not closed, then the leave event
8500 // will eventually handle the widget under mouse use case.
8501 // Otherwise, we need to explicitly handle it here.
8502 if (QWidget* widgetWindow = q->window();
8503 widgetWindow && widgetWindow->data->is_closing) {
8504 q->setAttribute(Qt::WA_UnderMouse, false);
8505 }
8506}
8507
8527{
8528 Q_Q(QWidget);
8529 qCDebug(lcWidgetShowHide) << "Handling close event for" << q;
8530
8531 if (data.is_closing)
8532 return true;
8533
8534 // We might not have initiated the close, so update the state now that we know
8535 data.is_closing = true;
8536
8537 QPointer<QWidget> that = q;
8538
8539 if (data.in_destructor)
8541
8542 if (mode != CloseNoEvent) {
8543 QCloseEvent e;
8545 QApplication::sendSpontaneousEvent(q, &e);
8546 else
8548 if (!that.isNull() && !e.isAccepted()) {
8549 data.is_closing = false;
8550 return false;
8551 }
8552 }
8553
8554 // even for windows, make sure we deliver a hide event and that all children get hidden
8555 if (!that.isNull() && !q->isHidden())
8556 q->hide();
8557
8558 if (!that.isNull()) {
8559 data.is_closing = false;
8560 if (q->testAttribute(Qt::WA_DeleteOnClose)) {
8561 q->setAttribute(Qt::WA_DeleteOnClose, false);
8562 q->deleteLater();
8563 }
8564 }
8565 return true;
8566}
8567
8568
8592{
8593 return d_func()->close();
8594}
8595
8597{
8598 // FIXME: We're not setting is_closing here, even though that would
8599 // make sense, as the code below will not end up in handleClose to
8600 // reset is_closing when there's a QWindow, but no QPlatformWindow,
8601 // and we can't assume close is synchronous so we can't reset it here.
8602
8603 // Close native widgets via QWindow::close() in order to run QWindow
8604 // close code. The QWidget-specific close code in handleClose() will
8605 // in this case be called from the Close event handler in QWidgetWindow.
8606 if (QWindow *widgetWindow = windowHandle()) {
8607 if (widgetWindow->isTopLevel())
8608 return widgetWindow->close();
8609 }
8610
8612}
8613
8672bool QWidget::isVisibleTo(const QWidget *ancestor) const
8673{
8674 if (!ancestor)
8675 return isVisible();
8676 const QWidget * w = this;
8677 while (!w->isHidden()
8678 && !w->isWindow()
8679 && w->parentWidget()
8680 && w->parentWidget() != ancestor)
8681 w = w->parentWidget();
8682 return !w->isHidden();
8683}
8684
8685
8697{
8698 Q_D(const QWidget);
8699
8700 QRect clipRect = d->clipRect();
8701 if (clipRect.isEmpty())
8702 return QRegion();
8703 QRegion r(clipRect);
8704 d->subtractOpaqueChildren(r, clipRect);
8705 d->subtractOpaqueSiblings(r);
8706 return r;
8707}
8708
8709
8711{
8712 Q_Q(const QWidget);
8713
8714 QSize s = q->sizeHint();
8715
8716 if (q->isWindow()) {
8717 Qt::Orientations exp;
8718 if (layout) {
8721 exp = layout->expandingDirections();
8722 } else
8723 {
8724 if (q->sizePolicy().hasHeightForWidth())
8725 s.setHeight(q->heightForWidth(s.width()));
8726 exp = q->sizePolicy().expandingDirections();
8727 }
8728 if (exp & Qt::Horizontal)
8729 s.setWidth(qMax(s.width(), 200));
8730 if (exp & Qt::Vertical)
8731 s.setHeight(qMax(s.height(), 100));
8732
8733 QRect screen;
8734 if (const QScreen *screenAtPoint = QGuiApplication::screenAt(q->pos()))
8735 screen = screenAtPoint->geometry();
8736 else
8738
8739 s.setWidth(qMin(s.width(), screen.width()*2/3));
8740 s.setHeight(qMin(s.height(), screen.height()*2/3));
8741
8742 if (QTLWExtra *extra = maybeTopData())
8743 extra->sizeAdjusted = true;
8744 }
8745
8746 if (!s.isValid()) {
8747 QRect r = q->childrenRect(); // get children rectangle
8748 if (r.isNull())
8749 return s;
8750 s = r.size() + QSize(2 * r.x(), 2 * r.y());
8751 }
8752
8753 return s;
8754}
8755
8773{
8774 Q_D(QWidget);
8776 QSize s = d->adjustedSize();
8777
8778 if (d->layout)
8779 d->layout->activate();
8780
8781 if (s.isValid())
8782 resize(s);
8783}
8784
8785
8802{
8803 Q_D(const QWidget);
8804 if (d->layout)
8805 return d->layout->totalSizeHint();
8806 return QSize(-1, -1);
8807}
8808
8829{
8830 Q_D(const QWidget);
8831 if (d->layout)
8832 return d->layout->totalMinimumSize();
8833 return QSize(-1, -1);
8834}
8835
8836
8852{
8853 while (child) {
8854 if (child == this)
8855 return true;
8856 if (child->isWindow())
8857 return false;
8858 child = child->parentWidget();
8859 }
8860 return false;
8861}
8862
8863/*****************************************************************************
8864 QWidget event handling
8865 *****************************************************************************/
8866
8896{
8897 Q_D(QWidget);
8898
8899 // ignore mouse and key events when disabled
8900 if (!isEnabled()) {
8901 switch(event->type()) {
8904 case QEvent::TabletMove:
8908 case QEvent::MouseMove:
8909 case QEvent::TouchBegin:
8911 case QEvent::TouchEnd:
8914 case QEvent::KeyPress:
8915 case QEvent::KeyRelease:
8916#if QT_CONFIG(wheelevent)
8917 case QEvent::Wheel:
8918#endif
8919 return false;
8920 default:
8921 break;
8922 }
8923 }
8924 switch (event->type()) {
8926 // Sync up QWidget's view of whether or not the widget has been created
8927 switch (static_cast<QPlatformSurfaceEvent*>(event)->surfaceEventType()) {
8930 create();
8931 break;
8934 // Child windows have already been destroyed by QWindow,
8935 // so we skip them here.
8936 destroy(false, false);
8937 }
8938 break;
8939 }
8940 break;
8941 }
8942 case QEvent::MouseMove:
8944 break;
8945
8948 break;
8949
8952 break;
8953
8956 break;
8957#if QT_CONFIG(wheelevent)
8958 case QEvent::Wheel:
8959 wheelEvent((QWheelEvent*)event);
8960 break;
8961#endif
8962#if QT_CONFIG(tabletevent)
8963 case QEvent::TabletMove:
8964 if (static_cast<QTabletEvent *>(event)->buttons() == Qt::NoButton && !testAttribute(Qt::WA_TabletTracking))
8965 break;
8966 Q_FALLTHROUGH();
8969 tabletEvent((QTabletEvent*)event);
8970 break;
8971#endif
8972 case QEvent::KeyPress: {
8973 QKeyEvent *k = static_cast<QKeyEvent *>(event);
8974 bool res = false;
8975 if (!(k->modifiers() & (Qt::ControlModifier | Qt::AltModifier))) { //### Add MetaModifier?
8976 if (k->key() == Qt::Key_Backtab
8977 || (k->key() == Qt::Key_Tab && (k->modifiers() & Qt::ShiftModifier)))
8978 res = focusNextPrevChild(false);
8979 else if (k->key() == Qt::Key_Tab)
8980 res = focusNextPrevChild(true);
8981 if (res)
8982 break;
8983 }
8984 keyPressEvent(k);
8985#ifdef QT_KEYPAD_NAVIGATION
8986 if (!k->isAccepted() && QApplication::keypadNavigationEnabled()
8988 if (QApplication::navigationMode() == Qt::NavigationModeKeypadTabOrder) {
8989 if (k->key() == Qt::Key_Up)
8990 res = focusNextPrevChild(false);
8991 else if (k->key() == Qt::Key_Down)
8992 res = focusNextPrevChild(true);
8993 } else if (QApplication::navigationMode() == Qt::NavigationModeKeypadDirectional) {
8994 if (k->key() == Qt::Key_Up)
8995 res = QWidgetPrivate::navigateToDirection(QWidgetPrivate::DirectionNorth);
8996 else if (k->key() == Qt::Key_Right)
8997 res = QWidgetPrivate::navigateToDirection(QWidgetPrivate::DirectionEast);
8998 else if (k->key() == Qt::Key_Down)
8999 res = QWidgetPrivate::navigateToDirection(QWidgetPrivate::DirectionSouth);
9000 else if (k->key() == Qt::Key_Left)
9001 res = QWidgetPrivate::navigateToDirection(QWidgetPrivate::DirectionWest);
9002 }
9003 if (res) {
9004 k->accept();
9005 break;
9006 }
9007 }
9008#endif
9009#if QT_CONFIG(whatsthis)
9010 if (!k->isAccepted()
9011 && k->modifiers() & Qt::ShiftModifier && k->key() == Qt::Key_F1
9012 && d->whatsThis.size()) {
9013 QWhatsThis::showText(mapToGlobal(inputMethodQuery(Qt::ImCursorRectangle).toRect().center()), d->whatsThis, this);
9014 k->accept();
9015 }
9016#endif
9017 }
9018 break;
9019
9020 case QEvent::KeyRelease:
9022 Q_FALLTHROUGH();
9024 break;
9025
9028 break;
9029
9032 Qt::InputMethodQueries queries = query->queries();
9033 for (uint i = 0; i < 32; ++i) {
9034 Qt::InputMethodQuery q = (Qt::InputMethodQuery)(int)(queries & (1<<i));
9035 if (q) {
9037 if (q == Qt::ImEnabled && !v.isValid() && isEnabled()) {
9038 // Qt:ImEnabled was added in Qt 5.3. So not all widgets support it, even
9039 // if they implement IM otherwise (by overriding inputMethodQuery()). Instead
9040 // they set the widget attribute Qt::WA_InputMethodEnabled. But this attribute
9041 // will only be set if the widget supports IM _and_ is not read-only. So for
9042 // read-only widgets, not all IM features will be supported when ImEnabled is
9043 // not implemented explicitly (e.g selection handles for read-only widgets on iOS).
9045 }
9046 query->setValue(q, v);
9047 }
9048 }
9049 query->accept();
9050 }
9051 break;
9052
9055 break;
9056
9057 case QEvent::Polish: {
9058 style()->polish(this);
9060 if (!QApplication::font(this).isCopyOf(QApplication::font()))
9061 d->resolveFont();
9062 if (!QApplication::palette(this).isCopyOf(QGuiApplication::palette()))
9063 d->resolvePalette();
9064 }
9065 break;
9066
9069 d->setWindowIcon_sys();
9070 d->setWindowIcon_helper();
9071 }
9072 break;
9073 case QEvent::FocusIn:
9075 d->updateWidgetTransform(event);
9076 break;
9077
9078 case QEvent::FocusOut:
9080 break;
9081
9082 case QEvent::Enter:
9083#if QT_CONFIG(statustip)
9084 if (d->statusTip.size()) {
9085 QStatusTipEvent tip(d->statusTip);
9086 QCoreApplication::sendEvent(const_cast<QWidget *>(this), &tip);
9087 }
9088#endif
9089 enterEvent(static_cast<QEnterEvent*>(event));
9090 break;
9091
9092 case QEvent::Leave:
9093#if QT_CONFIG(statustip)
9094 if (d->statusTip.size()) {
9095 QString empty;
9096 QStatusTipEvent tip(empty);
9097 QCoreApplication::sendEvent(const_cast<QWidget *>(this), &tip);
9098 }
9099#endif
9101 break;
9102
9103 case QEvent::HoverEnter:
9104 case QEvent::HoverLeave:
9105 update();
9106 break;
9107
9108 case QEvent::Paint:
9109 // At this point the event has to be delivered, regardless
9110 // whether the widget isVisible() or not because it
9111 // already went through the filters
9113 break;
9114
9115 case QEvent::Move:
9117 d->updateWidgetTransform(event);
9118 break;
9119
9120 case QEvent::Resize:
9122 d->updateWidgetTransform(event);
9123 break;
9124
9125 case QEvent::Close:
9127 break;
9128
9129#ifndef QT_NO_CONTEXTMENU
9131 switch (data->context_menu_policy) {
9133 break;
9135 contextMenuEvent(static_cast<QContextMenuEvent *>(event));
9136 break;
9139 break;
9140#if QT_CONFIG(menu)
9142 if (d->actions.size()) {
9143 QMenu::exec(d->actions, static_cast<QContextMenuEvent *>(event)->globalPos(),
9144 nullptr, this);
9145 break;
9146 }
9147 Q_FALLTHROUGH();
9148#endif
9149 default:
9150 event->ignore();
9151 break;
9152 }
9153 break;
9154#endif // QT_NO_CONTEXTMENU
9155
9156#if QT_CONFIG(draganddrop)
9157 case QEvent::Drop:
9158 dropEvent((QDropEvent*) event);
9159 break;
9160
9161 case QEvent::DragEnter:
9162 dragEnterEvent((QDragEnterEvent*) event);
9163 break;
9164
9165 case QEvent::DragMove:
9166 dragMoveEvent((QDragMoveEvent*) event);
9167 break;
9168
9169 case QEvent::DragLeave:
9170 dragLeaveEvent((QDragLeaveEvent*) event);
9171 break;
9172#endif
9173
9174 case QEvent::Show:
9176 break;
9177
9178 case QEvent::Hide:
9180 break;
9181
9183 if (!isHidden())
9184 d->show_sys();
9185 break;
9186
9188 d->resolveFont();
9189 break;
9191 if (!(windowType() == Qt::Desktop))
9192 d->resolvePalette();
9193 break;
9194
9198 case QEvent::FontChange:
9213 break;
9214
9216 const bool wasMinimized = static_cast<const QWindowStateChangeEvent *>(event)->oldState() & Qt::WindowMinimized;
9217 if (wasMinimized != isMinimized()) {
9218 QWidget *widget = const_cast<QWidget *>(this);
9219 if (wasMinimized) {
9220 // Always send the spontaneous events here, otherwise it can break the application!
9221 if (!d->childrenShownByExpose) {
9222 // Show widgets only when they are not yet shown by the expose event
9223 d->showChildren(true);
9225 QCoreApplication::sendSpontaneousEvent(widget, &showEvent);
9226 }
9227 d->childrenHiddenByWState = false; // Set it always to "false" when window is restored
9228 } else {
9230 QCoreApplication::sendSpontaneousEvent(widget, &hideEvent);
9231 d->hideChildren(true);
9232 d->childrenHiddenByWState = true;
9233 }
9234 d->childrenShownByExpose = false; // Set it always to "false" when window state changes
9235 }
9237 }
9238 break;
9239
9243 update();
9244 QList<QObject*> childList = d->children;
9245 for (int i = 0; i < childList.size(); ++i) {
9246 QWidget *w = qobject_cast<QWidget *>(childList.at(i));
9247 if (w && w->isVisible() && !w->isWindow())
9249 }
9250 break; }
9251
9254 {
9255 QList<QObject*> childList = d->children;
9256 for (int i = 0; i < childList.size(); ++i) {
9257 QObject *o = childList.at(i);
9258 if (o)
9260 }
9261 }
9262 update();
9263 break;
9264
9266 d->resolveLayoutDirection();
9267 break;
9268
9270 if (d->layout)
9271 d->layout->invalidate();
9272 update();
9274 break;
9276 d->syncBackingStore();
9277 break;
9279 update(static_cast<QUpdateLaterEvent*>(event)->region());
9280 break;
9282 if (isVisible() && !window()->isMinimized()) {
9283 event->accept();
9284 update();
9285 }
9286 break;
9287
9290 if (!d->children.isEmpty()) {
9292 for (int i = 0; i < d->children.size(); ++i) {
9293 QObject *o = d->children.at(i);
9294 if (o && o != modalWidget && o->isWidgetType()) {
9295 QWidget *w = static_cast<QWidget *>(o);
9296 // do not forward the event to child windows; QApplication does this for us
9297 if (!w->isWindow())
9299 }
9300 }
9301 }
9302 break;
9303#if QT_CONFIG(tooltip)
9304 case QEvent::ToolTip:
9305 if (!d->toolTip.isEmpty())
9306 QToolTip::showText(static_cast<QHelpEvent*>(event)->globalPos(), d->toolTip, this, QRect(), d->toolTipDuration);
9307 else
9308 event->ignore();
9309 break;
9310#endif
9311#if QT_CONFIG(whatsthis)
9312 case QEvent::WhatsThis:
9313 if (d->whatsThis.size())
9314 QWhatsThis::showText(static_cast<QHelpEvent *>(event)->globalPos(), d->whatsThis, this);
9315 else
9316 event->ignore();
9317 break;
9319 if (d->whatsThis.isEmpty())
9320 event->ignore();
9321 break;
9322#endif
9324 d->topData()->frameStrut.setCoords(0 ,0, 0, 0);
9325 data->fstrut_dirty = false;
9326 break;
9327#ifndef QT_NO_ACTION
9332 break;
9333#endif
9334
9336 {
9338
9339 // inform children of the change
9340 QList<QObject*> childList = d->children;
9341 for (int i = 0; i < childList.size(); ++i) {
9342 QWidget *w = qobject_cast<QWidget *>(childList.at(i));
9343 if (w && w->isVisible() && !w->isWindow())
9345 }
9346 break;
9347 }
9348 case QEvent::TouchBegin:
9350 case QEvent::TouchEnd:
9352 {
9353 event->ignore();
9354 break;
9355 }
9356#ifndef QT_NO_GESTURES
9357 case QEvent::Gesture:
9358 event->ignore();
9359 break;
9360#endif
9362 if (const QTLWExtra *te = d->maybeTopData()) {
9363 const QWindow *win = te->window;
9364 d->setWinId((win && win->handle()) ? win->handle()->winId() : 0);
9365 }
9366 break;
9368 if (d->data.fnt.d->dpi != logicalDpiY())
9369 d->updateFont(d->data.fnt);
9370 d->renderToTextureReallyDirty = 1;
9371 break;
9373 const QByteArray &propName = static_cast<QDynamicPropertyChangeEvent *>(event)->propertyName();
9374 if (propName.size() == 13 && !qstrncmp(propName, "_q_customDpi", 12)) {
9375 uint value = property(propName.constData()).toUInt();
9376 if (!d->extra)
9377 d->createExtra();
9378 const char axis = propName.at(12);
9379 if (axis == 'X')
9380 d->extra->customDpiX = value;
9381 else if (axis == 'Y')
9382 d->extra->customDpiY = value;
9383 d->updateFont(d->data.fnt);
9384 }
9385 if (windowHandle() && !qstrncmp(propName, "_q_platform_", 12))
9386 windowHandle()->setProperty(propName, property(propName));
9387 Q_FALLTHROUGH();
9388 }
9389 default:
9390 return QObject::event(event);
9391 }
9392 return true;
9393}
9394
9412{
9413 switch(event->type()) {
9414 case QEvent::EnabledChange: {
9415 update();
9416#if QT_CONFIG(accessibility)
9418 s.disabled = true;
9419 QAccessibleStateChangeEvent event(this, s);
9420 QAccessible::updateAccessibility(&event);
9421#endif
9422 break;
9423 }
9424
9425 case QEvent::FontChange:
9426 case QEvent::StyleChange: {
9427 Q_D(QWidget);
9428 update();
9430 if (d->layout)
9431 d->layout->invalidate();
9432 break;
9433 }
9434
9436 update();
9437 break;
9438
9443 QApplication::style()->unpolish(this);
9445 QApplication::style()->polish(this);
9446 QEvent styleChangedEvent(QEvent::StyleChange);
9447 QCoreApplication::sendEvent(this, &styleChangedEvent);
9448 if (isVisible())
9449 update();
9450 }
9451 break;
9452
9453#ifdef Q_OS_MAC
9456 break;
9457#endif
9458
9459 default:
9460 break;
9461 }
9462}
9463
9491{
9492 event->ignore();
9493}
9494
9513{
9514 event->ignore();
9515 if ((windowType() == Qt::Popup)) {
9516 event->accept();
9517 QWidget* w;
9518 while ((w = QApplication::activePopupWidget()) && w != this){
9519 w->close();
9520 if (QApplication::activePopupWidget() == w) // widget does not want to disappear
9521 w->hide(); // hide at least
9522 }
9523 if (!rect().contains(event->position().toPoint())){
9524 close();
9525 }
9526 }
9527}
9528
9538{
9539 event->ignore();
9540}
9541
9563
9564#if QT_CONFIG(wheelevent)
9579void QWidget::wheelEvent(QWheelEvent *event)
9580{
9581 event->ignore();
9582}
9583#endif // QT_CONFIG(wheelevent)
9584
9585#if QT_CONFIG(tabletevent)
9606void QWidget::tabletEvent(QTabletEvent *event)
9607{
9608 event->ignore();
9609}
9610#endif // QT_CONFIG(tabletevent)
9611
9636{
9637#ifndef QT_NO_SHORTCUT
9638 if ((windowType() == Qt::Popup) && event->matches(QKeySequence::Cancel)) {
9639 event->accept();
9640 close();
9641 } else
9642#endif
9643 {
9644 event->ignore();
9645 }
9646}
9647
9671{
9672 event->ignore();
9673}
9674
9695{
9696 if (focusPolicy() != Qt::NoFocus || !isWindow()) {
9697 update();
9698 }
9699}
9700
9721{
9722 if (focusPolicy() != Qt::NoFocus || !isWindow())
9723 update();
9724
9725#if !defined(QT_PLATFORM_UIKIT)
9726 // FIXME: revisit autoSIP logic, QTBUG-42906
9727 if (qApp->autoSipEnabled() && testAttribute(Qt::WA_InputMethodEnabled))
9729#endif
9730}
9731
9747
9761{
9762}
9763
9815
9816
9831{
9832}
9833
9834
9852{
9853}
9854
9855#ifndef QT_NO_ACTION
9865{
9866
9867}
9868#endif
9869
9886{
9887 event->accept();
9888}
9889
9890#ifndef QT_NO_CONTEXTMENU
9905{
9906 event->ignore();
9907}
9908#endif // QT_NO_CONTEXTMENU
9909
9910
9928{
9929 event->ignore();
9930}
9931
9943{
9944 switch(query) {
9946 return QRect(width()/2, 0, 1, height());
9947 case Qt::ImFont:
9948 return font();
9950 // Fallback.
9952 case Qt::ImHints:
9953 return (int)inputMethodHints();
9955 return d_func()->clipRect();
9956 default:
9957 return QVariant();
9958 }
9959}
9960
9986Qt::InputMethodHints QWidget::inputMethodHints() const
9987{
9988#if QT_CONFIG(im)
9989 const QWidgetPrivate *priv = d_func();
9990 while (priv->inheritsInputMethodHints) {
9991 priv = priv->q_func()->parentWidget()->d_func();
9992 Q_ASSERT(priv);
9993 }
9994 return priv->imHints;
9995#else
9996 return Qt::ImhNone;
9997#endif
9998}
9999
10000void QWidget::setInputMethodHints(Qt::InputMethodHints hints)
10001{
10002#ifndef QT_NO_IM
10003 Q_D(QWidget);
10004 if (d->imHints == hints)
10005 return;
10006 d->imHints = hints;
10007 if (this == QGuiApplication::focusObject())
10009#else
10010 Q_UNUSED(hints);
10011#endif //QT_NO_IM
10012}
10013
10014
10015#if QT_CONFIG(draganddrop)
10016
10031void QWidget::dragEnterEvent(QDragEnterEvent *)
10032{
10033}
10034
10049void QWidget::dragMoveEvent(QDragMoveEvent *)
10050{
10051}
10052
10065void QWidget::dragLeaveEvent(QDragLeaveEvent *)
10066{
10067}
10068
10080void QWidget::dropEvent(QDropEvent *)
10081{
10082}
10083
10084#endif // QT_CONFIG(draganddrop)
10085
10106{
10107}
10108
10128{
10129}
10130
10159{
10160 Q_UNUSED(eventType);
10163 return false;
10164}
10165
10190{
10191 Q_D(const QWidget);
10192
10193 const QMetaObject *m = metaObject();
10194 if (m == d->polished)
10195 return;
10196 d->polished = m;
10197
10199 QCoreApplication::sendEvent(const_cast<QWidget *>(this), &e);
10200
10201 // polish children after 'this'
10202 QList<QObject*> children = d->children;
10203 for (int i = 0; i < children.size(); ++i) {
10204 QObject *o = children.at(i);
10205 if (!o->isWidgetType())
10206 continue;
10207 if (QWidget *w = qobject_cast<QWidget *>(o))
10208 w->ensurePolished();
10209 }
10210
10211 if (d->parent && d->sendChildEvents) {
10212 QChildEvent e(QEvent::ChildPolished, const_cast<QWidget *>(this));
10213 QCoreApplication::sendEvent(d->parent, &e);
10214 }
10215}
10216
10224{
10225 Q_D(const QWidget);
10226 return d->extra ? d->extra->mask : QRegion();
10227}
10228
10239{
10240 return d_func()->layout;
10241}
10242
10243
10270{
10271 if (Q_UNLIKELY(!l)) {
10272 qWarning("QWidget::setLayout: Cannot set layout to 0");
10273 return;
10274 }
10275 if (layout()) {
10276 if (Q_UNLIKELY(layout() != l))
10277 qWarning("QWidget::setLayout: Attempting to set QLayout \"%s\" on %s \"%s\", which already has a"
10278 " layout", l->objectName().toLocal8Bit().data(), metaObject()->className(),
10280 return;
10281 }
10282
10283 QObject *oldParent = l->parent();
10284 if (oldParent && oldParent != this) {
10285 if (oldParent->isWidgetType()) {
10286 // Steal the layout off a widget parent. Takes effect when
10287 // morphing laid-out container widgets in Designer.
10288 QWidget *oldParentWidget = static_cast<QWidget *>(oldParent);
10289 oldParentWidget->takeLayout();
10290 } else {
10291 qWarning("QWidget::setLayout: Attempting to set QLayout \"%s\" on %s \"%s\", when the QLayout already has a parent",
10294 return;
10295 }
10296 }
10297
10298 Q_D(QWidget);
10299 l->d_func()->topLevel = true;
10300 d->layout = l;
10301 if (oldParent != this) {
10302 l->setParent(this);
10303 l->d_func()->reparentChildWidgets(this);
10304 l->invalidate();
10305 }
10306
10307 if (isWindow() && d->maybeTopData())
10308 d->topData()->sizeAdjusted = false;
10309}
10310
10318QLayout *QWidget::takeLayout()
10319{
10320 Q_D(QWidget);
10321 QLayout *l = layout();
10322 if (!l)
10323 return nullptr;
10324 d->layout = nullptr;
10325 l->setParent(nullptr);
10326 return l;
10327}
10328
10355{
10356 Q_D(const QWidget);
10357 return d->size_policy;
10358}
10359
10361{
10362 Q_D(QWidget);
10364 if (policy == d->size_policy)
10365 return;
10366
10367 if (d->size_policy.retainSizeWhenHidden() != policy.retainSizeWhenHidden())
10368 d->retainSizeWhenHiddenChanged = 1;
10369
10370 d->size_policy = policy;
10371
10372#if QT_CONFIG(graphicsview)
10373 if (const auto &extra = d->extra) {
10374 if (extra->proxyWidget)
10375 extra->proxyWidget->setSizePolicy(policy);
10376 }
10377#endif
10378
10380 d->retainSizeWhenHiddenChanged = 0;
10381
10382 if (isWindow() && d->maybeTopData())
10383 d->topData()->sizeAdjusted = false;
10384}
10385
10406{
10407 if (layout() && layout()->hasHeightForWidth())
10408 return layout()->totalHeightForWidth(w);
10409 return -1;
10410}
10411
10412
10419{
10420 Q_D(const QWidget);
10421 return d->layout ? d->layout->hasHeightForWidth() : d->size_policy.hasHeightForWidth();
10422}
10423
10440{
10441 return d_func()->childAt_helper(p, false);
10442}
10443
10444QWidget *QWidgetPrivate::childAt_helper(const QPoint &p, bool ignoreChildrenInDestructor) const
10445{
10446 if (children.isEmpty())
10447 return nullptr;
10448
10450 return nullptr;
10451 return childAtRecursiveHelper(p, ignoreChildrenInDestructor);
10452}
10453
10454QWidget *QWidgetPrivate::childAtRecursiveHelper(const QPoint &p, bool ignoreChildrenInDestructor) const
10455{
10456 for (int i = children.size() - 1; i >= 0; --i) {
10458 if (!child || child->isWindow() || child->isHidden() || child->testAttribute(Qt::WA_TransparentForMouseEvents)
10459 || (ignoreChildrenInDestructor && child->data->in_destructor)) {
10460 continue;
10461 }
10462
10463 // Map the point 'p' from parent coordinates to child coordinates.
10464 QPoint childPoint = p;
10465 childPoint -= child->data->crect.topLeft();
10466
10467 // Check if the point hits the child.
10468 if (!child->d_func()->pointInsideRectAndMask(childPoint))
10469 continue;
10470
10471 // Do the same for the child's descendants.
10472 if (QWidget *w = child->d_func()->childAtRecursiveHelper(childPoint, ignoreChildrenInDestructor))
10473 return w;
10474
10475 // We have found our target; namely the child at position 'p'.
10476 return child;
10477 }
10478 return nullptr;
10479}
10480
10482{
10483 Q_Q(QWidget);
10484 if (widgetItem)
10485 widgetItem->invalidateSizeCache();
10486 QWidget *parent;
10487 if (forceUpdate || !extra || extra->minw != extra->maxw || extra->minh != extra->maxh) {
10488 const int isHidden = q->isHidden() && !size_policy.retainSizeWhenHidden() && !retainSizeWhenHiddenChanged;
10489
10490 if (!q->isWindow() && !isHidden && (parent = q->parentWidget())) {
10491 if (parent->d_func()->layout)
10492 parent->d_func()->layout->invalidate();
10493 else if (parent->isVisible())
10495 }
10496 }
10497}
10498
10510{
10511 Q_D(QWidget);
10512 d->updateGeometry_helper(false);
10513}
10514
10533void QWidget::setWindowFlags(Qt::WindowFlags flags)
10534{
10535 Q_D(QWidget);
10536 d->setWindowFlags(flags);
10537}
10538
10548{
10549 Q_D(QWidget);
10550 if (on)
10551 d->setWindowFlags(data->window_flags | flag);
10552 else
10553 d->setWindowFlags(data->window_flags & ~flag);
10554}
10555
10561{
10562 Q_Q(QWidget);
10563 if (q->data->window_flags == flags)
10564 return;
10565
10566 if ((q->data->window_flags | flags) & Qt::Window) {
10567 // the old type was a window and/or the new type is a window
10568 QPoint oldPos = q->pos();
10569 bool visible = q->isVisible();
10570 const bool windowFlagChanged = (q->data->window_flags ^ flags) & Qt::Window;
10571 q->setParent(q->parentWidget(), flags);
10572
10573 // if both types are windows or neither of them are, we restore
10574 // the old position
10575 if (!windowFlagChanged && (visible || q->testAttribute(Qt::WA_Moved)))
10576 q->move(oldPos);
10577 // for backward-compatibility we change Qt::WA_QuitOnClose attribute value only when the window was recreated.
10579 } else {
10580 q->data->window_flags = flags;
10581 }
10582}
10583
10594{
10595 data->window_flags = flags;
10596}
10597
10636{
10637 if (parent == parentWidget())
10638 return;
10640}
10641
10643{
10645 if (d->renderToTexture) {
10646 QEvent e(eventType);
10648 }
10649
10650 for (int i = 0; i < d->children.size(); ++i) {
10651 QWidget *w = qobject_cast<QWidget *>(d->children.at(i));
10652 if (w && !w->isWindow())
10654 }
10655
10656 // Notify QWidgetWindow after we've notified all child QWidgets
10657 if (auto *window = d->windowHandle(QWidgetPrivate::WindowHandleMode::Direct)) {
10658 QEvent e(eventType);
10660 }
10661}
10662
10669void QWidget::setParent(QWidget *parent, Qt::WindowFlags f)
10670{
10671 Q_D(QWidget);
10672 Q_ASSERT_X(this != parent, Q_FUNC_INFO, "Cannot parent a QWidget to itself");
10673#ifdef QT_DEBUG
10674 const auto checkForParentChildLoops = qScopeGuard([&](){
10675 int depth = 0;
10676 auto p = parentWidget();
10677 while (p) {
10678 if (++depth == QObjectPrivate::CheckForParentChildLoopsWarnDepth) {
10679 qWarning("QWidget %p (class: '%s', object name: '%s') may have a loop in its parent-child chain; "
10680 "this is undefined behavior",
10681 this, metaObject()->className(), qPrintable(objectName()));
10682 }
10683 p = p->parentWidget();
10684 }
10685 });
10686#endif
10687
10688 const bool resized = testAttribute(Qt::WA_Resized);
10689 const bool wasCreated = testAttribute(Qt::WA_WState_Created);
10690 QWidget *oldtlw = window();
10691 Q_ASSERT(oldtlw);
10692 QWidget *oldParentWithWindow = d->closestParentWidgetWithWindowHandle();
10693
10694 if (f & Qt::Window) // Frame geometry likely changes, refresh.
10695 d->data.fstrut_dirty = true;
10696
10697 QWidget *desktopWidget = nullptr;
10698 if (parent && parent->windowType() == Qt::Desktop)
10699 desktopWidget = parent;
10700 bool newParent = (parent != parentWidget()) || desktopWidget;
10701
10702 if (newParent && parent && !desktopWidget) {
10704 parent->d_func()->enforceNativeChildren();
10705 else if (parent->d_func()->nativeChildrenForced() || parent->testAttribute(Qt::WA_PaintOnScreen))
10707 }
10708
10709 if (wasCreated) {
10711 // Hiding the widget will set WA_WState_Hidden as well, which would
10712 // normally require the widget to be explicitly shown again to become
10713 // visible, even as a child widget. But we refine this value later in
10714 // setParent_sys(), applying WA_WState_Hidden based on whether the
10715 // widget is a top level or not.
10716 hide();
10717
10718 // We reset WA_WState_ExplicitShowHide here, likely as a remnant of
10719 // when we only had QWidget::setVisible(), which is treated as an
10720 // explicit show/hide. Nowadays we have QWidgetPrivate::setVisible(),
10721 // that allows us to hide a widget without affecting ExplicitShowHide.
10722 // Though it can be argued that ExplicitShowHide should reflect the
10723 // last update of the widget's state, so if we hide the widget as a
10724 // side effect of changing parent, perhaps we _should_ reset it?
10726 }
10727 if (newParent) {
10730 }
10731 }
10732
10733 // texture-based widgets need a pre-notification when their associated top-level window changes
10734 // This is not under the wasCreated/newParent conditions above in order to also play nice with QDockWidget.
10735 const bool oldParentUsesRhiFlush = oldParentWithWindow ? oldParentWithWindow->d_func()->usesRhiFlush : false;
10736 if (oldParentUsesRhiFlush && ((!parent && parentWidget()) || (parent && parent->window() != oldtlw)))
10738
10739 // If we get parented into another window, children will be folded
10740 // into the new parent's focus chain, so clear focus now.
10741 if (newParent && isAncestorOf(focusWidget()) && !(f & Qt::Window))
10743
10744 d->setParent_sys(parent, f);
10745
10746 if (desktopWidget)
10747 parent = nullptr;
10748
10749 if (d->textureChildSeen && parent) {
10750 // set the textureChildSeen flag up the whole parent chain
10751 QWidgetPrivate::get(parent)->setTextureChildSeen();
10752 }
10753
10754 if (QWidgetRepaintManager *oldPaintManager = oldtlw->d_func()->maybeRepaintManager()) {
10755 if (newParent)
10756 oldPaintManager->removeDirtyWidget(this);
10757 // Move the widget and all its static children from
10758 // the old backing store to the new one.
10759 oldPaintManager->moveStaticWidgets(this);
10760 }
10761
10762 d->reparentFocusWidgets(oldtlw);
10763 setAttribute(Qt::WA_Resized, resized);
10764
10765 const bool useStyleSheetPropagationInWidgetStyles =
10767
10768 if (!useStyleSheetPropagationInWidgetStyles && !testAttribute(Qt::WA_StyleSheet)
10769 && (!parent || !parent->testAttribute(Qt::WA_StyleSheet))) {
10770 // if the parent has a font set or inherited, then propagate the mask to the new child
10771 if (parent) {
10772 const auto pd = parent->d_func();
10773 d->inheritedFontResolveMask = pd->directFontResolveMask | pd->inheritedFontResolveMask;
10774 d->inheritedPaletteResolveMask = pd->directPaletteResolveMask | pd->inheritedPaletteResolveMask;
10775 }
10776 d->resolveFont();
10777 d->resolvePalette();
10778 }
10779 d->resolveLayoutDirection();
10780 d->resolveLocale();
10781
10782 // Note: GL widgets under WGL or EGL will always need a ParentChange
10783 // event to handle recreation/rebinding of the GL context, hence the
10784 // (f & Qt::MSWindowsOwnDC) clause (which is set on QGLWidgets on all
10785 // platforms).
10786 if (newParent || !wasCreated
10787#if QT_CONFIG(opengles2)
10788 || (f & Qt::MSWindowsOwnDC)
10789#endif
10790 ) {
10791 // propagate enabled updates enabled state to non-windows
10792 if (!isWindow()) {
10794 d->setEnabled_helper(parent ? parent->isEnabled() : true);
10796 d->setUpdatesEnabled_helper(parent ? parent->updatesEnabled() : true);
10797 }
10798 d->inheritStyle();
10799
10800 // send and post remaining QObject events
10801 if (parent && d->sendChildEvents) {
10804 }
10805
10806 if (parent && d->sendChildEvents && d->polished) {
10809 }
10810
10813 }
10814
10815 // texture-based widgets need another event when their top-level window
10816 // changes (more precisely, has already changed at this point)
10817 if (oldParentUsesRhiFlush && oldtlw != window())
10819
10820 if (!wasCreated) {
10821 if (isWindow() || parentWidget()->isVisible())
10825 }
10826
10827 d->updateIsOpaque();
10828
10829#if QT_CONFIG(graphicsview)
10830 // Embed the widget into a proxy if the parent is embedded.
10831 // ### Doesn't handle reparenting out of an embedded widget.
10832 if (oldtlw->graphicsProxyWidget()) {
10833 if (QGraphicsProxyWidget *ancestorProxy = d->nearestGraphicsProxyWidget(oldtlw))
10834 ancestorProxy->d_func()->unembedSubWindow(this);
10835 }
10836 if (isWindow() && parent && !graphicsProxyWidget() && !bypassGraphicsProxyWidget(this)) {
10837 if (QGraphicsProxyWidget *ancestorProxy = d->nearestGraphicsProxyWidget(parent))
10838 ancestorProxy->d_func()->embedSubWindow(this);
10839 }
10840#endif
10841
10842 if (d->extra && d->extra->hasWindowContainer)
10844
10845 QWidget *newParentWithWindow = d->closestParentWidgetWithWindowHandle();
10846 if (newParentWithWindow && newParentWithWindow != oldParentWithWindow) {
10847 // Check if the native parent now needs to switch to RHI
10848 qCDebug(lcWidgetPainting) << "Evaluating whether reparenting of" << this
10849 << "into" << parent << "requires RHI enablement for" << newParentWithWindow;
10850
10853
10854 // First evaluate whether the reparented widget uses RHI.
10855 // We do this as a separate step because the performance
10856 // implications of always checking the native parent are
10857 // problematic when it comes to large widget trees.
10858 if (q_evaluateRhiConfig(this, &rhiConfig, &surfaceType)) {
10859 // Then check whether the native parent requires RHI
10860 // as a result. It may not, if this widget is a native
10861 // window, and can handle its own RHI flushing.
10862 if (q_evaluateRhiConfig(newParentWithWindow, nullptr, nullptr)) {
10863 // Finally, check whether we need to recreate the
10864 // native parent to enable RHI flushing.
10865 auto *existingWindow = newParentWithWindow->windowHandle();
10866 auto existingSurfaceType = existingWindow->surfaceType();
10867 if (existingSurfaceType != surfaceType) {
10868 qCDebug(lcWidgetPainting)
10869 << "Recreating" << existingWindow
10870 << "with current type" << existingSurfaceType
10871 << "to support" << surfaceType;
10872 const auto windowStateBeforeDestroy = newParentWithWindow->windowState();
10873 const auto visibilityBeforeDestroy = newParentWithWindow->isVisible();
10874 newParentWithWindow->destroy();
10875 newParentWithWindow->create();
10876 Q_ASSERT(newParentWithWindow->windowHandle());
10877 newParentWithWindow->windowHandle()->setWindowStates(windowStateBeforeDestroy);
10878 QWidgetPrivate::get(newParentWithWindow)->setVisible(visibilityBeforeDestroy);
10879 } else if (auto *backingStore = newParentWithWindow->backingStore()) {
10880 // If we don't recreate we still need to make sure the native parent
10881 // widget has a RHI config that the reparented widget can use.
10882 backingStore->handle()->createRhi(existingWindow, rhiConfig);
10883 // And that it knows it's now flushing with RHI
10884 QWidgetPrivate::get(newParentWithWindow)->usesRhiFlush = true;
10885 }
10886 }
10887 }
10888 }
10889}
10890
10891void QWidgetPrivate::setParent_sys(QWidget *newparent, Qt::WindowFlags f)
10892{
10893 Q_Q(QWidget);
10894
10895 Qt::WindowFlags oldFlags = data.window_flags;
10896 bool wasCreated = q->testAttribute(Qt::WA_WState_Created);
10897
10898 QScreen *targetScreen = nullptr;
10899 // Handle a request to move the widget to a particular screen
10900 if (newparent && newparent->windowType() == Qt::Desktop) {
10901 // make sure the widget is created on the same screen as the
10902 // programmer specified desktop widget
10903 targetScreen = newparent->screen();
10904 newparent = nullptr;
10905 }
10906
10907 setWinId(0);
10908
10909 if (!newparent) {
10910 f |= Qt::Window;
10911 if (parent)
10912 targetScreen = q->parentWidget()->window()->screen();
10913 }
10914
10915 const bool destroyWindow = (
10916 // Reparenting top level to child
10917 (oldFlags & Qt::Window) && !(f & Qt::Window)
10918 // And we can dispose of the window
10919 && wasCreated && !q->testAttribute(Qt::WA_NativeWindow)
10920 );
10921
10922 if (parent != newparent) {
10923 // Update object parent now, so we can resolve new parent window below
10925
10926 if (q->windowHandle())
10927 q->windowHandle()->setFlags(f);
10928
10929 // If the widget itself or any of its children have been created,
10930 // we need to reparent their QWindows as well.
10931 QWidget *parentWithWindow = closestParentWidgetWithWindowHandle();
10932 // But if the widget is about to be destroyed we must skip the
10933 // widget itself, and only reparent children.
10934 if (destroyWindow)
10935 reparentWidgetWindowChildren(parentWithWindow);
10936 else
10937 reparentWidgetWindows(parentWithWindow, f);
10938 }
10939
10940 bool explicitlyHidden = isExplicitlyHidden();
10941
10942 if (destroyWindow) {
10943 if (extra && extra->hasWindowContainer)
10945
10946 // There shouldn't be any QWindow children left, but if there
10947 // are, re-parent them now, before we destroy.
10948 if (!q->windowHandle()->children().isEmpty()) {
10949 QWidget *parentWithWindow = closestParentWidgetWithWindowHandle();
10950 QWindow *newParentWindow = parentWithWindow ? parentWithWindow->windowHandle() : nullptr;
10951 for (QObject *child : q->windowHandle()->children()) {
10952 if (QWindow *childWindow = qobject_cast<QWindow *>(child)) {
10953 qCWarning(lcWidgetWindow) << "Reparenting" << childWindow
10954 << "before destroying" << this;
10955 childWindow->setParent(newParentWindow);
10956 }
10957 }
10958 }
10959
10960 // We have reparented any child windows of the widget we are
10961 // about to destroy to the new parent window handle, so we can
10962 // safely destroy this widget without destroying sub windows.
10963 q->destroy(true, false);
10964 }
10965
10966 adjustFlags(f, q);
10967 data.window_flags = f;
10968 q->setAttribute(Qt::WA_WState_Created, false);
10969 q->setAttribute(Qt::WA_WState_Visible, false);
10970 q->setAttribute(Qt::WA_WState_Hidden, false);
10971
10972 if (newparent && wasCreated && (q->testAttribute(Qt::WA_NativeWindow) || (f & Qt::Window)))
10973 q->createWinId();
10974
10975 if (q->isWindow() || (!newparent || newparent->isVisible()) || explicitlyHidden)
10976 q->setAttribute(Qt::WA_WState_Hidden);
10977 q->setAttribute(Qt::WA_WState_ExplicitShowHide, explicitlyHidden);
10978
10979 // move the window to the selected screen
10980 if (!newparent && targetScreen) {
10981 // only if it is already created
10982 if (q->testAttribute(Qt::WA_WState_Created))
10983 q->windowHandle()->setScreen(targetScreen);
10984 else
10985 topData()->initialScreen = targetScreen;
10986 }
10987}
10988
10989void QWidgetPrivate::reparentWidgetWindows(QWidget *parentWithWindow, Qt::WindowFlags windowFlags)
10990{
10991 if (QWindow *window = windowHandle()) {
10992 // Reparent this QWindow, and all QWindow children will follow
10993 if (parentWithWindow) {
10994 // The reparented widget has not updated its window flags yet,
10995 // so we can't ask the widget directly. And we can't use the
10996 // QWindow flags, as unlike QWidgets the QWindow flags always
10997 // reflect Qt::Window, even for child windows. And we can't use
10998 // QWindow::isTopLevel() either, as that depends on the parent,
10999 // which we are in the process of updating. So we propagate the
11000 // new flags of the reparented window from setParent_sys().
11001 if (windowFlags & Qt::Window) {
11002 // Top level windows can only have transient parents,
11003 // and the transient parent must be another top level.
11004 QWidget *topLevel = parentWithWindow->window();
11005 auto *transientParent = topLevel->windowHandle();
11006 Q_ASSERT(transientParent);
11007 qCDebug(lcWidgetWindow) << "Setting" << window << "transient parent to" << transientParent;
11008 window->setTransientParent(transientParent);
11009 window->setParent(nullptr);
11010 } else {
11011 auto *parentWindow = parentWithWindow->windowHandle();
11012 qCDebug(lcWidgetWindow) << "Reparenting" << window << "into" << parentWindow;
11013 window->setTransientParent(nullptr);
11014 window->setParent(parentWindow);
11015 }
11016 } else {
11017 qCDebug(lcWidgetWindow) << "Making" << window << "top level window";
11018 window->setTransientParent(nullptr);
11019 window->setParent(nullptr);
11020 }
11021 } else {
11022 reparentWidgetWindowChildren(parentWithWindow);
11023 }
11024}
11025
11027{
11028 for (auto *child : std::as_const(children)) {
11029 if (auto *childWidget = qobject_cast<QWidget*>(child)) {
11030 auto *childPrivate = QWidgetPrivate::get(childWidget);
11031 childPrivate->reparentWidgetWindows(parentWithWindow);
11032 }
11033 }
11034}
11035
11057void QWidget::scroll(int dx, int dy)
11058{
11059 if ((!updatesEnabled() && children().size() == 0) || !isVisible())
11060 return;
11061 if (dx == 0 && dy == 0)
11062 return;
11063 Q_D(QWidget);
11064#if QT_CONFIG(graphicsview)
11065 if (QGraphicsProxyWidget *proxy = QWidgetPrivate::nearestGraphicsProxyWidget(this)) {
11066 // Graphics View maintains its own dirty region as a list of rects;
11067 // until we can connect item updates directly to the view, we must
11068 // separately add a translated dirty region.
11069 for (const QRect &rect : d->dirty)
11070 proxy->update(rect.translated(dx, dy));
11071 proxy->scroll(dx, dy, proxy->subWidgetRect(this));
11072 return;
11073 }
11074#endif
11075 d->setDirtyOpaqueRegion();
11076 d->scroll_sys(dx, dy);
11077}
11078
11079void QWidgetPrivate::scroll_sys(int dx, int dy)
11080{
11081 Q_Q(QWidget);
11082 scrollChildren(dx, dy);
11083 scrollRect(q->rect(), dx, dy);
11084}
11085
11096void QWidget::scroll(int dx, int dy, const QRect &r)
11097{
11098
11099 if ((!updatesEnabled() && children().size() == 0) || !isVisible())
11100 return;
11101 if (dx == 0 && dy == 0)
11102 return;
11103 Q_D(QWidget);
11104#if QT_CONFIG(graphicsview)
11105 if (QGraphicsProxyWidget *proxy = QWidgetPrivate::nearestGraphicsProxyWidget(this)) {
11106 // Graphics View maintains its own dirty region as a list of rects;
11107 // until we can connect item updates directly to the view, we must
11108 // separately add a translated dirty region.
11109 if (!d->dirty.isEmpty()) {
11110 for (const QRect &rect : d->dirty.translated(dx, dy) & r)
11111 proxy->update(rect);
11112 }
11113 proxy->scroll(dx, dy, r.translated(proxy->subWidgetRect(this).topLeft().toPoint()));
11114 return;
11115 }
11116#endif
11117 d->scroll_sys(dx, dy, r);
11118}
11119
11120void QWidgetPrivate::scroll_sys(int dx, int dy, const QRect &r)
11121{
11122 scrollRect(r, dx, dy);
11123}
11124
11142{
11143 repaint(rect());
11144}
11145
11154void QWidget::repaint(int x, int y, int w, int h)
11155{
11156 if (x > data->crect.width() || y > data->crect.height())
11157 return;
11158
11159 if (w < 0)
11160 w = data->crect.width() - x;
11161 if (h < 0)
11162 h = data->crect.height() - y;
11163
11164 repaint(QRect(x, y, w, h));
11165}
11166
11172{
11173 Q_D(QWidget);
11174 d->repaint(rect);
11175}
11176
11183{
11184 Q_D(QWidget);
11185 d->repaint(rgn);
11186}
11187
11188template <typename T>
11190{
11191 Q_Q(QWidget);
11192
11193 if (!q->isVisible() || !q->updatesEnabled() || r.isEmpty())
11194 return;
11195
11196 QTLWExtra *tlwExtra = q->window()->d_func()->maybeTopData();
11197 if (tlwExtra && tlwExtra->backingStore && tlwExtra->repaintManager)
11198 tlwExtra->repaintManager->markDirty(r, q, QWidgetRepaintManager::UpdateNow);
11199}
11200
11220{
11221 update(rect());
11222}
11223
11237{
11238 Q_D(QWidget);
11239 d->update(rect);
11240}
11241
11247void QWidget::update(const QRegion &rgn)
11248{
11249 Q_D(QWidget);
11250 d->update(rgn);
11251}
11252
11253template <typename T>
11255{
11256 Q_Q(QWidget);
11257
11258 if (renderToTexture && !q->isVisible()) {
11260 return;
11261 }
11262
11263 if (!q->isVisible() || !q->updatesEnabled())
11264 return;
11265
11266 T clipped = r & q->rect();
11267
11268 if (clipped.isEmpty())
11269 return;
11270
11271 if (q->testAttribute(Qt::WA_WState_InPaintEvent)) {
11273 return;
11274 }
11275
11276 QTLWExtra *tlwExtra = q->window()->d_func()->maybeTopData();
11277 if (tlwExtra && tlwExtra->backingStore && tlwExtra->repaintManager)
11278 tlwExtra->repaintManager->markDirty(clipped, q);
11279}
11280
11288{
11289 if (attribute < int(8*sizeof(uint))) {
11290 if (on)
11291 data->widget_attributes |= (1<<attribute);
11292 else
11293 data->widget_attributes &= ~(1<<attribute);
11294 } else {
11295 const int x = attribute - 8*sizeof(uint);
11296 const int int_off = x / (8*sizeof(uint));
11297 if (on)
11298 d->high_attributes[int_off] |= (1<<(x-(int_off*8*sizeof(uint))));
11299 else
11300 d->high_attributes[int_off] &= ~(1<<(x-(int_off*8*sizeof(uint))));
11301 }
11302}
11303
11304#ifdef Q_OS_MAC
11305void QWidgetPrivate::macUpdateSizeAttribute()
11306{
11307 Q_Q(QWidget);
11310 for (int i = 0; i < children.size(); ++i) {
11312 if (w && (!w->isWindow() || w->testAttribute(Qt::WA_WindowPropagation))
11313 && !w->testAttribute(Qt::WA_MacMiniSize) // no attribute set? inherit from parent
11314 && !w->testAttribute(Qt::WA_MacSmallSize)
11315 && !w->testAttribute(Qt::WA_MacNormalSize))
11316 w->d_func()->macUpdateSizeAttribute();
11317 }
11318 resolveFont();
11319}
11320#endif
11321
11329{
11330 if (testAttribute(attribute) == on)
11331 return;
11332
11333 Q_D(QWidget);
11334 static_assert(sizeof(d->high_attributes)*8 >= (Qt::WA_AttributeCount - sizeof(uint)*8),
11335 "QWidget::setAttribute(WidgetAttribute, bool): "
11336 "QWidgetPrivate::high_attributes[] too small to contain all attributes in WidgetAttribute");
11337#ifdef Q_OS_WIN
11338 // ### Don't use PaintOnScreen+paintEngine() to do native painting in some future release
11339 if (attribute == Qt::WA_PaintOnScreen && on && windowType() != Qt::Desktop && !inherits("QGLWidget")) {
11340 // see ::paintEngine for details
11341 paintEngine();
11342 if (d->noPaintOnScreen)
11343 return;
11344 }
11345#endif
11346
11347 // Don't set WA_NativeWindow on platforms that don't support it -- except for QGLWidget, which depends on it
11348 if (attribute == Qt::WA_NativeWindow && !d->mustHaveWindowHandle) {
11350 if (!platformIntegration->hasCapability(QPlatformIntegration::NativeWidgets))
11351 return;
11352 }
11353
11355
11356 switch (attribute) {
11357
11358#if QT_CONFIG(draganddrop)
11359 case Qt::WA_AcceptDrops: {
11366 break;
11367 }
11369 for (int i = 0; i < d->children.size(); ++i) {
11370 QWidget *w = qobject_cast<QWidget *>(d->children.at(i));
11371 if (w && !w->isWindow() && !w->testAttribute(Qt::WA_AcceptDrops) && w->testAttribute(Qt::WA_DropSiteRegistered) != on)
11372 w->setAttribute(Qt::WA_DropSiteRegistered, on);
11373 }
11374 break;
11375 }
11376#endif
11377
11379 d->sendChildEvents = !on;
11380 break;
11382 d->receiveChildEvents = !on;
11383 break;
11386 case Qt::WA_MacMiniSize:
11387#ifdef Q_OS_MAC
11388 {
11389 // We can only have one of these set at a time
11392 for (int i = 0; i < 3; ++i) {
11393 if (MacSizes[i] != attribute)
11394 setAttribute_internal(MacSizes[i], false, data, d);
11395 }
11396 d->macUpdateSizeAttribute();
11397 }
11398#endif
11399 break;
11400 case Qt::WA_ShowModal:
11401 if (!on) {
11402 // reset modality type to NonModal when clearing WA_ShowModal
11403 data->window_modality = Qt::NonModal;
11404 } else if (data->window_modality == Qt::NonModal) {
11405 // If modality hasn't been set prior to setting WA_ShowModal, use
11406 // ApplicationModal.
11407 data->window_modality = Qt::ApplicationModal;
11408 // Some window managers do not allow us to enter modality after the
11409 // window is visible.The window must be hidden before changing the
11410 // windowModality property and then reshown.
11411 }
11413 // don't call setModal_sys() before create()
11414 d->setModal_sys();
11415 }
11416 break;
11417 case Qt::WA_MouseTracking: {
11420 break; }
11421 case Qt::WA_TabletTracking: {
11424 break; }
11425 case Qt::WA_NativeWindow: {
11426 d->createTLExtra();
11427 if (on)
11428 d->createTLSysExtra();
11429#ifndef QT_NO_IM
11430 QWidget *focusWidget = d->effectiveFocusWidget();
11431 if (on && !internalWinId() && this == QGuiApplication::focusObject()
11433 QGuiApplication::inputMethod()->commit();
11435 }
11437 parentWidget()->d_func()->enforceNativeChildren();
11439 d->createWinId();
11443 }
11444#endif //QT_NO_IM
11445 break;
11446 }
11448 d->updateIsOpaque();
11449 Q_FALLTHROUGH();
11451 d->updateIsOpaque();
11452 break;
11454 d->updateIsOpaque();
11455 Q_FALLTHROUGH();
11457 d->updateSystemBackground();
11458 break;
11460 break;
11462#ifndef QT_NO_IM
11463 if (QGuiApplication::focusObject() == this) {
11464 if (!on)
11465 QGuiApplication::inputMethod()->commit();
11467 }
11468#endif //QT_NO_IM
11469 break;
11470 }
11472 d->resolvePalette();
11473 d->resolveFont();
11474 d->resolveLocale();
11475 break;
11477 if (on && isVisible()) {
11478 // Make sure we keep the current state and only hide the widget
11479 // from the desktop. show_sys will only update platform specific
11480 // attributes at this point.
11481 d->hide_sys();
11482 d->show_sys();
11483 }
11484 break;
11485 }
11486
11500 d->setNetWmWindowTypes();
11501 break;
11502
11504 if (QWidgetRepaintManager *repaintManager = d->maybeRepaintManager()) {
11505 if (on)
11506 repaintManager->addStaticWidget(this);
11507 else
11508 repaintManager->removeStaticWidget(this);
11509 }
11510 break;
11512 if (on)
11514 d->updateIsTranslucent();
11515
11516 break;
11518 break;
11519 default:
11520 break;
11521 }
11522}
11523
11531bool QWidget::testAttribute_helper(Qt::WidgetAttribute attribute) const
11532{
11533 Q_D(const QWidget);
11534 const int x = attribute - 8*sizeof(uint);
11535 const int int_off = x / (8*sizeof(uint));
11536 return (d->high_attributes[int_off] & (1<<(x-(int_off*8*sizeof(uint)))));
11537}
11538
11565{
11566 Q_D(const QWidget);
11567 return (isWindow() && d->maybeTopData()) ? d->maybeTopData()->opacity / 255. : 1.0;
11568}
11569
11571{
11572 Q_D(QWidget);
11573 if (!isWindow())
11574 return;
11575
11576 opacity = qBound(qreal(0.0), opacity, qreal(1.0));
11577 QTLWExtra *extra = d->topData();
11578 extra->opacity = uint(opacity * 255);
11580 d->setWindowOpacity_sys(opacity);
11581
11583 return;
11584
11585#if QT_CONFIG(graphicsview)
11586 if (QGraphicsProxyWidget *proxy = graphicsProxyWidget()) {
11587 // Avoid invalidating the cache if set.
11588 if (proxy->cacheMode() == QGraphicsItem::NoCache)
11589 proxy->update();
11590 else if (QGraphicsScene *scene = proxy->scene())
11591 scene->update(proxy->sceneBoundingRect());
11592 return;
11593 }
11594#endif
11595}
11596
11598{
11599 Q_Q(QWidget);
11600 if (q->windowHandle())
11601 q->windowHandle()->setOpacity(level);
11602}
11603
11629{
11631}
11632
11634{
11635 Q_D(QWidget);
11637
11638 d->setWindowModified_helper();
11639
11642}
11643
11645{
11646 Q_Q(QWidget);
11647 QWindow *window = q->windowHandle();
11648 if (!window)
11649 return;
11650 QPlatformWindow *platformWindow = window->handle();
11651 if (!platformWindow)
11652 return;
11653 bool on = q->testAttribute(Qt::WA_WindowModified);
11654 if (!platformWindow->setWindowModified(on)) {
11655 if (Q_UNLIKELY(on && !q->windowTitle().contains("[*]"_L1)))
11656 qWarning("QWidget::setWindowModified: The window title does not contain a '[*]' placeholder");
11657 setWindowTitle_helper(q->windowTitle());
11658 setWindowIconText_helper(q->windowIconText());
11659 }
11660}
11661
11662#if QT_CONFIG(tooltip)
11681void QWidget::setToolTip(const QString &s)
11682{
11683 Q_D(QWidget);
11684 d->toolTip = s;
11685
11688}
11689
11690QString QWidget::toolTip() const
11691{
11692 Q_D(const QWidget);
11693 return d->toolTip;
11694}
11695
11707void QWidget::setToolTipDuration(int msec)
11708{
11709 Q_D(QWidget);
11710 d->toolTipDuration = msec;
11711}
11712
11713int QWidget::toolTipDuration() const
11714{
11715 Q_D(const QWidget);
11716 return d->toolTipDuration;
11717}
11718
11719#endif // QT_CONFIG(tooltip)
11720
11721
11722#if QT_CONFIG(statustip)
11731void QWidget::setStatusTip(const QString &s)
11732{
11733 Q_D(QWidget);
11734 d->statusTip = s;
11735}
11736
11737QString QWidget::statusTip() const
11738{
11739 Q_D(const QWidget);
11740 return d->statusTip;
11741}
11742#endif // QT_CONFIG(statustip)
11743
11744#if QT_CONFIG(whatsthis)
11754void QWidget::setWhatsThis(const QString &s)
11755{
11756 Q_D(QWidget);
11757 d->whatsThis = s;
11758}
11759
11760QString QWidget::whatsThis() const
11761{
11762 Q_D(const QWidget);
11763 return d->whatsThis;
11764}
11765#endif // QT_CONFIG(whatsthis)
11766
11767#if QT_CONFIG(accessibility)
11789void QWidget::setAccessibleName(const QString &name)
11790{
11791 Q_D(QWidget);
11792 d->accessibleName = name;
11793 QAccessibleEvent event(this, QAccessible::NameChanged);
11794 QAccessible::updateAccessibility(&event);
11795}
11796
11797QString QWidget::accessibleName() const
11798{
11799 Q_D(const QWidget);
11800 return d->accessibleName;
11801}
11802
11819void QWidget::setAccessibleDescription(const QString &description)
11820{
11821 Q_D(QWidget);
11822 d->accessibleDescription = description;
11823 QAccessibleEvent event(this, QAccessible::DescriptionChanged);
11824 QAccessible::updateAccessibility(&event);
11825}
11826
11827QString QWidget::accessibleDescription() const
11828{
11829 Q_D(const QWidget);
11830 return d->accessibleDescription;
11831}
11832#endif // QT_CONFIG(accessibility)
11833
11834#ifndef QT_NO_SHORTCUT
11859{
11860 Q_ASSERT(qApp);
11861 if (key.isEmpty())
11862 return 0;
11864 return QGuiApplicationPrivate::instance()->shortcutMap.addShortcut(this, key, context, qWidgetShortcutContextMatcher);
11865}
11866
11883{
11884 Q_ASSERT(qApp);
11885 if (id)
11886 QGuiApplicationPrivate::instance()->shortcutMap.removeShortcut(id, this, 0);
11887}
11888
11902{
11903 Q_ASSERT(qApp);
11904 if (id)
11905 QGuiApplicationPrivate::instance()->shortcutMap.setShortcutEnabled(enable, id, this, 0);
11906}
11907
11917{
11918 Q_ASSERT(qApp);
11919 if (id)
11920 QGuiApplicationPrivate::instance()->shortcutMap.setShortcutAutoRepeat(enable, id, this, 0);
11921}
11922#endif // QT_NO_SHORTCUT
11923
11933
11947{
11948 Q_D(QWidget);
11949 if (!isWindow()) {
11950 QWidget *p = parentWidget();
11951 const int parentChildCount = p->d_func()->children.size();
11952 if (parentChildCount < 2)
11953 return;
11954 const int from = p->d_func()->children.indexOf(this);
11955 Q_ASSERT(from >= 0);
11956 // Do nothing if the widget is already in correct stacking order _and_ created.
11957 if (from != parentChildCount -1)
11958 p->d_func()->children.move(from, parentChildCount - 1);
11960 create();
11961 else if (from == parentChildCount - 1)
11962 return;
11963
11964 QRegion region(rect());
11965 d->subtractOpaqueSiblings(region);
11966 d->invalidateBackingStore(region);
11967 }
11969 d->raise_sys();
11970
11971 if (d->extra && d->extra->hasWindowContainer)
11973
11976}
11977
11979{
11980 Q_Q(QWidget);
11981 if (q->isWindow() || q->testAttribute(Qt::WA_NativeWindow)) {
11982 q->windowHandle()->raise();
11983 } else if (renderToTexture) {
11984 if (QWidget *p = q->parentWidget()) {
11986 p->d_func()->invalidateBackingStore(effectiveRectFor(q->geometry()));
11987 }
11988 }
11989}
11990
12001{
12002 Q_D(QWidget);
12003 if (!isWindow()) {
12004 QWidget *p = parentWidget();
12005 const int parentChildCount = p->d_func()->children.size();
12006 if (parentChildCount < 2)
12007 return;
12008 const int from = p->d_func()->children.indexOf(this);
12009 Q_ASSERT(from >= 0);
12010 // Do nothing if the widget is already in correct stacking order _and_ created.
12011 if (from != 0)
12012 p->d_func()->children.move(from, 0);
12014 create();
12015 else if (from == 0)
12016 return;
12017 }
12019 d->lower_sys();
12020
12021 if (d->extra && d->extra->hasWindowContainer)
12023
12026}
12027
12029{
12030 Q_Q(QWidget);
12031 if (q->isWindow() || q->testAttribute(Qt::WA_NativeWindow)) {
12032 Q_ASSERT(q->testAttribute(Qt::WA_WState_Created));
12033 q->windowHandle()->lower();
12034 } else if (QWidget *p = q->parentWidget()) {
12036 p->d_func()->invalidateBackingStore(effectiveRectFor(q->geometry()));
12037 }
12038}
12039
12048{
12049 Q_D(QWidget);
12050 QWidget *p = parentWidget();
12051 if (!w || isWindow() || p != w->parentWidget() || this == w)
12052 return;
12053 if (p) {
12054 int from = p->d_func()->children.indexOf(this);
12055 int to = p->d_func()->children.indexOf(w);
12056 Q_ASSERT(from >= 0);
12057 Q_ASSERT(to >= 0);
12058 if (from < to)
12059 --to;
12060 // Do nothing if the widget is already in correct stacking order _and_ created.
12061 if (from != to)
12062 p->d_func()->children.move(from, to);
12064 create();
12065 else if (from == to)
12066 return;
12067 }
12069 d->stackUnder_sys(w);
12070
12073}
12074
12076{
12077 Q_Q(QWidget);
12078 if (QWidget *p = q->parentWidget()) {
12080 p->d_func()->invalidateBackingStore(effectiveRectFor(q->geometry()));
12081 }
12082}
12083
12125{
12126 Q_Q(const QWidget);
12127 if (!q->isWindow() || (q->windowType() == Qt::Desktop) || q->testAttribute(Qt::WA_DontShowOnScreen)) {
12128 // x2 = x1 + w - 1, so w/h = 1
12129 return QRect(0, 0, 1, 1);
12130 }
12131
12132 if (data.fstrut_dirty
12133 // ### Fix properly for 4.3
12134 && q->isVisible()
12135 && q->testAttribute(Qt::WA_WState_Created))
12136 const_cast<QWidgetPrivate *>(this)->updateFrameStrut();
12137
12138 return maybeTopData() ? maybeTopData()->frameStrut : QRect();
12139}
12140
12142{
12143 Q_Q(QWidget);
12144 if (q->data->fstrut_dirty) {
12145 if (QTLWExtra *te = maybeTopData()) {
12146 if (te->window && te->window->handle()) {
12147 const QMargins margins = te->window->frameMargins();
12148 if (!margins.isNull()) {
12149 te->frameStrut.setCoords(margins.left(), margins.top(), margins.right(), margins.bottom());
12150 q->data->fstrut_dirty = false;
12151 }
12152 }
12153 }
12154 }
12155}
12156
12157#ifdef QT_KEYPAD_NAVIGATION
12166bool QWidgetPrivate::navigateToDirection(Direction direction)
12167{
12168 QWidget *targetWidget = widgetInNavigationDirection(direction);
12169 if (targetWidget)
12170 targetWidget->setFocus();
12171 return (targetWidget != 0);
12172}
12173
12183QWidget *QWidgetPrivate::widgetInNavigationDirection(Direction direction)
12184{
12185 const QWidget *sourceWidget = QApplication::focusWidget();
12186 if (!sourceWidget)
12187 return nullptr;
12188 const QRect sourceRect = sourceWidget->rect().translated(sourceWidget->mapToGlobal(QPoint()));
12189 const int sourceX =
12191 (sourceRect.left() + (sourceRect.right() - sourceRect.left()) / 2)
12192 :(direction == DirectionEast ? sourceRect.right() : sourceRect.left());
12193 const int sourceY =
12195 (sourceRect.top() + (sourceRect.bottom() - sourceRect.top()) / 2)
12196 :(direction == DirectionSouth ? sourceRect.bottom() : sourceRect.top());
12197 const QPoint sourcePoint(sourceX, sourceY);
12198 const QPoint sourceCenter = sourceRect.center();
12199 const QWidget *sourceWindow = sourceWidget->window();
12200
12201 QWidget *targetWidget = nullptr;
12202 int shortestDistance = INT_MAX;
12203
12204 const auto targetCandidates = QApplication::allWidgets();
12205 for (QWidget *targetCandidate : targetCandidates) {
12206
12207 const QRect targetCandidateRect = targetCandidate->rect().translated(targetCandidate->mapToGlobal(QPoint()));
12208
12209 // For focus proxies, the child widget handling the focus can have keypad navigation focus,
12210 // but the owner of the proxy cannot.
12211 // Additionally, empty widgets should be ignored.
12212 if (targetCandidate->focusProxy() || targetCandidateRect.isEmpty())
12213 continue;
12214
12215 // Only navigate to a target widget that...
12216 if ( targetCandidate != sourceWidget
12217 // ...takes the focus,
12218 && targetCandidate->focusPolicy() & Qt::TabFocus
12219 // ...is above if DirectionNorth,
12220 && !(direction == DirectionNorth && targetCandidateRect.bottom() > sourceRect.top())
12221 // ...is on the right if DirectionEast,
12222 && !(direction == DirectionEast && targetCandidateRect.left() < sourceRect.right())
12223 // ...is below if DirectionSouth,
12224 && !(direction == DirectionSouth && targetCandidateRect.top() < sourceRect.bottom())
12225 // ...is on the left if DirectionWest,
12226 && !(direction == DirectionWest && targetCandidateRect.right() > sourceRect.left())
12227 // ...is enabled,
12228 && targetCandidate->isEnabled()
12229 // ...is visible,
12230 && targetCandidate->isVisible()
12231 // ...is in the same window,
12232 && targetCandidate->window() == sourceWindow) {
12233 const int targetCandidateDistance = [](const QPoint &sourcePoint,
12234 const QRect &targetCandidateRect) {
12235 int dx = 0;
12236 int dy = 0;
12237 if (p.x() < r.left())
12238 dx = r.left() - p.x();
12239 else if (p.x() > r.right())
12240 dx = p.x() - r.right();
12241 if (p.y() < r.top())
12242 dy = r.top() - p.y();
12243 else if (p.y() > r.bottom())
12244 dy = p.y() - r.bottom();
12245 return dx + dy;
12246 }();
12247 if (targetCandidateDistance < shortestDistance) {
12248 shortestDistance = targetCandidateDistance;
12249 targetWidget = targetCandidate;
12250 }
12251 }
12252 }
12253 return targetWidget;
12254}
12255
12267bool QWidgetPrivate::canKeypadNavigate(Qt::Orientation orientation)
12268{
12269 return orientation == Qt::Horizontal?
12270 (QWidgetPrivate::widgetInNavigationDirection(QWidgetPrivate::DirectionEast)
12271 || QWidgetPrivate::widgetInNavigationDirection(QWidgetPrivate::DirectionWest))
12272 :(QWidgetPrivate::widgetInNavigationDirection(QWidgetPrivate::DirectionNorth)
12273 || QWidgetPrivate::widgetInNavigationDirection(QWidgetPrivate::DirectionSouth));
12274}
12287bool QWidgetPrivate::inTabWidget(QWidget *widget)
12288{
12289 for (QWidget *tabWidget = widget; tabWidget; tabWidget = tabWidget->parentWidget())
12290 if (qobject_cast<const QTabWidget*>(tabWidget))
12291 return true;
12292 return false;
12293}
12294#endif
12295
12303void QWidget::setBackingStore(QBackingStore *store)
12304{
12305 // ### createWinId() ??
12306
12307 if (!isWindow())
12308 return;
12309
12310 Q_D(QWidget);
12311
12312 QTLWExtra *topData = d->topData();
12313 if (topData->backingStore == store)
12314 return;
12315
12316 QBackingStore *oldStore = topData->backingStore;
12317 delete topData->backingStore;
12318 topData->backingStore = store;
12319
12320 QWidgetRepaintManager *repaintManager = d->maybeRepaintManager();
12321 if (!repaintManager)
12322 return;
12323
12324 if (isWindow()) {
12325 if (repaintManager->backingStore() != oldStore && repaintManager->backingStore() != store)
12326 delete repaintManager->backingStore();
12327 repaintManager->setBackingStore(store);
12328 }
12329}
12330
12337{
12338 Q_D(const QWidget);
12339 QTLWExtra *extra = d->maybeTopData();
12340 if (extra && extra->backingStore)
12341 return extra->backingStore;
12342
12343 if (!isWindow())
12344 return window()->backingStore();
12345
12346 return nullptr;
12347}
12348
12350{
12351 if (left)
12352 *left = (int)leftLayoutItemMargin;
12353 if (top)
12354 *top = (int)topLayoutItemMargin;
12355 if (right)
12357 if (bottom)
12359}
12360
12362{
12367 return;
12368
12369 Q_Q(QWidget);
12370 leftLayoutItemMargin = (signed char)left;
12371 topLayoutItemMargin = (signed char)top;
12372 rightLayoutItemMargin = (signed char)right;
12373 bottomLayoutItemMargin = (signed char)bottom;
12374 q->updateGeometry();
12375}
12376
12378{
12379 Q_Q(QWidget);
12380 QStyleOption myOpt;
12381 if (!opt) {
12382 myOpt.initFrom(q);
12383 myOpt.rect.setRect(0, 0, 32768, 32768); // arbitrary
12384 opt = &myOpt;
12385 }
12386
12387 QRect liRect = q->style()->subElementRect(element, opt, q);
12388 if (liRect.isValid()) {
12389 leftLayoutItemMargin = (signed char)(opt->rect.left() - liRect.left());
12390 topLayoutItemMargin = (signed char)(opt->rect.top() - liRect.top());
12391 rightLayoutItemMargin = (signed char)(liRect.right() - opt->rect.right());
12392 bottomLayoutItemMargin = (signed char)(liRect.bottom() - opt->rect.bottom());
12393 } else {
12398 }
12399}
12400// resets the Qt::WA_QuitOnClose attribute to the default value for transient widgets.
12402{
12403 Q_Q(QWidget);
12404
12405 if (!q->parentWidget()) {
12406 Qt::WindowType type = q->windowType();
12407 if (type == Qt::Widget || type == Qt::SubWindow)
12408 type = Qt::Window;
12409 if (type != Qt::Widget && type != Qt::Window && type != Qt::Dialog)
12410 q->setAttribute(Qt::WA_QuitOnClose, false);
12411 }
12412}
12413
12415{
12417 if (!wd->textureChildSeen)
12418 return;
12419 if (end)
12420 wd->endCompose();
12421 else
12422 wd->beginCompose();
12423 for (int i = 0; i < wd->children.size(); ++i) {
12425 if (w && !w->isWindow() && !w->isHidden() && QWidgetPrivate::get(w)->textureChildSeen)
12427 }
12428}
12429
12431{
12432 return widget->data;
12433}
12434
12436{
12437 return widget->d_func();
12438}
12439
12440
12441#if QT_CONFIG(graphicsview)
12451QGraphicsProxyWidget *QWidget::graphicsProxyWidget() const
12452{
12453 Q_D(const QWidget);
12454 if (d->extra) {
12455 return d->extra->proxyWidget;
12456 }
12457 return nullptr;
12458}
12459#endif
12460
12461#ifndef QT_NO_GESTURES
12468void QWidget::grabGesture(Qt::GestureType gesture, Qt::GestureFlags flags)
12469{
12470 Q_D(QWidget);
12471 d->gestureContext.insert(gesture, flags);
12472 (void)QGestureManager::instance(); // create a gesture manager
12473}
12474
12482{
12483 // if you modify this function, check the inlined version in ~QWidget, too
12484 Q_D(QWidget);
12485 if (d->gestureContext.remove(gesture)) {
12487 manager->cleanupCachedGestures(this, gesture);
12488 }
12489}
12490#endif // QT_NO_GESTURES
12491
12505void QWidget::destroy(bool destroyWindow, bool destroySubWindows)
12506{
12507 Q_D(QWidget);
12508
12509 d->aboutToDestroy();
12510 if (!isWindow() && parentWidget())
12511 parentWidget()->d_func()->invalidateBackingStore(d->effectiveRectFor(geometry()));
12512 d->deactivateWidgetCleanup();
12513
12514 if ((windowType() == Qt::Popup) && qApp)
12515 qApp->d_func()->closePopup(this);
12516
12517 if (this == qApp->activeWindow())
12519 if (QWidget::mouseGrabber() == this)
12520 releaseMouse();
12521 if (QWidget::keyboardGrabber() == this)
12523
12525
12526 if (windowType() != Qt::Desktop) {
12527 if (destroySubWindows) {
12528 QObjectList childList(children());
12529 for (int i = 0; i < childList.size(); i++) {
12530 QWidget *widget = qobject_cast<QWidget *>(childList.at(i));
12532 if (widget->windowHandle()) {
12533 widget->destroy();
12534 }
12535 }
12536 }
12537 }
12538 if (destroyWindow) {
12539 d->deleteTLSysExtra();
12540 } else {
12542 d->hide_sys();
12543 }
12544 }
12545
12546 d->setWinId(0);
12547 }
12548}
12549
12561{
12562 qWarning("QWidget::paintEngine: Should no longer be called");
12563
12564#ifdef Q_OS_WIN
12565 // We set this bit which is checked in setAttribute for
12566 // Qt::WA_PaintOnScreen. We do this to allow these two scenarios:
12567 //
12568 // 1. Users accidentally set Qt::WA_PaintOnScreen on X and port to
12569 // Windows which would mean suddenly their widgets stop working.
12570 //
12571 // 2. Users set paint on screen and subclass paintEngine() to
12572 // return 0, in which case we have a "hole" in the backingstore
12573 // allowing use of GDI or DirectX directly.
12574 //
12575 // 1 is WRONG, but to minimize silent failures, we have set this
12576 // bit to ignore the setAttribute call. 2. needs to be
12577 // supported because its our only means of embedding native
12578 // graphics stuff.
12579 const_cast<QWidgetPrivate *>(d_func())->noPaintOnScreen = 1;
12580#endif
12581
12582 return nullptr; //##### @@@
12583}
12584
12585// Do not call QWindow::mapToGlobal() until QPlatformWindow is properly showing.
12586static inline bool canMapPosition(QWindow *window)
12587{
12588 return window->handle() && !qt_window_private(window)->resizeEventPending;
12589}
12590
12591#if QT_CONFIG(graphicsview)
12592static inline QGraphicsProxyWidget *graphicsProxyWidget(const QWidget *w)
12593{
12594 QGraphicsProxyWidget *result = nullptr;
12595 const QWidgetPrivate *d = qt_widget_private(const_cast<QWidget *>(w));
12596 if (d->extra)
12597 result = d->extra->proxyWidget;
12598 return result;
12599}
12600#endif // QT_CONFIG(graphicsview)
12601
12606
12608{
12610 result.window = nullptr;
12611 for ( ; w ; w = w->parentWidget()) {
12612#if QT_CONFIG(graphicsview)
12613 if (QGraphicsProxyWidget *qgpw = graphicsProxyWidget(w)) {
12614 if (const QGraphicsScene *scene = qgpw->scene()) {
12615 const QList <QGraphicsView *> views = scene->views();
12616 if (!views.isEmpty()) {
12617 result.transform *= qgpw->sceneTransform();
12618 result.transform *= views.first()->viewportTransform();
12619 w = views.first()->viewport();
12620 }
12621 }
12622 }
12623#endif // QT_CONFIG(graphicsview)
12624 QWindow *window = w->windowHandle();
12625 if (window && canMapPosition(window)) {
12626 result.window = window;
12627 break;
12628 }
12629
12630 const QPoint topLeft = w->geometry().topLeft();
12631 result.transform.translate(topLeft.x(), topLeft.y());
12632 if (w->isWindow())
12633 break;
12634 }
12635 return result;
12636}
12637
12649{
12651 const QPointF g = t.transform.map(pos);
12652 return t.window ? t.window->mapToGlobal(g) : g;
12653}
12654
12659{
12660 return mapToGlobal(QPointF(pos)).toPoint();
12661}
12662
12673{
12675 const QPointF windowLocal = t.window ? t.window->mapFromGlobal(pos) : pos;
12676 return t.transform.inverted().map(windowLocal);
12677}
12678
12683{
12684 return mapFromGlobal(QPointF(pos)).toPoint();
12685}
12686
12689static bool mouseGrabWithCursor = false;
12690static QWidget *keyboardGrb = nullptr;
12691
12692static inline QWindow *grabberWindow(const QWidget *w)
12693{
12694 QWindow *window = w->windowHandle();
12695 if (!window)
12696 if (const QWidget *nativeParent = w->nativeParentWidget())
12697 window = nativeParent->windowHandle();
12698 return window;
12699}
12700
12701#ifndef QT_NO_CURSOR
12702static void grabMouseForWidget(QWidget *widget, const QCursor *cursor = nullptr)
12703#else
12704static void grabMouseForWidget(QWidget *widget)
12705#endif
12706{
12707 if (qt_mouseGrb)
12709
12710 mouseGrabWithCursor = false;
12712#ifndef QT_NO_CURSOR
12713 if (cursor) {
12714 mouseGrabWithCursor = true;
12716 }
12717#endif // !QT_NO_CURSOR
12718 window->setMouseGrabEnabled(true);
12719 }
12720
12722 qt_pressGrab = nullptr;
12723}
12724
12726{
12727 if (qt_mouseGrb == widget) {
12729#ifndef QT_NO_CURSOR
12730 if (mouseGrabWithCursor) {
12732 mouseGrabWithCursor = false;
12733 }
12734#endif // !QT_NO_CURSOR
12735 window->setMouseGrabEnabled(false);
12736 }
12737 }
12738 qt_mouseGrb = nullptr;
12739}
12740
12770{
12771 grabMouseForWidget(this);
12772}
12773
12790#ifndef QT_NO_CURSOR
12792{
12793 grabMouseForWidget(this, &cursor);
12794}
12795#endif
12796
12798{
12799 // This is like a combination of grab/releaseMouse() but with error checking
12800 // and it has no effect on the result of mouseGrabber().
12801 Q_Q(QWidget);
12803 return window ? window->setMouseGrabEnabled(grab) : false;
12804}
12805
12814{
12816}
12817
12838{
12839 if (keyboardGrb)
12840 keyboardGrb->releaseKeyboard();
12841 if (QWindow *window = grabberWindow(this))
12842 window->setKeyboardGrabEnabled(true);
12843 keyboardGrb = this;
12844}
12845
12847{
12848 // This is like a combination of grab/releaseKeyboard() but with error
12849 // checking and it has no effect on the result of keyboardGrabber().
12850 Q_Q(QWidget);
12852 return window ? window->setKeyboardGrabEnabled(grab) : false;
12853}
12854
12863{
12864 if (keyboardGrb == this) {
12865 if (QWindow *window = grabberWindow(this))
12866 window->setKeyboardGrabEnabled(false);
12867 keyboardGrb = nullptr;
12868 }
12869}
12870
12882{
12883 if (qt_mouseGrb)
12884 return qt_mouseGrb;
12885 return qt_pressGrab;
12886}
12887
12899{
12900 return keyboardGrb;
12901}
12902
12928{
12929 QWindow *const wnd = window()->windowHandle();
12930
12931 if (wnd)
12932 wnd->requestActivate();
12933}
12934
12943{
12944 QScreen *screen = this->screen();
12945
12946 if (!screen) {
12947 if (m == PdmDpiX || m == PdmDpiY)
12948 return 72;
12949 return QPaintDevice::metric(m);
12950 }
12951
12952 auto resolveDevicePixelRatio = [this, screen]() -> qreal {
12953
12954 // Note: keep in sync with QBackingStorePrivate::backingStoreDevicePixelRatio()!
12955 static bool downscale = qEnvironmentVariableIntValue("QT_WIDGETS_HIGHDPI_DOWNSCALE") > 0;
12956 QWindow *window = this->window()->windowHandle();
12957 if (window)
12958 return downscale ? std::ceil(window->devicePixelRatio()) : window->devicePixelRatio();
12959 return screen->devicePixelRatio();
12960 };
12961
12962 switch (m) {
12963 case PdmWidth:
12964 return data->crect.width();
12965 case PdmWidthMM:
12966 return data->crect.width() * screen->physicalSize().width() / screen->geometry().width();
12967 case PdmHeight:
12968 return data->crect.height();
12969 case PdmHeightMM:
12970 return data->crect.height() * screen->physicalSize().height() / screen->geometry().height();
12971 case PdmDepth:
12972 return screen->depth();
12973 case PdmDpiX:
12974 for (const QWidget *p = this; p; p = p->parentWidget()) {
12975 if (p->d_func()->extra && p->d_func()->extra->customDpiX)
12976 return p->d_func()->extra->customDpiX;
12977 }
12979 case PdmDpiY:
12980 for (const QWidget *p = this; p; p = p->parentWidget()) {
12981 if (p->d_func()->extra && p->d_func()->extra->customDpiY)
12982 return p->d_func()->extra->customDpiY;
12983 }
12985 case PdmPhysicalDpiX:
12987 case PdmPhysicalDpiY:
12990 return resolveDevicePixelRatio();
12992 return QPaintDevice::devicePixelRatioFScale() * resolveDevicePixelRatio();
12994 Q_FALLTHROUGH();
12996 return QPaintDevice::encodeMetricF(m, resolveDevicePixelRatio());
12997 default:
12998 break;
12999 }
13000 return QPaintDevice::metric(m);
13001}
13002
13009{
13010 const QPalette &pal = palette();
13011 painter->d_func()->state->pen = QPen(pal.brush(foregroundRole()), 1);
13012 painter->d_func()->state->bgBrush = pal.brush(backgroundRole());
13013 QFont f(font(), const_cast<QWidget *>(this));
13014 painter->d_func()->state->deviceFont = f;
13015 painter->d_func()->state->font = f;
13016}
13017
13024{
13025 return d_func()->redirected(offset);
13026}
13027
13034{
13035 // Someone sent a paint event directly to the widget
13036 if (!d_func()->redirectDev)
13037 return nullptr;
13038
13039 QPainter *sp = d_func()->sharedPainter();
13040 if (!sp || !sp->isActive())
13041 return nullptr;
13042
13043 if (sp->paintEngine()->paintDevice() != d_func()->redirectDev)
13044 return nullptr;
13045
13046 return sp;
13047}
13048
13071void QWidget::setMask(const QRegion &newMask)
13072{
13073 Q_D(QWidget);
13074
13075 d->createExtra();
13076 if (newMask == d->extra->mask)
13077 return;
13078
13079#ifndef QT_NO_BACKINGSTORE
13080 const QRegion oldMask(d->extra->mask);
13081#endif
13082
13083 d->extra->mask = newMask;
13084 d->extra->hasMask = !newMask.isEmpty();
13085
13087 return;
13088
13089 d->setMask_sys(newMask);
13090
13091#ifndef QT_NO_BACKINGSTORE
13092 if (!isVisible())
13093 return;
13094
13095 if (!d->extra->hasMask) {
13096 // Mask was cleared; update newly exposed area.
13097 QRegion expose(rect());
13098 expose -= oldMask;
13099 if (!expose.isEmpty()) {
13100 d->setDirtyOpaqueRegion();
13101 update(expose);
13102 }
13103 return;
13104 }
13105
13106 if (!isWindow()) {
13107 // Update newly exposed area on the parent widget.
13108 QRegion parentExpose(rect());
13109 parentExpose -= newMask;
13110 if (!parentExpose.isEmpty()) {
13111 d->setDirtyOpaqueRegion();
13112 parentExpose.translate(data->crect.topLeft());
13113 parentWidget()->update(parentExpose);
13114 }
13115
13116 // Update newly exposed area on this widget
13117 if (!oldMask.isEmpty())
13118 update(newMask - oldMask);
13119 }
13120#endif
13121}
13122
13124{
13125 Q_Q(QWidget);
13126 if (QWindow *window = q->windowHandle())
13127 window->setMask(region);
13128}
13129
13156{
13158}
13159
13168{
13169 Q_D(QWidget);
13170 if (!d->extra || !d->extra->hasMask)
13171 return;
13172 setMask(QRegion());
13173}
13174
13176{
13177 Q_ASSERT(widgetAsObject->isWidgetType());
13178 Q_ASSERT(!newParent || newParent->isWidgetType());
13179 QWidget *widget = static_cast<QWidget*>(widgetAsObject);
13180 widget->setParent(static_cast<QWidget*>(newParent));
13181}
13182
13184{
13185 Q_Q(const QWidget);
13186 std::string flags = QObjectPrivate::flagsForDumping();
13188 flags += 'F';
13189 if (q->isVisible()) {
13190 std::stringstream s;
13191 s << '<'
13192 << q->width() << 'x' << q->height()
13193 << std::showpos << q->x() << q->y()
13194 << '>';
13195 flags += s.str();
13196 } else {
13197 flags += 'I';
13198 }
13199 return flags;
13200}
13201
13203{
13204#if QT_CONFIG(xcb)
13205 Q_Q(QWidget);
13206
13207 if (!q->windowHandle())
13208 return;
13209
13210 QXcbWindow::WindowTypes wmWindowType = QXcbWindow::None;
13211 if (q->testAttribute(Qt::WA_X11NetWmWindowTypeDesktop))
13212 wmWindowType |= QXcbWindow::Desktop;
13213 if (q->testAttribute(Qt::WA_X11NetWmWindowTypeDock))
13214 wmWindowType |= QXcbWindow::Dock;
13215 if (q->testAttribute(Qt::WA_X11NetWmWindowTypeToolBar))
13216 wmWindowType |= QXcbWindow::Toolbar;
13217 if (q->testAttribute(Qt::WA_X11NetWmWindowTypeMenu))
13218 wmWindowType |= QXcbWindow::Menu;
13219 if (q->testAttribute(Qt::WA_X11NetWmWindowTypeUtility))
13220 wmWindowType |= QXcbWindow::Utility;
13221 if (q->testAttribute(Qt::WA_X11NetWmWindowTypeSplash))
13222 wmWindowType |= QXcbWindow::Splash;
13223 if (q->testAttribute(Qt::WA_X11NetWmWindowTypeDialog))
13224 wmWindowType |= QXcbWindow::Dialog;
13225 if (q->testAttribute(Qt::WA_X11NetWmWindowTypeDropDownMenu))
13226 wmWindowType |= QXcbWindow::DropDownMenu;
13227 if (q->testAttribute(Qt::WA_X11NetWmWindowTypePopupMenu))
13228 wmWindowType |= QXcbWindow::PopupMenu;
13229 if (q->testAttribute(Qt::WA_X11NetWmWindowTypeToolTip))
13230 wmWindowType |= QXcbWindow::Tooltip;
13231 if (q->testAttribute(Qt::WA_X11NetWmWindowTypeNotification))
13232 wmWindowType |= QXcbWindow::Notification;
13233 if (q->testAttribute(Qt::WA_X11NetWmWindowTypeCombo))
13234 wmWindowType |= QXcbWindow::Combo;
13235 if (q->testAttribute(Qt::WA_X11NetWmWindowTypeDND))
13236 wmWindowType |= QXcbWindow::Dnd;
13237
13238 if (wmWindowType == QXcbWindow::None && skipIfMissing)
13239 return;
13240
13241 if (auto *xcbWindow = dynamic_cast<QXcbWindow*>(q->windowHandle()->handle()))
13242 xcbWindow->setWindowType(wmWindowType);
13243#else
13244 Q_UNUSED(skipIfMissing);
13245#endif
13246}
13247
13254{
13255 Q_Q(const QWidget);
13256 const QWidgetList &children = q->findChildren<QWidget *>(Qt::FindChildrenRecursively);
13257 for (const auto *child : children) {
13258 if (child->focusPolicy() == policy && child->isEnabled()
13259 && (!excludeChildrenOf || !excludeChildrenOf->isAncestorOf(child))) {
13260 return true;
13261 }
13262 }
13263 return false;
13264}
13265
13266#ifndef QT_NO_DEBUG_STREAM
13267
13268namespace {
13269QDebug operator<<(QDebug debug, const WidgetAttributes &attributes)
13270{
13271 const QDebugStateSaver saver(debug);
13272 debug.nospace();
13273 debug << '[';
13274 if (const QWidget *widget = attributes.widget) {
13275 const QMetaObject *qtMo = qt_getEnumMetaObject(Qt::WA_AttributeCount);
13276 const QMetaEnum me = qtMo->enumerator(qtMo->indexOfEnumerator("WidgetAttribute"));
13277 int count = 0;
13278 for (int a = 0; a < Qt::WA_AttributeCount; ++a) {
13279 if (widget->testAttribute(static_cast<Qt::WidgetAttribute>(a))) {
13280 if (count++)
13281 debug << ',';
13282 debug << me.valueToKey(a);
13283 }
13284 }
13285 }
13286 debug << ']';
13287 return debug;
13288}
13289}
13290
13292{
13293 const QDebugStateSaver saver(debug);
13294 debug.nospace();
13295 if (widget) {
13296 debug << widget->metaObject()->className() << '(' << (const void *)widget;
13297 if (!widget->objectName().isEmpty())
13298 debug << ", name=" << widget->objectName();
13299 if (debug.verbosity() > 2) {
13300 const QRect geometry = widget->geometry();
13302 if (widget->isVisible())
13303 debug << ", visible";
13304 if (!widget->isEnabled())
13305 debug << ", disabled";
13306 debug << ", states=" << widget->windowState()
13307 << ", type=" << widget->windowType() << ", flags=" << widget->windowFlags();
13308 debug << ", attributes=" << WidgetAttributes{widget};
13309 if (widget->isWindow())
13310 debug << ", window";
13311 debug << ", " << geometry.width() << 'x' << geometry.height()
13312 << Qt::forcesign << geometry.x() << geometry.y() << Qt::noforcesign;
13313 if (frameGeometry != geometry) {
13314 const QMargins margins(geometry.x() - frameGeometry.x(),
13315 geometry.y() - frameGeometry.y(),
13316 frameGeometry.right() - geometry.right(),
13317 frameGeometry.bottom() - geometry.bottom());
13318 debug << ", margins=" << margins;
13319 }
13320 debug << ", devicePixelRatio=" << widget->devicePixelRatio();
13321 if (const WId wid = widget->internalWinId())
13322 debug << ", winId=0x" << Qt::hex << wid << Qt::dec;
13323 }
13324 debug << ')';
13325 } else {
13326 debug << "QWidget(0x0)";
13327 }
13328 return debug;
13329}
13330#endif // !QT_NO_DEBUG_STREAM
13331
13332
13333// *************************** Focus abstraction ************************************
13334
13335#define FOCUS_NEXT(w) w->d_func()->focus_next
13336#define FOCUS_PREV(w) w->d_func()->focus_prev
13337
13348
13361{
13362 Q_Q(QWidget);
13363 if (!isFocusChainConsistent()) {
13364#ifdef QT_DEBUG
13365 if (rules.testFlag(FocusChainRemovalRule::AssertConsistency))
13366 qFatal() << q << "has inconsistent focus chain.";
13367#endif
13368 qCDebug(lcWidgetFocus) << q << "wasn't removed, because of inconsistent focus chain.";
13369 return false;
13370 }
13371
13372 if (!isInFocusChain()) {
13373 qCDebug(lcWidgetFocus) << q << "wasn't removed, because it is not part of a focus chain.";
13374 return false;
13375 }
13376
13377 if (rules.testFlag(FocusChainRemovalRule::EnsureFocusOut))
13378 q->focusNextPrevChild(direction == FocusDirection::Next);
13379
13383 qCDebug(lcWidgetFocus) << q << "removed from focus chain.";
13384 return true;
13385}
13386
13392{
13393 Q_Q(QWidget);
13394 qCDebug(lcWidgetFocus) << "Initializing focus chain of" << q;
13395 FOCUS_PREV(q) = q;
13396 FOCUS_NEXT(q) = q;
13397}
13398
13407{
13408 Q_Q(QWidget);
13409
13410 // separate the focus chain into new (children of myself) and old (the rest)
13411 QWidget *firstOld = nullptr;
13412 QWidget *lastOld = nullptr; // last in the old list
13413 QWidget *lastNew = q; // last in the new list
13414 bool prevWasNew = true;
13416
13417 // For efficiency, do not maintain the list invariant inside the loop.
13418 // Append items to the relevant list, and we optimize by not changing pointers,
13419 // when subsequent items are going into the same list.
13420 while (widget != q) {
13421 bool currentIsNew = q->isAncestorOf(widget);
13422 if (currentIsNew) {
13423 if (!prevWasNew) {
13424 // previous was old => append to new list
13425 FOCUS_NEXT(lastNew) = widget;
13426 FOCUS_PREV(widget) = lastNew;
13427 }
13428 lastNew = widget;
13429 } else {
13430 if (prevWasNew) {
13431 // prev was new => append to old list, if it exists
13432 if (lastOld) {
13433 FOCUS_NEXT(lastOld) = widget;
13434 FOCUS_PREV(widget) = lastOld;
13435 } else {
13436 // start the old list
13437 firstOld = widget;
13438 }
13439 }
13440 lastOld = widget;
13441 }
13442 widget = widget->d_func()->nextPrevElementInFocusChain(direction);
13443 prevWasNew = currentIsNew;
13444 }
13445
13446 // repair old list:
13447 if (firstOld) {
13448 FOCUS_NEXT(lastOld) = firstOld;
13449 FOCUS_PREV(firstOld) = lastOld;
13450 }
13451
13452 if (!q->isWindow()) {
13453 QWidget *topLevel = q->window();
13454 // insert new chain into toplevel's chain
13455 QWidget *prev = FOCUS_PREV(topLevel);
13456 FOCUS_PREV(topLevel) = lastNew;
13457 FOCUS_NEXT(prev) = q;
13458 FOCUS_PREV(q) = prev;
13459 FOCUS_NEXT(lastNew) = topLevel;
13460 } else {
13461 // repair new list
13462 FOCUS_NEXT(lastNew) = q;
13463 FOCUS_PREV(q) = lastNew;
13464 }
13465}
13466
13474{
13475 Q_Q(QWidget);
13478 QWidget *previous = FOCUS_PREV(q);
13479
13480 switch (direction) {
13482 if (previous == position) {
13483 qCDebug(lcWidgetFocus) << "No-op insertion." << q << "is already before" << position;
13484 return false;
13485 }
13486
13488
13493 qCDebug(lcWidgetFocus) << q << "inserted after" << position;
13494 break;
13495
13497 if (next == position) {
13498 qCDebug(lcWidgetFocus) << "No-op insertion." << q << "is already after" << position;
13499 return false;
13500 }
13501
13503
13508 qCDebug(lcWidgetFocus) << q << "inserted before" << position;
13509 break;
13510 }
13511
13513 return true;
13514}
13515
13526{
13527 if (toBeInserted.isEmpty()) {
13528 qCDebug(lcWidgetFocus) << "No-op insertion of an empty list";
13529 return false;
13530 }
13531
13532 Q_ASSERT_X(!toBeInserted.contains(position),
13534 "Coding error: toBeInserted contains position");
13535
13536 QWidget *first = toBeInserted.constFirst();
13537 QWidget *last = toBeInserted.constLast();
13538
13539 // Call QWidget override to log accordingly
13540 if (toBeInserted.count() == 1)
13541 return first->d_func()->insertIntoFocusChain(direction, position);
13542
13543 Q_ASSERT(first != last);
13544 switch (direction) {
13546 if (FOCUS_PREV(position) == last) {
13547 qCDebug(lcWidgetFocus) << "No-op insertion." << toBeInserted << "is already before"
13548 << position;
13549 return false;
13550 }
13553 FOCUS_NEXT(last) = position;
13554 FOCUS_PREV(position) = last;
13555 qCDebug(lcWidgetFocus) << toBeInserted << "inserted before" << position;
13556 break;
13558 if (FOCUS_PREV(position) == last) {
13559 qCDebug(lcWidgetFocus) << "No-op insertion." << toBeInserted << "is already after"
13560 << position;
13561 return false;
13562 }
13567 qCDebug(lcWidgetFocus) << toBeInserted << "inserted after" << position;
13568 break;
13569 }
13570
13571 Q_ASSERT(position->d_func()->isFocusChainConsistent());
13572 return true;
13573}
13574
13581{
13582 QWidgetList path({from});
13583 if (from == to)
13584 return path;
13585
13586 QWidget *current = from;
13587 do {
13588 switch (direction) {
13590 current = current->previousInFocusChain();
13591 break;
13593 current = current->nextInFocusChain();
13594 break;
13595 }
13596 if (path.contains(current))
13597 return QWidgetList();
13598 path << current;
13599 } while (current != to);
13600
13601 return path;
13602}
13603
13611 QWidget *to,
13613{
13614 // Check if there is a path from->to in direction
13615 const QWidgetList path = focusPath(from, to , direction);
13616 if (path.isEmpty()) {
13617 qCDebug(lcWidgetFocus) << "No-op removal. Focus chain from" << from << "doesn't lead to " << to;
13618 return QWidgetList();
13619 }
13620
13621 QWidget *first = path.constFirst();
13622 QWidget *last = path.constLast();
13623 if (first == last) {
13624 first->d_func()->removeFromFocusChain();
13625 return QWidgetList({first});
13626 }
13627
13630 FOCUS_PREV(first) = last;
13631 FOCUS_NEXT(last) = first;
13632 qCDebug(lcWidgetFocus) << path << "removed from focus chain";
13633 return path;
13634}
13635
13642{
13643 Q_Q(QWidget);
13644 // Since we need to repeat the same logic for both 'first' and 'second', we add a function
13645 // that determines the last focus child for a widget, taking proxies and compound widgets into
13646 // account. If the target is not a compound widget (it doesn't have a focus proxy that points
13647 // to a child), 'lastFocusChild' will be set to the target itself.
13648 QWidget *lastFocusChild = q;
13649
13650 QWidget *focusProxy = deepestFocusProxy();
13651 if (!focusProxy) {
13652 // QTBUG-81097: Another case is possible here. We can have a child
13653 // widget, that sets its focusProxy() to the parent (target).
13654 // An example of such widget is a QLineEdit, nested into
13655 // a QAbstractSpinBox. In this case such widget should be considered
13656 // the last focus child.
13657 for (auto *object : std::as_const(q->children())) {
13659 if (w && w->focusProxy() == q) {
13660 lastFocusChild = w;
13661 break;
13662 }
13663 }
13664 } else if (q->isAncestorOf(focusProxy)) {
13665 lastFocusChild = focusProxy;
13666 for (QWidget *focusNext = lastFocusChild->nextInFocusChain();
13667 focusNext != focusProxy && q->isAncestorOf(focusNext)
13668 && focusNext->window() == focusProxy->window();
13669 focusNext = focusNext->nextInFocusChain()) {
13670 if (focusNext == noFurtherThan)
13671 break;
13672 if (focusNext->focusPolicy() != Qt::NoFocus)
13673 lastFocusChild = focusNext;
13674 }
13675 }
13676 return lastFocusChild;
13677};
13678
13692{
13693 Q_Q(const QWidget);
13694 return !(FOCUS_NEXT(q) == q && FOCUS_PREV(q) == q);
13695}
13696
13720{
13721 Q_Q(const QWidget);
13722 const bool skip = !QLoggingCategory("qt.widgets.focus").isDebugEnabled();
13723 if (skip)
13724 return true;
13725
13726 if (!isInFocusChain())
13727 return true;
13728
13729 const QWidget *position = q;
13730
13731 for (int i = 0; i < QApplication::allWidgets().count(); ++i) {
13733 qCDebug(lcWidgetFocus) << "Nullptr found at:" << position
13734 << "Previous pointing to" << FOCUS_PREV(position)
13735 << "Next pointing to" << FOCUS_NEXT(position);
13736 return false;
13737 }
13740 qCDebug(lcWidgetFocus) << "Inconsistent focus chain at:" << position
13741 << "Previous pointing to" << FOCUS_PREV(FOCUS_NEXT(position))
13742 << "Next pointing to" << FOCUS_NEXT(FOCUS_PREV(position));
13743 return false;
13744 }
13746 if (position == q)
13747 return true;
13748
13749 }
13750
13751 qCDebug(lcWidgetFocus) << "Focus chain leading from" << q << "to" << position << "is not closed.";
13752 return false;
13753}
13754
13755#undef FOCUS_NEXT
13756#undef FOCUS_PREV
13757
13758
13760
13761#include "moc_qwidget.cpp"
13762#include "moc_qwidget_p.cpp"
static bool isEqual(const aiUVTransform &a, const aiUVTransform &b)
IOBluetoothDevice * device
static void(* destroyed)(QAbstractDeclarativeData *, QObject *)
Definition qobject_p.h:66
\inmodule QtGui
The QActionEvent class provides an event that is generated when a QAction is added,...
QObjectList associatedObjects
Definition qaction_p.h:67
The QAction class provides an abstraction for user commands that can be added to different user inter...
Definition qaction.h:30
QList< QObject * > associatedObjects() const
Definition qaction.cpp:505
static QWidget * focus_widget
static QWidget * hidden_focus_widget
static void setFocusWidget(QWidget *focus, Qt::FocusReason reason)
static QWidget * focusNextPrevChild_helper(QWidget *toplevel, bool next, bool *wrappingOccurred=nullptr)
internal Helper function that returns the new focus widget, but does not set the focus reason.
static bool isBlockedByModal(QWidget *widget)
static void setActiveWindow(QWidget *act)
static QStyle * style()
Returns the application's style object.
static QPalette palette()
Returns the current application palette.
static QWidget * activeModalWidget()
Returns the active modal widget.
static QWidget * focusWidget()
Returns the application widget that has the keyboard input focus, or \nullptr if no widget in this ap...
static QFont font()
Returns the default application font.
static QWidget * activePopupWidget()
Returns the active popup widget.
static QWidget * activeWindow()
Returns the application top-level window that has the keyboard input focus, or \nullptr if no applica...
static QWidgetList allWidgets()
Returns a list of all the widgets in the application.
static QSurface::SurfaceType surfaceTypeForConfig(const QPlatformBackingStoreRhiConfig &config)
static bool checkForceRhi(QPlatformBackingStoreRhiConfig *outConfig, QSurface::SurfaceType *outType)
The QBackingStore class provides a drawing area for QWindow.
QPlatformBackingStore * handle() const
Returns a pointer to the QPlatformBackingStore implementation.
\inmodule QtGui
Definition qbitmap.h:16
\inmodule QtGui
Definition qbrush.h:30
bool isOpaque() const
Returns true if the brush is fully opaque otherwise false.
Definition qbrush.cpp:830
QPixmap texture() const
Returns the custom brush pattern, or a null pixmap if no custom brush pattern has been set.
Definition qbrush.cpp:711
Qt::BrushStyle style() const
Returns the brush style.
Definition qbrush.h:120
\inmodule QtCore
Definition qbytearray.h:57
char * data()
\macro QT_NO_CAST_FROM_BYTEARRAY
Definition qbytearray.h:612
qsizetype size() const noexcept
Returns the number of bytes in this byte array.
Definition qbytearray.h:495
const char * constData() const noexcept
Returns a pointer to the const data stored in the byte array.
Definition qbytearray.h:124
char at(qsizetype i) const
Returns the byte at index position i in the byte array.
Definition qbytearray.h:601
\inmodule QtCore
Definition qcoreevent.h:379
The QCloseEvent class contains parameters that describe a close event.
Definition qevent.h:562
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition qcolor.h:31
void setAlphaF(float alpha)
Sets the alpha of this color to alpha.
Definition qcolor.cpp:1511
The QContextMenuEvent class contains parameters that describe a context menu event.
Definition qevent.h:594
const QPoint & globalPos() const
Returns the global position of the mouse pointer at the time of the event.
Definition qevent.h:612
static bool testAttribute(uint flag)
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
static void removePostedEvents(QObject *receiver, int eventType=0)
static void processEvents(QEventLoop::ProcessEventsFlags flags=QEventLoop::AllEvents)
Processes some pending events for the calling thread according to the specified flags.
static QCoreApplication * instance() noexcept
Returns a pointer to the application's QCoreApplication (or QGuiApplication/QApplication) instance.
static bool closingDown()
Returns true if the application objects are being destroyed; otherwise returns false.
static bool testAttribute(Qt::ApplicationAttribute attribute)
Returns true if attribute attribute is set; otherwise returns false.
static void postEvent(QObject *receiver, QEvent *event, int priority=Qt::NormalEventPriority)
The QCursor class provides a mouse cursor with an arbitrary shape.
Definition qcursor.h:45
Qt::CursorShape shape() const
Returns the cursor shape identifier.
Definition qcursor.cpp:498
\inmodule QtCore\reentrant
Definition qdatastream.h:47
\inmodule QtCore
\inmodule QtCore
\inmodule QtGui
Definition qevent.h:165
\inmodule QtCore
Definition qcoreevent.h:45
Type
This enum type defines the valid event types in Qt.
Definition qcoreevent.h:51
@ QueryWhatsThis
Definition qcoreevent.h:169
@ TabletMove
Definition qcoreevent.h:121
@ ApplicationPaletteChange
Definition qcoreevent.h:93
@ ActionRemoved
Definition qcoreevent.h:153
@ ContentsRectChange
Definition qcoreevent.h:219
@ WindowStateChange
Definition qcoreevent.h:143
@ DevicePixelRatioChange
Definition qcoreevent.h:287
@ ParentChange
Definition qcoreevent.h:80
@ FocusAboutToChange
Definition qcoreevent.h:68
@ ScreenChangeInternal
Definition qcoreevent.h:276
@ AcceptDropsChange
Definition qcoreevent.h:185
@ EnabledChange
Definition qcoreevent.h:134
@ ModifiedChange
Definition qcoreevent.h:138
@ PolishRequest
Definition qcoreevent.h:110
@ ActionAdded
Definition qcoreevent.h:152
@ WindowAboutToChangeInternal
Definition qcoreevent.h:285
@ LayoutDirectionChange
Definition qcoreevent.h:124
@ ChildPolished
Definition qcoreevent.h:107
@ ApplicationLayoutDirectionChange
Definition qcoreevent.h:92
@ WindowBlocked
Definition qcoreevent.h:141
@ WindowUnblocked
Definition qcoreevent.h:142
@ ReadOnlyChange
Definition qcoreevent.h:145
@ ApplicationWindowIconChange
Definition qcoreevent.h:90
@ ShortcutOverride
Definition qcoreevent.h:158
@ FocusOut
Definition qcoreevent.h:67
@ InputMethod
Definition qcoreevent.h:120
@ StyleChange
Definition qcoreevent.h:136
@ DragEnter
Definition qcoreevent.h:101
@ CursorChange
Definition qcoreevent.h:228
@ LocaleChange
Definition qcoreevent.h:122
@ InputMethodQuery
Definition qcoreevent.h:261
@ ActionChanged
Definition qcoreevent.h:151
@ LayoutRequest
Definition qcoreevent.h:112
@ FontChange
Definition qcoreevent.h:133
@ KeyRelease
Definition qcoreevent.h:65
@ MouseMove
Definition qcoreevent.h:63
@ ShowWindowRequest
Definition qcoreevent.h:109
@ KeyPress
Definition qcoreevent.h:64
@ ZOrderChange
Definition qcoreevent.h:173
@ StyleAnimationUpdate
Definition qcoreevent.h:272
@ FocusIn
Definition qcoreevent.h:66
@ ToolBarChange
Definition qcoreevent.h:162
@ TouchCancel
Definition qcoreevent.h:264
@ ActivationChange
Definition qcoreevent.h:135
@ ThemeChange
Definition qcoreevent.h:266
@ MouseButtonPress
Definition qcoreevent.h:60
@ TouchUpdate
Definition qcoreevent.h:242
@ TouchBegin
Definition qcoreevent.h:241
@ HoverLeave
Definition qcoreevent.h:176
@ ToolTipChange
Definition qcoreevent.h:229
@ HoverEnter
Definition qcoreevent.h:175
@ ParentAboutToChange
Definition qcoreevent.h:81
@ WindowActivate
Definition qcoreevent.h:83
@ LanguageChange
Definition qcoreevent.h:123
@ TabletRelease
Definition qcoreevent.h:127
@ DynamicPropertyChange
Definition qcoreevent.h:207
@ WindowIconChange
Definition qcoreevent.h:89
@ HideToParent
Definition qcoreevent.h:86
@ IconTextChange
Definition qcoreevent.h:137
@ UpdateRequest
Definition qcoreevent.h:113
@ DragLeave
Definition qcoreevent.h:103
@ UpdateLater
Definition qcoreevent.h:114
@ EmbeddingControl
Definition qcoreevent.h:116
@ PlatformSurface
Definition qcoreevent.h:278
@ PaletteChange
Definition qcoreevent.h:94
@ TabletPress
Definition qcoreevent.h:126
@ MouseButtonDblClick
Definition qcoreevent.h:62
@ Destroy
Definition qcoreevent.h:75
@ MacSizeChange
Definition qcoreevent.h:217
@ ApplicationFontChange
Definition qcoreevent.h:91
@ TabletTrackingChange
Definition qcoreevent.h:282
@ WindowTitleChange
Definition qcoreevent.h:88
@ WhatsThis
Definition qcoreevent.h:148
@ WinIdChange
Definition qcoreevent.h:251
@ ShowToParent
Definition qcoreevent.h:85
@ KeyboardLayoutChange
Definition qcoreevent.h:205
@ WindowDeactivate
Definition qcoreevent.h:84
@ ContextMenu
Definition qcoreevent.h:119
@ MouseButtonRelease
Definition qcoreevent.h:61
@ MouseTrackingChange
Definition qcoreevent.h:139
@ WindowChangeInternal
Definition qcoreevent.h:275
@ ChildAdded
Definition qcoreevent.h:106
bool isAccepted() const
Definition qcoreevent.h:308
void accept()
Sets the accept flag of the event object, the equivalent of calling setAccepted(true).
Definition qcoreevent.h:310
QString fileName() const
The QFocusEvent class contains event parameters for widget focus events.
Definition qevent.h:470
\reentrant
Definition qfont.h:22
QFont resolve(const QFont &) const
Returns a new QFont that has attributes copied from other that have not been previously set on this f...
Definition qfont.cpp:1910
void setResolveMask(uint mask)
Definition qfont.h:314
uint resolveMask() const
Definition qfont.h:313
static QGestureManager * instance(InstanceCreation ic=ForceCreation)
@ ObjectBoundingMode
Definition qbrush.h:156
@ ObjectMode
Definition qbrush.h:157
The QGraphicsEffectSource class represents the source on which a QGraphicsEffect is installed on.
The QGraphicsEffect class is the base class for all graphics effects.
PixmapPadMode
This enum describes how the pixmap returned from sourcePixmap should be padded.
QGraphicsEffectSource * source() const
virtual void draw(QPainter *painter)=0
This pure virtual function draws the effect and is called whenever the source needs to be drawn.
bool isEnabled() const
The QGraphicsProxyWidget class provides a proxy layer for embedding a QWidget in a QGraphicsScene.
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items.
QList< QGraphicsView * > views() const
Returns a list of all the views that display this scene.
void update(qreal x, qreal y, qreal w, qreal h)
This is an overloaded member function, provided for convenience. It differs from the above function o...
QPalette palette
the widget's palette
QFont font
the widgets' font
static void showModalWindow(QWindow *window)
static void hideModalWindow(QWindow *window)
static QPlatformIntegration * platformIntegration()
static QGuiApplicationPrivate * instance()
static Qt::ApplicationState applicationState()
QScreen * primaryScreen
the primary (or default) screen of the application.
static QPalette palette()
Returns the current application palette.
static QObject * focusObject()
Returns the QObject in currently active window that will be final receiver of events tied to focus,...
static QWindow * focusWindow()
Returns the QWindow that receives events tied to focus, such as key events.
static QInputMethod * inputMethod()
returns the input method.
static void setOverrideCursor(const QCursor &)
Sets the application override cursor to cursor.
static void restoreOverrideCursor()
Undoes the last setOverrideCursor().
static bool desktopSettingsAware()
Returns true if Qt is set to use the system's standard colors, fonts, etc.; otherwise returns false.
Qt::LayoutDirection layoutDirection
the default layout direction for this application
static QScreen * screenAt(const QPoint &point)
Returns the screen at point, or \nullptr if outside of any screen.
static QList< QScreen * > screens()
Returns a list of all the screens associated with the windowing system the application is connected t...
QIcon windowIcon
the default window icon
The QHelpEvent class provides an event that is used to request helpful information about a particular...
Definition qevent.h:788
const QPoint & globalPos() const
Returns the mouse cursor position when the event was generated in global coordinates.
Definition qevent.h:799
The QHideEvent class provides an event which is sent after a widget is hidden.
Definition qevent.h:586
The QIcon class provides scalable icons in different modes and states.
Definition qicon.h:20
bool isNull() const
Returns true if the icon is empty; otherwise returns false.
Definition qicon.cpp:1042
\inmodule QtGui
Definition qimage.h:37
@ Format_RGB32
Definition qimage.h:46
@ Format_ARGB32_Premultiplied
Definition qimage.h:48
The QInputMethodEvent class provides parameters for input method events.
Definition qevent.h:625
The QInputMethodQueryEvent class provides an event sent by the input context to input objects.
Definition qevent.h:679
Qt::InputMethodQueries queries() const
Returns the properties queried by the event.
Definition qevent.h:684
The QKeyEvent class describes a key event.
Definition qevent.h:424
Qt::KeyboardModifiers modifiers() const
Returns the keyboard modifier flags that existed immediately after the event occurred.
Definition qevent.cpp:1468
int key() const
Returns the code of the key that was pressed or released.
Definition qevent.h:434
The QKeySequence class encapsulates a key sequence as used by shortcuts.
virtual QRect geometry() const =0
Returns the rectangle covered by this layout item.
virtual bool hasHeightForWidth() const
Returns true if this layout's preferred height depends on its width; otherwise returns false.
virtual QLayout * layout()
If this item is a QLayout, it is returned as a QLayout; otherwise \nullptr is returned.
The QLayout class is the base class of geometry managers.
Definition qlayout.h:26
QRect geometry() const override
\reimp
Definition qlayout.cpp:460
int totalHeightForWidth(int w) const
Definition qlayout.cpp:599
void update()
Updates the layout for parentWidget().
Definition qlayout.cpp:971
bool activate()
Redoes the layout for parentWidget() if necessary.
Definition qlayout.cpp:995
Qt::Orientations expandingDirections() const override
Returns whether this layout can make use of more space than sizeHint().
Definition qlayout.cpp:944
void invalidate() override
\reimp
Definition qlayout.cpp:469
QWidget * parentWidget() const
Returns the parent widget of this layout, or \nullptr if this layout is not installed on any widget.
Definition qlayout.cpp:399
QLayout * layout() override
\reimp
virtual int indexOf(const QWidget *) const
Searches for widget widget in this layout (not including child layouts).
Definition qlayout.cpp:1177
qsizetype size() const noexcept
Definition qlist.h:398
bool isEmpty() const noexcept
Definition qlist.h:402
const_reference at(qsizetype i) const noexcept
Definition qlist.h:447
qsizetype removeAll(const AT &t)
Definition qlist.h:593
void append(parameter_type t)
Definition qlist.h:459
\inmodule QtCore
bool isDebugEnabled() const
Returns true if debug messages should be shown for this category; false otherwise.
\inmodule QtCore
Definition qmargins.h:24
constexpr int bottom() const noexcept
Returns the bottom margin.
Definition qmargins.h:115
constexpr bool isNull() const noexcept
Returns true if all margins are is 0; otherwise returns false.
Definition qmargins.h:103
constexpr int left() const noexcept
Returns the left margin.
Definition qmargins.h:106
constexpr int right() const noexcept
Returns the right margin.
Definition qmargins.h:112
constexpr int top() const noexcept
Returns the top margin.
Definition qmargins.h:109
QAction * exec()
Executes this menu synchronously.
Definition qmenu.cpp:2613
\inmodule QtCore
const char * valueToKey(int value) const
Returns the string that is used as the name of the given enumeration value, or \nullptr if value is n...
\inmodule QtGui
Definition qevent.h:196
The QMoveEvent class contains event parameters for move events.
Definition qevent.h:502
uint isWindow
Definition qobject.h:82
uint isWidget
Definition qobject.h:76
QObjectList children
Definition qobject.h:74
uint wasWidget
Definition qobject.h:86
uint willBeWidget
Definition qobject.h:85
QObject * parent
Definition qobject.h:73
void setParent_helper(QObject *)
Definition qobject.cpp:2219
virtual std::string flagsForDumping() const
Definition qobject.cpp:4364
\inmodule QtCore
Definition qobject.h:103
const QObjectList & children() const
Returns a list of child objects.
Definition qobject.h:201
QObject * parent() const
Returns a pointer to the parent object.
Definition qobject.h:346
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2960
QString objectName
the name of this object
Definition qobject.h:107
virtual bool event(QEvent *event)
This virtual function receives events to an object and should return true if the event e was recogniz...
Definition qobject.cpp:1389
void setParent(QObject *parent)
Makes the object a child of parent.
Definition qobject.cpp:2195
friend class QWidget
Definition qobject.h:382
QList< QByteArray > dynamicPropertyNames() const
Definition qobject.cpp:4352
bool setProperty(const char *name, const QVariant &value)
Sets the value of the object's name property to value.
bool inherits(const char *classname) const
Returns true if this object is an instance of a class that inherits className or a QObject subclass t...
Definition qobject.h:348
void destroyed(QObject *=nullptr)
This signal is emitted immediately before the object obj is destroyed, after any instances of QPointe...
bool isWidgetType() const
Returns true if the object is a widget; otherwise returns false.
Definition qobject.h:131
bool paintingActive() const
qreal devicePixelRatio() const
@ PdmDevicePixelRatioF_EncodedB
@ PdmDevicePixelRatioF_EncodedA
@ PdmDevicePixelRatioScaled
int logicalDpiY() const
virtual QPaintDevice * redirected(QPoint *offset) const
static int encodeMetricF(PaintDeviceMetric metric, double value)
int width() const
virtual int metric(PaintDeviceMetric metric) const
virtual QPaintEngine * paintEngine() const =0
int height() const
static qreal devicePixelRatioFScale()
void setSystemViewport(const QRegion &region)
QTransform systemTransform
virtual void systemStateChanged()
void setSystemTransformAndViewport(const QTransform &xform, const QRegion &region)
\inmodule QtGui
QRect systemRect() const
The QPaintEvent class contains event parameters for paint events.
Definition qevent.h:486
The QPainter class performs low-level painting on widgets and other paint devices.
Definition qpainter.h:46
CompositionMode compositionMode() const
Returns the current composition mode.
const QPen & pen() const
Returns the painter's current pen.
Qt::LayoutDirection layoutDirection() const
Returns the layout direction used by the painter when drawing text.
RenderHints renderHints() const
Returns a flag that specifies the rendering hints that are set for this painter.
QPaintDevice * device() const
Returns the paint device on which this painter is currently painting, or \nullptr if the painter is n...
qreal opacity() const
QPaintEngine * paintEngine() const
Returns the paint engine that the painter is currently operating on if the painter is active; otherwi...
void setBrushOrigin(int x, int y)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qpainter.h:700
const QFont & font() const
Returns the currently set font used for drawing text.
void setLayoutDirection(Qt::LayoutDirection direction)
Sets the layout direction used by the painter when drawing text, to the specified direction.
void drawTiledPixmap(const QRectF &rect, const QPixmap &pm, const QPointF &offset=QPointF())
Draws a tiled pixmap, inside the given rectangle with its origin at the given position.
void restore()
Restores the current painter state (pops a saved state off the stack).
const QTransform & worldTransform() const
Returns the world transformation matrix.
void setCompositionMode(CompositionMode mode)
Sets the composition mode to the given mode.
void save()
Saves the current painter state (pushes the state onto a stack).
QRegion clipRegion() const
Returns the currently set clip region.
const QTransform & deviceTransform() const
Returns the matrix that transforms from logical coordinates to device coordinates of the platform dep...
void drawPixmap(const QRectF &targetRect, const QPixmap &pixmap, const QRectF &sourceRect)
Draws the rectangular portion source of the given pixmap into the given target in the paint device.
@ SmoothPixmapTransform
Definition qpainter.h:54
CompositionMode
Defines the modes supported for digital image compositing.
Definition qpainter.h:97
@ CompositionMode_Source
Definition qpainter.h:101
bool isActive() const
Returns true if begin() has been called and end() has not yet been called; otherwise returns false.
void translate(const QPointF &offset)
Translates the coordinate system by the given offset; i.e.
void setRenderHints(RenderHints hints, bool on=true)
void fillRect(const QRectF &, const QBrush &)
Fills the given rectangle with the brush specified.
bool hasClipping() const
Returns true if clipping has been set; otherwise returns false.
void setClipRegion(const QRegion &, Qt::ClipOperation op=Qt::ReplaceClip)
Sets the clip region to the given region using the specified clip operation.
void setTransform(const QTransform &transform, bool combine=false)
The QPalette class contains color groups for each widget state.
Definition qpalette.h:19
const QBrush & brush(ColorGroup cg, ColorRole cr) const
Returns the brush in the specified color group, used for the given color role.
Definition qpalette.cpp:748
quint64 ResolveMask
Definition qpalette.h:113
void setCurrentColorGroup(ColorGroup cg)
Set the palette's current color group to cg.
Definition qpalette.h:65
void setResolveMask(ResolveMask mask)
ResolveMask resolveMask() const
@ Inactive
Definition qpalette.h:49
@ Disabled
Definition qpalette.h:49
QPalette resolve(const QPalette &other) const
Returns a new QPalette that is a union of this instance and other.
Definition qpalette.cpp:966
@ HighlightedText
Definition qpalette.h:53
@ ToolTipBase
Definition qpalette.h:57
@ ButtonText
Definition qpalette.h:52
@ WindowText
Definition qpalette.h:51
@ Highlight
Definition qpalette.h:53
@ ToolTipText
Definition qpalette.h:57
\inmodule QtGui
Definition qpen.h:28
Returns a copy of the pixmap that is transformed using the given transformation transform and transfo...
Definition qpixmap.h:27
void createRhi(QWindow *window, QPlatformBackingStoreRhiConfig config)
The QPlatformIntegration class is the entry for WindowSystem specific functionality.
virtual bool hasCapability(Capability cap) const
The QPlatformSurfaceEvent class is used to notify about native platform surface events....
Definition qevent.h:531
The QPlatformWindow class provides an abstraction for top-level windows.
virtual bool setWindowModified(bool modified)
Reimplement to be able to let Qt indicate that the window has been modified.
virtual QMargins safeAreaMargins() const
The safe area margins of a window represent the area that is safe to place content within,...
\inmodule QtCore\reentrant
Definition qpoint.h:217
constexpr QPoint toPoint() const
Rounds the coordinates of this point to the nearest integer, and returns a QPoint object with the rou...
Definition qpoint.h:404
\inmodule QtCore\reentrant
Definition qpoint.h:25
constexpr int x() const noexcept
Returns the x coordinate of this point.
Definition qpoint.h:130
constexpr int y() const noexcept
Returns the y coordinate of this point.
Definition qpoint.h:135
\inmodule QtCore\reentrant
Definition qrect.h:484
QRect toAlignedRect() const noexcept
Definition qrect.cpp:2338
constexpr QRectF translated(qreal dx, qreal dy) const noexcept
Returns a copy of the rectangle that is translated dx along the x axis and dy along the y axis,...
Definition qrect.h:762
constexpr QRectF adjusted(qreal x1, qreal y1, qreal x2, qreal y2) const noexcept
Returns a new rectangle with dx1, dy1, dx2 and dy2 added respectively to the existing coordinates of ...
Definition qrect.h:813
\inmodule QtCore\reentrant
Definition qrect.h:30
constexpr bool isEmpty() const noexcept
Returns true if the rectangle is empty, otherwise returns false.
Definition qrect.h:167
constexpr int height() const noexcept
Returns the height of the rectangle.
Definition qrect.h:239
constexpr bool isNull() const noexcept
Returns true if the rectangle is a null rectangle, otherwise returns false.
Definition qrect.h:164
constexpr int bottom() const noexcept
Returns the y-coordinate of the rectangle's bottom edge.
Definition qrect.h:182
constexpr QPoint topLeft() const noexcept
Returns the position of the rectangle's top-left corner.
Definition qrect.h:221
constexpr QRect adjusted(int x1, int y1, int x2, int y2) const noexcept
Returns a new rectangle with dx1, dy1, dx2 and dy2 added respectively to the existing coordinates of ...
Definition qrect.h:370
constexpr int top() const noexcept
Returns the y-coordinate of the rectangle's top edge.
Definition qrect.h:176
bool contains(const QRect &r, bool proper=false) const noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qrect.cpp:855
constexpr int left() const noexcept
Returns the x-coordinate of the rectangle's left edge.
Definition qrect.h:173
constexpr int x() const noexcept
Returns the x-coordinate of the rectangle's left edge.
Definition qrect.h:185
constexpr void setWidth(int w) noexcept
Sets the width of the rectangle to the given width.
Definition qrect.h:381
constexpr QSize size() const noexcept
Returns the size of the rectangle.
Definition qrect.h:242
constexpr void translate(int dx, int dy) noexcept
Moves the rectangle dx along the x axis and dy along the y axis, relative to the current position.
Definition qrect.h:245
constexpr int width() const noexcept
Returns the width of the rectangle.
Definition qrect.h:236
constexpr QRect translated(int dx, int dy) const noexcept
Returns a copy of the rectangle that is translated dx along the x axis and dy along the y axis,...
Definition qrect.h:261
constexpr int y() const noexcept
Returns the y-coordinate of the rectangle's top edge.
Definition qrect.h:188
constexpr QPoint center() const noexcept
Returns the center point of the rectangle.
Definition qrect.h:233
constexpr int right() const noexcept
Returns the x-coordinate of the rectangle's right edge.
Definition qrect.h:179
The QRegion class specifies a clip region for a painter.
Definition qregion.h:27
QRect boundingRect() const noexcept
Returns the bounding rectangle of this region.
void translate(int dx, int dy)
Translates (moves) the region dx along the X axis and dy along the Y axis.
bool intersects(const QRegion &r) const
Definition qregion.cpp:613
bool isEmpty() const
Returns true if the region is empty; otherwise returns false.
QRegion translated(int dx, int dy) const
Definition qregion.cpp:593
The QResizeEvent class contains event parameters for resize events.
Definition qevent.h:548
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:1805
The QScreen class is used to query screen properties. \inmodule QtGui.
Definition qscreen.h:32
qreal logicalDotsPerInchY
the number of logical dots or pixels per inch in the vertical direction
Definition qscreen.h:57
qreal devicePixelRatio
the screen's ratio between physical pixels and device-independent pixels
Definition qscreen.h:59
qreal logicalDotsPerInchX
the number of logical dots or pixels per inch in the horizontal direction
Definition qscreen.h:56
QSizeF physicalSize
the screen's physical size (in millimeters)
Definition qscreen.h:50
QRect geometry
the screen's geometry in pixels
Definition qscreen.h:45
qreal physicalDotsPerInchY
the number of physical dots or pixels per inch in the vertical direction
Definition qscreen.h:54
int depth
the color depth of the screen
Definition qscreen.h:40
qreal physicalDotsPerInchX
the number of physical dots or pixels per inch in the horizontal direction
Definition qscreen.h:52
The QShowEvent class provides an event that is sent when a widget is shown.
Definition qevent.h:578
\inmodule QtCore
Definition qsize.h:208
constexpr qreal width() const noexcept
Returns the width.
Definition qsize.h:332
constexpr qreal height() const noexcept
Returns the height.
Definition qsize.h:335
The QSizePolicy class is a layout attribute describing horizontal and vertical resizing policy.
Definition qsizepolicy.h:18
constexpr bool retainSizeWhenHidden() const noexcept
Definition qsizepolicy.h:97
\inmodule QtCore
Definition qsize.h:25
constexpr void setHeight(int h) noexcept
Sets the height to the given height.
Definition qsize.h:139
The QStatusTipEvent class provides an event that is used to show messages in a status bar.
Definition qevent.h:808
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
qsizetype indexOf(QLatin1StringView s, qsizetype from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition qstring.cpp:4522
bool isEmpty() const noexcept
Returns true if the string has no characters; otherwise returns false.
Definition qstring.h:192
bool isNull() const
Returns true if this string is null; otherwise returns false.
Definition qstring.h:994
QByteArray toLocal8Bit() const &
Definition qstring.h:638
The QStyleOption class stores the parameters used by QStyle functions.
void initFrom(const QWidget *w)
The QStyle class is an abstract base class that encapsulates the look and feel of a GUI.
Definition qstyle.h:29
virtual void polish(QWidget *widget)
Initializes the appearance of the given widget.
Definition qstyle.cpp:436
@ SH_Widget_ShareActivation
Definition qstyle.h:608
@ SH_TitleBar_ModifyNotification
Definition qstyle.h:633
virtual int styleHint(StyleHint stylehint, const QStyleOption *opt=nullptr, const QWidget *widget=nullptr, QStyleHintReturn *returnData=nullptr) const =0
Returns an integer representing the specified style hint for the given widget described by the provid...
@ PM_TitleBarHeight
Definition qstyle.h:448
@ PE_Widget
Definition qstyle.h:148
SubElement
This enum represents a sub-area of a widget.
Definition qstyle.h:242
The QSurfaceFormat class represents the format of a QSurface. \inmodule QtGui.
SurfaceType
The SurfaceType enum describes what type of surface this is.
Definition qsurface.h:30
@ RasterSurface
Definition qsurface.h:31
@ OpenGLSurface
Definition qsurface.h:32
static void showText(const QPoint &pos, const QString &text, QWidget *w=nullptr, const QRect &rect={}, int msecShowTime=-1)
Shows text as a tool tip, with the global position pos as the point of interest.
Definition qtooltip.cpp:440
The QTransform class specifies 2D transformations of a coordinate system.
Definition qtransform.h:20
QTransform & scale(qreal sx, qreal sy)
Scales the coordinate system by sx horizontally and sy vertically, and returns a reference to the mat...
QPoint map(const QPoint &p) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
static QTransform fromTranslate(qreal dx, qreal dy)
Creates a matrix which corresponds to a translation of dx along the x axis and dy along the y axis.
bool isScaling() const
Returns true if the matrix represents a scaling transformation, otherwise returns false.
Definition qtransform.h:179
QTransform & translate(qreal dx, qreal dy)
Moves the coordinate system dx along the x axis and dy along the y axis, and returns a reference to t...
\inmodule QtCore
Definition qvariant.h:65
static void showText(const QPoint &pos, const QString &text, QWidget *w=nullptr)
Shows text as a "What's This?" window, at global position pos.
QRect crect
Definition qwidget.h:90
QWidget * wid
bool isFocusChainConsistent() const
uint mustHaveWindowHandle
Definition qwidget_p.h:726
void deleteExtra()
Definition qwidget.cpp:1680
void setEnabled_helper(bool)
Definition qwidget.cpp:3381
uint dirtyOpaqueChildren
Definition qwidget_p.h:719
const QMetaObject * polished
Definition qwidget_p.h:656
void hideChildren(bool spontaneous)
Definition qwidget.cpp:8457
QSize adjustedSize() const
Definition qwidget.cpp:8710
QMargins safeAreaMargins() const
Definition qwidget.cpp:7701
QWidget * nextPrevElementInFocusChain(FocusDirection direction) const
QWindow * _q_closestWindowHandle() const
Definition qwidget.cpp:1088
void setWindowFilePath_sys(const QString &filePath)
Definition qwidget.cpp:6308
QTLWExtra * maybeTopData() const
Definition qwidget_p.h:867
static QWidgetList takeFromFocusChain(QWidget *from, QWidget *to, FocusDirection direction=FocusDirection::Next)
static int instanceCounter
Definition qwidget_p.h:701
void setModal_sys()
Definition qwidget.cpp:2823
uint inheritedFontResolveMask
Definition qwidget_p.h:690
void setLayoutItemMargins(int left, int top, int right, int bottom)
bool hasChildWithFocusPolicy(Qt::FocusPolicy policy, const QWidget *excludeChildrenOf=nullptr) const
QWidgetData data
Definition qwidget_p.h:704
static void adjustFlags(Qt::WindowFlags &flags, QWidget *w=nullptr)
Definition qwidget.cpp:889
bool isExplicitlyHidden() const
Definition qwidget.cpp:8413
void deactivateWidgetCleanup()
Definition qwidget.cpp:2320
virtual void setWindowFlags(Qt::WindowFlags windowFlags)
void repaint(T t)
bool setScreen(QScreen *screen)
Definition qwidget.cpp:2434
QRegion clipRegion() const
Definition qwidget.cpp:1903
void createSysExtra()
Definition qwidget.cpp:1671
void createTLExtra()
Definition qwidget.cpp:1609
void getLayoutItemMargins(int *left, int *top, int *right, int *bottom) const
void subtractOpaqueChildren(QRegion &rgn, const QRect &clipRect) const
Definition qwidget.cpp:2021
void setWindowTitle_helper(const QString &cap)
Definition qwidget.cpp:6045
void setMask_sys(const QRegion &)
QScreen * associatedScreen() const
Definition qwidget.cpp:1093
bool insertIntoFocusChain(FocusDirection direction, QWidget *position)
QWidget * childAtRecursiveHelper(const QPoint &p, bool) const
uint usesDoubleBufferedGLContext
Definition qwidget_p.h:725
void updateFont(const QFont &)
Definition qwidget.cpp:4793
void setParent_sys(QWidget *parent, Qt::WindowFlags)
QFont localFont() const
Definition qwidget.cpp:4762
signed char leftLayoutItemMargin
Definition qwidget_p.h:697
virtual void beginBackingStorePainting()
Definition qwidget_p.h:606
QWidget * determineLastFocusChild(QWidget *noFurtherThan)
void setUpdatesEnabled_helper(bool)
Definition qwidget.cpp:1814
void scrollRect(const QRect &, int dx, int dy)
void hide_helper()
Definition qwidget.cpp:8171
uint high_attributes[4]
Definition qwidget_p.h:716
bool updateBrushOrigin(QPainter *, const QBrush &brush) const
Definition qwidget.cpp:2258
void updateFrameStrut()
QPalette::ResolveMask inheritedPaletteResolveMask
Definition qwidget_p.h:692
virtual QImage grabFramebuffer()
Definition qwidget_p.h:605
uint renderToTextureReallyDirty
Definition qwidget_p.h:732
QFont naturalWidgetFont(uint inheritedMask) const
Definition qwidget.cpp:4716
void activateChildLayoutsRecursively()
Definition qwidget.cpp:7977
void setSystemClip(QPaintEngine *paintEngine, qreal devicePixelRatio, const QRegion &region)
Definition qwidget.cpp:1940
virtual void endBackingStorePainting()
Definition qwidget_p.h:607
virtual QPlatformBackingStoreRhiConfig rhiConfig() const
Definition qwidget_p.h:590
static QWidgetMapper * mapper
Definition qwidget_p.h:661
void render(QPaintDevice *target, const QPoint &targetOffset, const QRegion &sourceRegion, QWidget::RenderFlags renderFlags)
Definition qwidget.cpp:5661
bool shouldDiscardSyncRequest() const
void restoreRedirected()
Definition qwidget_p.h:517
void setWindowIcon_sys()
Definition qwidget.cpp:6222
void updateContentsRect()
Definition qwidget.cpp:7655
void setSharedPainter(QPainter *painter)
Definition qwidget_p.h:879
bool setScreenForPoint(const QPoint &pos)
Definition qwidget.cpp:2419
uint retainSizeWhenHiddenChanged
Definition qwidget_p.h:721
void setWSGeometry()
Definition qwidget.cpp:219
void adjustQuitOnCloseAttribute()
void clipToEffectiveMask(QRegion &region) const
Definition qwidget.cpp:2118
void setFocus_sys()
Definition qwidget.cpp:6648
static QWidgetPrivate * get(QWidget *w)
Definition qwidget_p.h:212
void resolveLayoutDirection()
Definition qwidget.cpp:4869
@ DontSubtractOpaqueChildren
Definition qwidget_p.h:191
void scrollChildren(int dx, int dy)
Definition qwidget.cpp:197
bool stealKeyboardGrab(bool grab)
signed char topLayoutItemMargin
Definition qwidget_p.h:698
void setLocale_helper(const QLocale &l, bool forceUpdate=false)
Definition qwidget.cpp:5905
void reparentFocusWidgets(QWidget *oldtlw)
Definition qwidget.cpp:7103
void resolvePalette()
Definition qwidget.cpp:4613
QWidgetRepaintManager * maybeRepaintManager() const
Definition qwidget_p.h:893
static void setWidgetParentHelper(QObject *widgetAsObject, QObject *newParent)
const QRegion & getOpaqueChildren() const
Definition qwidget.cpp:1991
void showChildren(bool spontaneous)
Definition qwidget.cpp:8426
void propagatePaletteChange()
Definition qwidget.cpp:1843
void paintOnScreen(const QRegion &rgn)
Definition qwidget.cpp:1778
void paintSiblingsRecursive(QPaintDevice *pdev, const QObjectList &children, int index, const QRegion &rgn, const QPoint &offset, DrawWidgetFlags flags, QPainter *sharedPainter, QWidgetRepaintManager *repaintManager)
Definition qwidget.cpp:5733
void updateGeometry_helper(bool forceUpdate)
void setCursor_sys(const QCursor &cursor)
Definition qwidget.cpp:4992
QRegion prepareToRender(const QRegion &region, QWidget::RenderFlags renderFlags)
Definition qwidget.cpp:5342
QWidget * closestParentWidgetWithWindowHandle() const
Definition qwidget.cpp:1049
QPaintEngine * extraPaintEngine
Definition qwidget_p.h:655
QWidget * deepestFocusProxy() const
Definition qwidget.cpp:6628
std::unique_ptr< QWExtra > extra
Definition qwidget_p.h:647
static void checkRestoredGeometry(const QRect &availableGeometry, QRect *restoredGeometry, int frameHeight)
Definition qwidget.cpp:7415
bool setMaximumSize_helper(int &maxw, int &maxh)
Definition qwidget.cpp:3986
void subtractOpaqueSiblings(QRegion &source, bool *hasDirtySiblingsAbove=nullptr, bool alsoNonOpaque=false) const
Definition qwidget.cpp:2032
void sendPaintEvent(const QRegion &toBePainted)
Definition qwidget.cpp:5651
void setStyle_helper(QStyle *newStyle, bool propagate)
Definition qwidget.cpp:2663
signed char bottomLayoutItemMargin
Definition qwidget_p.h:700
QRegion overlappedRegion(const QRect &rect, bool breakAfterFirst=false) const
Definition qwidget.cpp:1718
void updateWidgetTransform(QEvent *event)
Definition qwidget.cpp:226
QRegion dirty
Definition qwidget_p.h:672
void resolveFont()
Definition qwidget.cpp:4777
QLocale locale
Definition qwidget_p.h:706
@ CloseWithSpontaneousEvent
Definition qwidget_p.h:340
void scroll_sys(int dx, int dy)
QGraphicsEffect * graphicsEffect
Definition qwidget_p.h:657
signed char rightLayoutItemMargin
Definition qwidget_p.h:699
void render_helper(QPainter *painter, const QPoint &targetOffset, const QRegion &sourceRegion, QWidget::RenderFlags renderFlags)
Definition qwidget.cpp:5400
void setWinId(WId)
Definition qwidget.cpp:1589
void createTLSysExtra()
Definition qwidget.cpp:1412
uint textureChildSeen
Definition qwidget_p.h:728
bool stealMouseGrab(bool grab)
void reparentWidgetWindowChildren(QWidget *parentWithWindow)
void setRedirected(QPaintDevice *replacement, const QPoint &offset)
Definition qwidget_p.h:503
void resolveLocale()
Definition qwidget.cpp:5944
void setWindowIcon_helper()
Definition qwidget.cpp:6177
void setNetWmWindowTypes(bool skipIfMissing=false)
QRect frameStrut() const
bool shouldPaintOnScreen() const
Definition qwidget.cpp:2143
void setDirtyOpaqueRegion()
Definition qwidget.cpp:1968
void initFocusChain()
QWidget * focus_child
Definition qwidget_p.h:650
QRhi * rhi() const
Definition qwidget.cpp:1030
void reparentFocusChildren(FocusDirection direction)
void updateIsOpaque()
Definition qwidget.cpp:2158
std::string flagsForDumping() const override
void syncBackingStore()
Definition qwidget.cpp:1759
virtual void beginCompose()
Definition qwidget_p.h:608
QRegion opaqueChildren
Definition qwidget_p.h:671
bool pointInsideRectAndMask(const QPoint &) const
Definition qwidget_p.h:886
void setWindowModified_helper()
QPalette naturalWidgetPalette(QPalette::ResolveMask inheritedMask) const
Definition qwidget.cpp:4569
void invalidateBackingStore_resizeHelper(const QPoint &oldPos, const QSize &oldSize)
Invalidates the backing store when the widget is resized.
QWidgetItemV2 * widgetItem
Definition qwidget_p.h:654
virtual void resolveSamples()
Definition qwidget_p.h:632
void setWindowTitle_sys(const QString &cap)
Definition qwidget.cpp:6052
void updateSystemBackground()
Definition qwidget.cpp:4633
void setVisible(bool)
Definition qwidget.cpp:8303
void paintBackground(QPainter *, const QRegion &, DrawWidgetFlags flags=DrawAsRoot) const
Definition qwidget.cpp:2275
void setOpaque(bool opaque)
Definition qwidget.cpp:2197
QWidget * childAt_helper(const QPoint &, bool) const
void unsetCursor_sys()
Definition qwidget.cpp:5012
void drawWidget(QPaintDevice *pdev, const QRegion &rgn, const QPoint &offset, DrawWidgetFlags flags, QPainter *sharedPainter=nullptr, QWidgetRepaintManager *repaintManager=nullptr)
Definition qwidget.cpp:5464
void setWindowIconText_helper(const QString &cap)
Definition qwidget.cpp:6063
void updateIsTranslucent()
Definition qwidget.cpp:2205
void inheritStyle()
Definition qwidget.cpp:2710
uint renderToTexture
Definition qwidget_p.h:727
QRect effectiveRectFor(const QRegion &region) const
Definition qwidget_p.h:540
void update(T t)
QSizePolicy size_policy
Definition qwidget_p.h:705
QRect clipRect() const
Definition qwidget.cpp:1879
QWidget * effectiveFocusWidget()
Definition qwidget_p.h:440
QTLWExtra * topData() const
Definition qwidget_p.h:861
void setLayoutDirection_helper(Qt::LayoutDirection)
Definition qwidget.cpp:4851
void sendPendingMoveAndResizeEvents(bool recursive=false, bool disableUpdates=false)
Definition qwidget.cpp:7945
void setWindowOpacity_sys(qreal opacity)
void moveRect(const QRect &, int dx, int dy)
bool handleClose(CloseMode mode)
Definition qwidget.cpp:8526
void setPalette_helper(const QPalette &)
Definition qwidget.cpp:4620
QPaintDevice * redirected(QPoint *offset) const
Definition qwidget_p.h:510
QPainter * sharedPainter() const
Definition qwidget_p.h:872
bool setMinimumSize_helper(int &minw, int &minh)
Definition qwidget.cpp:3898
void init(QWidget *desktopWidget, Qt::WindowFlags f)
Definition qwidget.cpp:937
uint directFontResolveMask
Definition qwidget_p.h:689
bool removeFromFocusChain(FocusChainRemovalRules rules=FocusChainRemovalRules(), FocusDirection direction=FocusDirection::Next)
void deleteSysExtra()
Definition qwidget.cpp:1697
void setGeometry_sys(int, int, int, int, bool)
Definition qwidget.cpp:7240
void setFont_helper(const QFont &font)
Definition qwidget_p.h:276
static int maxInstances
Definition qwidget_p.h:702
void createExtra()
Definition qwidget.cpp:1642
decltype(std::declval< QPalette >().resolveMask()) directPaletteResolveMask
Definition qwidget_p.h:691
void invalidateBackingStore(const T &)
void show_recursive()
Definition qwidget.cpp:7927
virtual void endCompose()
Definition qwidget_p.h:609
void setWindowIconText_sys(const QString &cap)
Definition qwidget.cpp:6070
virtual QObject * focusObject()
Definition qwidget.cpp:6863
void createWinId()
Definition qwidget.cpp:2384
void setWindowFilePath_helper(const QString &filePath)
Definition qwidget.cpp:6292
void deleteTLSysExtra()
Definition qwidget.cpp:1701
bool isInFocusChain() const
void createRecursively()
Definition qwidget.cpp:1019
QWidgetPrivate(int version=QObjectPrivateVersion)
Definition qwidget.cpp:105
QLayout * layout
Definition qwidget_p.h:651
void fixPosIncludesFrame()
Definition qwidget.cpp:7172
void reparentWidgetWindows(QWidget *parentWithWindow, Qt::WindowFlags windowFlags={})
void updateFocusChild()
Definition qwidget.cpp:6668
void stackUnder_sys(QWidget *)
void show_helper()
Definition qwidget.cpp:8007
static QWidgetSet * allWidgets
Definition qwidget_p.h:662
QWindow * windowHandle(WindowHandleMode mode=WindowHandleMode::Direct) const
Definition qwidget.cpp:1058
static void sendComposeStatus(QWidget *w, bool end)
bool isAboutToShow() const
The graphicsEffect function returns a pointer to the widget's graphics effect.
Definition qwidget.cpp:5328
void _q_showIfNotHidden()
Definition qwidget.cpp:8419
void setConstraints_sys()
Definition qwidget.cpp:3931
QBackingStore * backingStore() const
void setBackingStore(QBackingStore *backingStore)
void markNeedsFlush(QWidget *widget, const QRegion &region, const QPoint &topLevelOffset)
Marks the region of the widget as needing a flush.
QObject * focusObject() const override
Returns the QObject that will be the final receiver of events tied focus, such as key events.
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
void setAutoFillBackground(bool enabled)
Definition qwidget.cpp:330
QRect normalGeometry
the geometry of the widget as it will appear when shown as a normal (not maximized or full screen) to...
Definition qwidget.h:108
void setWindowFilePath(const QString &filePath)
Definition qwidget.cpp:6280
void setLayout(QLayout *)
Sets the layout manager for this widget to layout.
QRegion visibleRegion() const
Returns the unobscured region where paint events can occur.
Definition qwidget.cpp:8696
int metric(PaintDeviceMetric) const override
Internal implementation of the virtual QPaintDevice::metric() function.
void setAttribute(Qt::WidgetAttribute, bool on=true)
Sets the attribute attribute on this widget if on is true; otherwise clears the attribute.
QWidget * nativeParentWidget() const
Definition qwidget.cpp:4349
void repaint()
Repaints the widget directly by calling paintEvent() immediately, unless updates are disabled or the ...
QString windowRole() const
Returns the window's role, or an empty string.
Definition qwidget.cpp:6324
QWidget * window() const
Returns the window for this widget, i.e.
Definition qwidget.cpp:4329
virtual bool nativeEvent(const QByteArray &eventType, void *message, qintptr *result)
This special event handler can be reimplemented in a subclass to receive native platform events ident...
virtual bool hasHeightForWidth() const
WId internalWinId() const
Definition qwidget.h:220
void releaseShortcut(int id)
Removes the shortcut with the given id from Qt's shortcut system.
void setGeometry(int x, int y, int w, int h)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qwidget.h:886
void raise()
Raises this widget to the top of the parent widget's stack.
void setWindowIconText(const QString &)
Definition qwidget.cpp:6097
Qt::LayoutDirection layoutDirection
the layout direction for this widget.
Definition qwidget.h:170
Qt::WindowFlags windowFlags() const
Window flags are a combination of a type (e.g.
Definition qwidget.h:803
virtual void hideEvent(QHideEvent *event)
This event handler can be reimplemented in a subclass to receive widget hide events.
void setBackgroundRole(QPalette::ColorRole)
Sets the background role of the widget to role.
Definition qwidget.cpp:4407
bool autoFillBackground
whether the widget background is filled automatically
Definition qwidget.h:172
void setUpdatesEnabled(bool enable)
Definition qwidget.cpp:7887
QPointF mapFromParent(const QPointF &) const
Translates the parent widget coordinate pos to widget coordinates.
Definition qwidget.cpp:4302
void scroll(int dx, int dy)
Scrolls the widget including its children dx pixels to the right and dy downward.
virtual void leaveEvent(QEvent *event)
This event handler can be reimplemented in a subclass to receive widget leave events which are passed...
Definition qwidget.cpp:9760
void setWindowModality(Qt::WindowModality windowModality)
Definition qwidget.cpp:2815
virtual void mouseMoveEvent(QMouseEvent *event)
This event handler, for event event, can be reimplemented in a subclass to receive mouse move events ...
Definition qwidget.cpp:9490
void grabKeyboard()
Grabs the keyboard input.
void setContentsMargins(int left, int top, int right, int bottom)
Sets the margins around the contents of the widget to have the sizes left, top, right,...
Definition qwidget.cpp:7619
Q_INVOKABLE QPixmap grab(const QRect &rectangle=QRect(QPoint(0, 0), QSize(-1, -1)))
Definition qwidget.cpp:5231
void setParent(QWidget *parent)
Sets the parent of the widget to parent, and resets the window flags.
Qt::WindowModality windowModality
which windows are blocked by the modal widget
Definition qwidget.h:104
void setMinimumSize(const QSize &)
Definition qwidget.h:832
void setMask(const QBitmap &)
Causes only the pixels of the widget for which bitmap has a corresponding 1 bit to be visible.
void updateGeometry()
Notifies the layout system that this widget has changed and may need to change geometry.
void setSizePolicy(QSizePolicy)
void setStyle(QStyle *)
Sets the widget's GUI style to style.
Definition qwidget.cpp:2644
QWidget * focusProxy() const
Returns the focus proxy, or \nullptr if there is no focus proxy.
Definition qwidget.cpp:6457
virtual void closeEvent(QCloseEvent *event)
This event handler is called with the given event when Qt receives a window close request for a top-l...
Definition qwidget.cpp:9885
void setMinimumWidth(int minw)
Definition qwidget.cpp:4128
bool isMinimized() const
Definition qwidget.cpp:2852
bool isFullScreen() const
Definition qwidget.cpp:2998
bool isHidden() const
Returns true if the widget is hidden, otherwise returns false.
Definition qwidget.h:877
QWidget * nextInFocusChain() const
Returns the next widget in this widget's focus chain.
Definition qwidget.cpp:6875
QString styleSheet
the widget's style sheet
Definition qwidget.h:174
QSize size
the size of the widget excluding any window frame
Definition qwidget.h:113
void clearFocus()
Takes keyboard input focus from the widget.
Definition qwidget.cpp:6713
QSize minimumSize
the widget's minimum size
Definition qwidget.h:120
friend Q_WIDGETS_EXPORT QWidgetPrivate * qt_widget_private(QWidget *widget)
static void setTabOrder(QWidget *, QWidget *)
Puts the second widget after the first widget in the focus order.
Definition qwidget.cpp:7011
QPointF mapToGlobal(const QPointF &) const
Translates the widget coordinate pos to global screen coordinates.
void setWindowFlag(Qt::WindowType, bool on=true)
Qt::ContextMenuPolicy contextMenuPolicy
how the widget shows a context menu
Definition qwidget.h:142
void setEnabled(bool)
Definition qwidget.cpp:3374
void setWindowOpacity(qreal level)
void setFocusProxy(QWidget *)
Sets the widget's focus proxy to widget w.
Definition qwidget.cpp:6398
void overrideWindowFlags(Qt::WindowFlags type)
Sets the window flags for the widget to flags, without telling the window system.
QRect geometry
the geometry of the widget relative to its parent and excluding the window frame
Definition qwidget.h:106
QLayout * layout() const
Returns the layout manager that is installed on this widget, or \nullptr if no layout manager is inst...
void setPalette(const QPalette &)
Definition qwidget.cpp:4546
QPalette palette
the widget's palette
Definition qwidget.h:132
int width
the width of the widget excluding any window frame
Definition qwidget.h:114
virtual void actionEvent(QActionEvent *event)
This event handler is called with the given event whenever the widget's actions are changed.
Definition qwidget.cpp:9864
virtual void mousePressEvent(QMouseEvent *event)
This event handler, for event event, can be reimplemented in a subclass to receive mouse press events...
Definition qwidget.cpp:9512
QString windowIconText
the text to be displayed on the icon of a minimized window
Definition qwidget.h:153
bool isVisibleTo(const QWidget *) const
Returns true if this widget would become visible if ancestor is shown; otherwise returns false.
Definition qwidget.cpp:8672
@ DrawWindowBackground
Definition qwidget.h:207
@ IgnoreMask
Definition qwidget.h:209
@ DrawChildren
Definition qwidget.h:208
void showMinimized()
Shows the widget minimized, as an icon.
Definition qwidget.cpp:2863
bool maximized
whether this widget is maximized
Definition qwidget.h:146
QWidget * childAt(int x, int y) const
Returns the visible child widget at the position ({x}, {y}) in the widget's coordinate system.
Definition qwidget.h:798
void windowIconTextChanged(const QString &iconText)
This signal is emitted when the window's icon text has changed, with the new iconText as an argument.
QSize maximumSize
the widget's maximum size in pixels
Definition qwidget.h:121
QRegion childrenRegion
the combined region occupied by the widget's children
Definition qwidget.h:118
void releaseKeyboard()
Releases the keyboard grab.
QWidget * previousInFocusChain() const
The previousInFocusChain function returns the previous widget in this widget's focus chain.
Definition qwidget.cpp:6889
virtual void mouseDoubleClickEvent(QMouseEvent *event)
This event handler, for event event, can be reimplemented in a subclass to receive mouse double click...
Definition qwidget.cpp:9559
QPoint pos
the position of the widget within its parent widget
Definition qwidget.h:111
friend class QWidgetEffectSourcePrivate
Definition qwidget.h:770
bool isMaximized() const
Definition qwidget.cpp:2892
friend class QStyleSheetStyle
Definition qwidget.h:760
QRect contentsRect() const
Returns the area inside the widget's margins.
Definition qwidget.cpp:7696
void overrideWindowState(Qt::WindowStates state)
Definition qwidget.cpp:2916
~QWidget()
Destroys the widget.
Definition qwidget.cpp:1449
void unsetCursor()
Definition qwidget.cpp:4999
void setShortcutAutoRepeat(int id, bool enable=true)
bool close()
Closes this widget.
Definition qwidget.cpp:8591
void adjustSize()
Adjusts the size of the widget to fit its contents.
Definition qwidget.cpp:8772
void move(int x, int y)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qwidget.h:880
void createWinId()
Definition qwidget.cpp:2455
void showFullScreen()
Shows the widget in full-screen mode.
Definition qwidget.cpp:3037
QWidget * focusWidget() const
Returns the last child of this widget that setFocus had been called on.
Definition qwidget.cpp:6858
void setContextMenuPolicy(Qt::ContextMenuPolicy policy)
Definition qwidget.cpp:7819
static QWidget * find(WId)
Returns a pointer to the widget with window identifier/handle id.
Definition qwidget.cpp:2341
virtual void focusInEvent(QFocusEvent *event)
This event handler can be reimplemented in a subclass to receive keyboard focus events (focus receive...
Definition qwidget.cpp:9694
bool isModal() const
Definition qwidget.h:817
void setAcceptDrops(bool on)
Definition qwidget.cpp:3452
bool updatesEnabled
whether updates are enabled
Definition qwidget.h:143
virtual void mouseReleaseEvent(QMouseEvent *event)
This event handler, for event event, can be reimplemented in a subclass to receive mouse release even...
Definition qwidget.cpp:9537
virtual void keyReleaseEvent(QKeyEvent *event)
This event handler, for event event, can be reimplemented in a subclass to receive key release events...
Definition qwidget.cpp:9670
QSizePolicy sizePolicy
the default layout behavior of the widget
Definition qwidget.h:119
void setMaximumHeight(int maxh)
Definition qwidget.cpp:4155
QLocale locale
the widget's locale
Definition qwidget.h:176
void setFocusPolicy(Qt::FocusPolicy policy)
Definition qwidget.cpp:7851
virtual void moveEvent(QMoveEvent *event)
This event handler can be reimplemented in a subclass to receive widget move events which are passed ...
Definition qwidget.cpp:9830
void setWindowRole(const QString &)
Sets the window's role to role.
Definition qwidget.cpp:6334
QSize minimumSizeHint
the recommended minimum size for the widget
Definition qwidget.h:149
void hide()
Hides the widget.
Definition qwidget.cpp:8164
void setMinimumHeight(int minh)
Definition qwidget.cpp:4137
virtual bool focusNextPrevChild(bool next)
Finds a new widget to give the keyboard focus to, as appropriate for Tab and Shift+Tab,...
Definition qwidget.cpp:6807
virtual QVariant inputMethodQuery(Qt::InputMethodQuery) const
This method is only relevant for input widgets.
Definition qwidget.cpp:9942
int height
the height of the widget excluding any window frame
Definition qwidget.h:115
QList< QAction * > actions() const
Returns the (possibly empty) list of this widget's actions.
Definition qwidget.cpp:3223
int devType() const override
Definition qwidget.cpp:882
void setHidden(bool hidden)
Convenience function, equivalent to setVisible(!hidden).
Definition qwidget.cpp:8408
QRect rect
the internal geometry of the widget excluding any window frame
Definition qwidget.h:116
bool isEnabledTo(const QWidget *) const
Returns true if this widget would become enabled if ancestor is enabled; otherwise returns false.
Definition qwidget.cpp:3106
void setWindowState(Qt::WindowStates state)
Sets the window state to windowState.
Definition qwidget.cpp:2953
QSize sizeIncrement
the size increment of the widget
Definition qwidget.h:130
void setDisabled(bool)
Disables widget input events if disable is true; otherwise enables input events.
Definition qwidget.cpp:3466
void setFocus()
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qwidget.h:423
int y
the y coordinate of the widget relative to its parent and including any window frame
Definition qwidget.h:110
void setLayoutDirection(Qt::LayoutDirection direction)
Definition qwidget.cpp:4895
void show()
Shows the widget and its child widgets.
Definition qwidget.cpp:7904
virtual void setVisible(bool visible)
Definition qwidget.cpp:8284
QPaintEngine * paintEngine() const override
Returns the widget's paint engine.
void insertAction(QAction *before, QAction *action)
Inserts the action action to this widget's list of actions, before the action before.
Definition qwidget.cpp:3158
void setScreen(QScreen *)
Sets the screen on which the widget should be shown to screen.
Definition qwidget.cpp:2538
void stackUnder(QWidget *)
Places the widget under w in the parent widget's stack.
int x
the x coordinate of the widget relative to its parent including any window frame
Definition qwidget.h:109
void setMaximumSize(const QSize &)
Definition qwidget.h:835
void ensurePolished() const
Ensures that the widget and its children have been polished by QStyle (i.e., have a proper font and p...
virtual void enterEvent(QEnterEvent *event)
This event handler can be reimplemented in a subclass to receive widget enter events which are passed...
Definition qwidget.cpp:9744
bool isEnabled() const
Definition qwidget.h:814
QIcon windowIcon
the widget's icon
Definition qwidget.h:152
QString windowFilePath
the file path associated with a widget
Definition qwidget.h:177
void lower()
Lowers the widget to the bottom of the parent widget's stack.
void update()
Updates the widget unless updates are disabled or the widget is hidden.
static QWidget * mouseGrabber()
Returns the widget that is currently grabbing the mouse input.
QWindow * windowHandle() const
If this is a native widget, return the associated QWindow.
Definition qwidget.cpp:2497
virtual void changeEvent(QEvent *)
This event handler can be reimplemented to handle state changes.
Definition qwidget.cpp:9411
void setFixedHeight(int h)
Sets both the minimum and maximum heights of the widget to h without changing the widths.
Definition qwidget.cpp:4191
friend class QPixmap
Definition qwidget.h:748
void grabGesture(Qt::GestureType type, Qt::GestureFlags flags=Qt::GestureFlags())
Subscribes the widget to a given gesture with specific flags.
QSize sizeHint
the recommended size for the widget
Definition qwidget.h:148
void showMaximized()
Shows the widget maximized.
Definition qwidget.cpp:3060
void setFixedWidth(int w)
Sets both the minimum and maximum width of the widget to w without changing the heights.
Definition qwidget.cpp:4171
void setShortcutEnabled(int id, bool enable=true)
If enable is true, the shortcut with the given id is enabled; otherwise the shortcut is disabled.
void windowIconChanged(const QIcon &icon)
This signal is emitted when the window's icon has changed, with the new icon as an argument.
virtual void inputMethodEvent(QInputMethodEvent *)
This event handler, for event event, can be reimplemented in a subclass to receive Input Method compo...
Definition qwidget.cpp:9927
static QWidget * keyboardGrabber()
Returns the widget that is currently grabbing the keyboard input.
void setSizeIncrement(const QSize &)
Definition qwidget.h:838
QPointF mapFrom(const QWidget *, const QPointF &) const
Translates the widget coordinate pos from the coordinate system of parent to this widget's coordinate...
Definition qwidget.cpp:4245
Qt::InputMethodHints inputMethodHints
What input method specific hints the widget has.
Definition qwidget.h:178
WId effectiveWinId() const
Definition qwidget.cpp:2476
void initPainter(QPainter *painter) const override
Initializes the painter pen, background and font to the same as the given widget's.
void addActions(const QList< QAction * > &actions)
Appends the actions actions to this widget's list of actions.
Definition qwidget.cpp:3143
bool acceptDrops
whether drop events are enabled for this widget
Definition qwidget.h:150
void setWindowModified(bool)
WId winId() const
Returns the window system identifier of the widget.
Definition qwidget.cpp:2371
void ungrabGesture(Qt::GestureType type)
Unsubscribes the widget from a given gesture type.
bool enabled
whether the widget is enabled
Definition qwidget.h:105
void setWindowTitle(const QString &)
Definition qwidget.cpp:6121
QPaintDevice * redirected(QPoint *offset) const override
QByteArray saveGeometry() const
Definition qwidget.cpp:7366
bool event(QEvent *event) override
This is the main event handler; it handles event event.
Definition qwidget.cpp:8895
void setLocale(const QLocale &locale)
Definition qwidget.cpp:5929
bool isWindowModified() const
int grabShortcut(const QKeySequence &key, Qt::ShortcutContext context=Qt::WindowShortcut)
Adds a shortcut to Qt's shortcut system that watches for the given key sequence in the given context.
QStyle * style() const
Definition qwidget.cpp:2614
void setWindowIcon(const QIcon &icon)
Definition qwidget.cpp:6204
void setFont(const QFont &)
Definition qwidget.cpp:4683
QFont font
the font currently set for the widget
Definition qwidget.h:133
void customContextMenuRequested(const QPoint &pos)
This signal is emitted when the widget's \l contextMenuPolicy is Qt::CustomContextMenu,...
void resize(int w, int h)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qwidget.h:883
QString windowTitle
the window title (caption)
Definition qwidget.h:151
void render(QPaintDevice *target, const QPoint &targetOffset=QPoint(), const QRegion &sourceRegion=QRegion(), RenderFlags renderFlags=RenderFlags(DrawWindowBackground|DrawChildren))
Definition qwidget.cpp:5108
QRegion mask() const
Returns the mask currently set on a widget.
void create(WId=0, bool initializeWindow=true, bool destroyOldWindow=true)
Creates a new widget window.
Definition qwidget.cpp:1166
void destroy(bool destroyWindow=true, bool destroySubWindows=true)
Frees up window system resources.
bool hasFocus() const
Definition qwidget.cpp:6476
friend class QWidgetRepaintManager
Definition qwidget.h:740
virtual void focusOutEvent(QFocusEvent *event)
This event handler can be reimplemented in a subclass to receive keyboard focus events (focus lost) f...
Definition qwidget.cpp:9720
virtual void resizeEvent(QResizeEvent *event)
This event handler can be reimplemented in a subclass to receive widget resize events which are passe...
Definition qwidget.cpp:9851
Qt::FocusPolicy focusPolicy
the way the widget accepts keyboard focus
Definition qwidget.h:140
QWidget * parentWidget() const
Returns the parent of this widget, or \nullptr if it does not have any parent widget.
Definition qwidget.h:904
QPainter * sharedPainter() const override
double windowOpacity
The level of opacity for the window.
Definition qwidget.h:154
void grabMouse()
Grabs the mouse input.
QPalette::ColorRole foregroundRole() const
Returns the foreground role.
Definition qwidget.cpp:4427
QCursor cursor
the cursor shape for this widget
Definition qwidget.h:135
void setBaseSize(const QSize &)
Definition qwidget.h:841
QPointF mapTo(const QWidget *, const QPointF &) const
Translates the widget coordinate pos to the coordinate system of parent.
Definition qwidget.cpp:4213
bool isWindow() const
Returns true if the widget is an independent window, otherwise returns false.
Definition qwidget.h:811
Qt::WindowStates windowState() const
Returns the current window state.
Definition qwidget.cpp:2904
QRect frameGeometry
geometry of the widget relative to its parent including any window frame
Definition qwidget.h:107
bool isAncestorOf(const QWidget *child) const
Returns true if this widget is a parent, (or grandparent and so on to any level), of the given child,...
Definition qwidget.cpp:8851
QBackingStore * backingStore() const
QScreen * screen() const
Returns the screen the widget is on.
Definition qwidget.cpp:2510
void showNormal()
Restores the widget after it has been maximized or minimized.
Definition qwidget.cpp:3076
void setForegroundRole(QPalette::ColorRole)
Sets the foreground role of the widget to role.
Definition qwidget.cpp:4472
void clearMask()
Removes any mask set by setMask().
bool restoreGeometry(const QByteArray &geometry)
Definition qwidget.cpp:7478
void activateWindow()
Sets the top-level widget containing this widget to be the active window.
void insertActions(QAction *before, const QList< QAction * > &actions)
Inserts the actions actions to this widget's list of actions, before the action before.
Definition qwidget.cpp:3192
bool isActiveWindow
whether this widget's window is the active window
Definition qwidget.h:139
void setStyleSheet(const QString &styleSheet)
Definition qwidget.cpp:2569
QSize baseSize
the base size of the widget
Definition qwidget.h:131
QPalette::ColorRole backgroundRole() const
Returns the background role of the widget.
Definition qwidget.cpp:4376
virtual void keyPressEvent(QKeyEvent *event)
This event handler, for event event, can be reimplemented in a subclass to receive key press events f...
Definition qwidget.cpp:9635
QSize frameSize
the size of the widget including any window frame
Definition qwidget.h:112
QPointF mapToParent(const QPointF &) const
Translates the widget coordinate pos to a coordinate in the parent widget.
Definition qwidget.cpp:4279
void setFixedSize(const QSize &)
Sets both the minimum and maximum sizes of the widget to s, thereby preventing it from ever growing o...
Definition qwidget.cpp:4098
QMargins contentsMargins() const
The contentsMargins function returns the widget's contents margins.
Definition qwidget.cpp:7683
void removeAction(QAction *action)
Removes the action action from this widget's list of actions.
Definition qwidget.cpp:3202
virtual void paintEvent(QPaintEvent *event)
This event handler can be reimplemented in a subclass to receive paint events passed in event.
Definition qwidget.cpp:9812
void updateMicroFocus(Qt::InputMethodQuery query=Qt::ImQueryAll)
Updates the widget's micro focus and informs input methods that the state specified by query has chan...
virtual void showEvent(QShowEvent *event)
This event handler can be reimplemented in a subclass to receive widget show events which are passed ...
void unsetLayoutDirection()
Definition qwidget.cpp:4913
bool fullScreen
whether the widget is shown in full screen mode
Definition qwidget.h:147
bool isVisible() const
Definition qwidget.h:874
QPointF mapFromGlobal(const QPointF &) const
Translates the global screen coordinate pos to widget coordinates.
void addAction(QAction *action)
Appends the action action to this widget's list of actions.
Definition qwidget.cpp:3133
void releaseMouse()
Releases the mouse grab.
void setInputMethodHints(Qt::InputMethodHints hints)
Qt::WindowType windowType() const
Returns the window type of this widget.
Definition qwidget.h:801
void setCursor(const QCursor &)
Definition qwidget.cpp:4976
bool testAttribute(Qt::WidgetAttribute) const
Returns true if attribute attribute is set on this widget; otherwise returns false.
Definition qwidget.h:910
virtual void contextMenuEvent(QContextMenuEvent *event)
This event handler, for event event, can be reimplemented in a subclass to receive widget context men...
Definition qwidget.cpp:9904
void unsetLocale()
Definition qwidget.cpp:5955
void setMaximumWidth(int maxw)
Definition qwidget.cpp:4146
void windowTitleChanged(const QString &title)
This signal is emitted when the window's title has changed, with the new title as an argument.
bool visible
whether the widget is visible
Definition qwidget.h:144
QRect childrenRect
the bounding rectangle of the widget's children
Definition qwidget.h:117
virtual int heightForWidth(int) const
Returns the preferred height for this widget, given the width w.
void setWindowFlags(Qt::WindowFlags type)
static void parentWasChanged(QWidget *parent)
static void parentWasRaised(QWidget *parent)
static void parentWasMoved(QWidget *parent)
static void parentWasLowered(QWidget *parent)
static void toplevelAboutToBeDestroyed(QWidget *parent)
\inmodule QtGui
Definition qevent.h:899
\inmodule QtGui
Definition qwindow.h:63
void focusObjectChanged(QObject *object)
This signal is emitted when the final receiver of events tied to focus is changed to object.
QOpenGLWidget * widget
[1]
QString text
QCursor cursor
QSet< QString >::iterator it
rect
[4]
direction
QStyleOptionButton opt
short next
Definition keywords.cpp:445
Combined button and popup list for selecting options.
Definition qcompare.h:63
WindowState
Definition qnamespace.h:251
@ WindowFullScreen
Definition qnamespace.h:255
@ WindowNoState
Definition qnamespace.h:252
@ WindowMinimized
Definition qnamespace.h:253
@ WindowMaximized
Definition qnamespace.h:254
@ WindowActive
Definition qnamespace.h:256
InputMethodQuery
@ ImInputItemClipRectangle
@ ImCursorPosition
@ ImFont
@ ImAnchorPosition
@ ImCursorRectangle
@ ImHints
@ ImEnabled
@ NavigationModeKeypadDirectional
@ NavigationModeKeypadTabOrder
QTextStream & hex(QTextStream &stream)
Calls QTextStream::setIntegerBase(16) on stream and returns stream.
@ NoButton
Definition qnamespace.h:57
WidgetAttribute
Definition qnamespace.h:282
@ WA_GrabbedShortcut
Definition qnamespace.h:316
@ WA_X11NetWmWindowTypeDND
Definition qnamespace.h:398
@ WA_SetWindowIcon
Definition qnamespace.h:319
@ WA_X11NetWmWindowTypePopupMenu
Definition qnamespace.h:394
@ WA_WState_ExplicitShowHide
Definition qnamespace.h:335
@ WA_AcceptTouchEvents
Definition qnamespace.h:404
@ WA_UnderMouse
Definition qnamespace.h:284
@ WA_AlwaysStackOnTop
Definition qnamespace.h:411
@ WA_WState_WindowOpacitySet
Definition qnamespace.h:401
@ WA_TransparentForMouseEvents
Definition qnamespace.h:317
@ WA_ForceUpdatesDisabled
Definition qnamespace.h:325
@ WA_PendingResizeEvent
Definition qnamespace.h:302
@ WA_SetLayoutDirection
Definition qnamespace.h:323
@ WA_StyleSheet
Definition qnamespace.h:372
@ WA_MacMiniSize
Definition qnamespace.h:363
@ WA_SetLocale
Definition qnamespace.h:358
@ WA_SetPalette
Definition qnamespace.h:303
@ WA_WindowPropagation
Definition qnamespace.h:349
@ WA_MacAlwaysShowToolWindow
Definition qnamespace.h:370
@ WA_SetWindowModality
Definition qnamespace.h:400
@ WA_X11NetWmWindowTypeDock
Definition qnamespace.h:387
@ WA_X11NetWmWindowTypeUtility
Definition qnamespace.h:390
@ WA_RightToLeft
Definition qnamespace.h:322
@ WA_X11NetWmWindowTypeDialog
Definition qnamespace.h:392
@ WA_X11NetWmWindowTypeSplash
Definition qnamespace.h:391
@ WA_SetCursor
Definition qnamespace.h:305
@ WA_X11NetWmWindowTypeDropDownMenu
Definition qnamespace.h:393
@ WA_Resized
Definition qnamespace.h:308
@ WA_QuitOnClose
Definition qnamespace.h:342
@ WA_WState_Polished
Definition qnamespace.h:332
@ WA_TranslucentBackground
Definition qnamespace.h:402
@ WA_NoChildEventsFromChildren
Definition qnamespace.h:306
@ WA_DontShowOnScreen
Definition qnamespace.h:383
@ WA_ContentsMarginsRespectsSafeArea
Definition qnamespace.h:415
@ WA_X11NetWmWindowTypeToolTip
Definition qnamespace.h:395
@ WA_X11NetWmWindowTypeCombo
Definition qnamespace.h:397
@ WA_X11NetWmWindowTypeToolBar
Definition qnamespace.h:388
@ WA_DropSiteRegistered
Definition qnamespace.h:347
@ WA_KeyboardFocusChange
Definition qnamespace.h:344
@ WA_PendingMoveEvent
Definition qnamespace.h:301
@ WA_PaintOnScreen
Definition qnamespace.h:290
@ WA_NoChildEventsForParent
Definition qnamespace.h:324
@ WA_AttributeCount
Definition qnamespace.h:420
@ WA_DontCreateNativeAncestors
Definition qnamespace.h:379
@ WA_Moved
Definition qnamespace.h:309
@ WA_SetStyle
Definition qnamespace.h:356
@ WA_MacNormalSize
Definition qnamespace.h:361
@ WA_NativeWindow
Definition qnamespace.h:378
@ WA_Disabled
Definition qnamespace.h:283
@ WA_TabletTracking
Definition qnamespace.h:413
@ WA_OutsideWSRange
Definition qnamespace.h:315
@ WA_WState_Hidden
Definition qnamespace.h:297
@ WA_StaticContents
Definition qnamespace.h:288
@ WA_ShowWithoutActivating
Definition qnamespace.h:374
@ WA_X11NetWmWindowTypeMenu
Definition qnamespace.h:389
@ WA_WState_Visible
Definition qnamespace.h:296
@ WA_NoSystemBackground
Definition qnamespace.h:291
@ WA_WState_InPaintEvent
Definition qnamespace.h:329
@ WA_WState_OwnSizePolicy
Definition qnamespace.h:334
@ WA_SetFont
Definition qnamespace.h:304
@ WA_StyledBackground
Definition qnamespace.h:366
@ WA_WState_Created
Definition qnamespace.h:327
@ WA_MacSmallSize
Definition qnamespace.h:362
@ WA_TintedBackground
Definition qnamespace.h:352
@ WA_ShowModal
Definition qnamespace.h:337
@ WA_X11NetWmWindowTypeDesktop
Definition qnamespace.h:386
@ WA_UpdatesDisabled
Definition qnamespace.h:292
@ WA_InputMethodEnabled
Definition qnamespace.h:295
@ WA_MouseTracking
Definition qnamespace.h:285
@ WA_ForceDisabled
Definition qnamespace.h:299
@ WA_Mapped
Definition qnamespace.h:293
@ WA_OpaquePaintEvent
Definition qnamespace.h:287
@ WA_DeleteOnClose
Definition qnamespace.h:321
@ WA_WindowModified
Definition qnamespace.h:307
@ WA_LayoutOnEntireRect
Definition qnamespace.h:314
@ WA_AcceptDrops
Definition qnamespace.h:346
@ WA_X11NetWmWindowTypeNotification
Definition qnamespace.h:396
WindowModality
@ NonModal
@ ApplicationModal
LayoutDirection
@ LeftToRight
@ LayoutDirectionAuto
@ RightToLeft
QTextStream & noforcesign(QTextStream &stream)
Calls QTextStream::setNumberFlags(QTextStream::numberFlags() & ~QTextStream::ForceSign) on stream and...
FocusPolicy
Definition qnamespace.h:106
@ NoFocus
Definition qnamespace.h:107
@ TabFocus
Definition qnamespace.h:108
Orientation
Definition qnamespace.h:98
@ Horizontal
Definition qnamespace.h:99
@ Vertical
Definition qnamespace.h:100
@ ArrowCursor
@ ImhNone
@ transparent
Definition qnamespace.h:47
@ Key_Tab
Definition qnamespace.h:664
@ Key_Right
Definition qnamespace.h:679
@ Key_Backtab
Definition qnamespace.h:665
@ Key_Left
Definition qnamespace.h:677
@ Key_Up
Definition qnamespace.h:678
@ Key_Down
Definition qnamespace.h:680
@ Key_F1
Definition qnamespace.h:690
QTextStream & dec(QTextStream &stream)
Calls QTextStream::setIntegerBase(10) on stream and returns stream.
@ FindChildrenRecursively
@ ShiftModifier
@ ControlModifier
@ AltModifier
@ AA_DontCreateNativeWidgetSiblings
Definition qnamespace.h:429
@ AA_UseStyleSheetPropagationInWidgetStyles
Definition qnamespace.h:457
@ AA_NativeWindows
Definition qnamespace.h:428
@ AA_PluginApplication
Definition qnamespace.h:430
QTextStream & forcesign(QTextStream &stream)
Calls QTextStream::setNumberFlags(QTextStream::numberFlags() | QTextStream::ForceSign) on stream and ...
@ SolidPattern
@ TexturePattern
@ NoBrush
@ ApplicationActive
Definition qnamespace.h:266
ConnectionType
CoordinateSystem
@ DeviceCoordinates
GestureType
WindowType
Definition qnamespace.h:205
@ CustomizeWindowHint
Definition qnamespace.h:239
@ Desktop
Definition qnamespace.h:215
@ Widget
Definition qnamespace.h:206
@ FramelessWindowHint
Definition qnamespace.h:225
@ MSWindowsOwnDC
Definition qnamespace.h:222
@ WindowContextHelpButtonHint
Definition qnamespace.h:231
@ ToolTip
Definition qnamespace.h:213
@ Popup
Definition qnamespace.h:211
@ WindowType_Mask
Definition qnamespace.h:220
@ Window
Definition qnamespace.h:207
@ SplashScreen
Definition qnamespace.h:214
@ WindowFullscreenButtonHint
Definition qnamespace.h:245
@ WindowMaximizeButtonHint
Definition qnamespace.h:229
@ WindowMinimizeButtonHint
Definition qnamespace.h:228
@ Dialog
Definition qnamespace.h:208
@ WindowMinMaxButtonsHint
Definition qnamespace.h:230
@ Sheet
Definition qnamespace.h:209
@ WindowTransparentForInput
Definition qnamespace.h:234
@ SubWindow
Definition qnamespace.h:216
@ MaximizeUsingFullscreenGeometryHint
Definition qnamespace.h:237
@ Tool
Definition qnamespace.h:212
@ WindowTitleHint
Definition qnamespace.h:226
@ WindowSystemMenuHint
Definition qnamespace.h:227
@ WindowCloseButtonHint
Definition qnamespace.h:241
ContextMenuPolicy
@ ActionsContextMenu
@ DefaultContextMenu
@ CustomContextMenu
@ PreventContextMenu
FocusReason
@ PopupFocusReason
@ BacktabFocusReason
@ NoFocusReason
@ MenuBarFocusReason
@ OtherFocusReason
@ TabFocusReason
ShortcutContext
Definition brush.cpp:5
Q_WIDGETS_EXPORT QWidget * qt_button_down
void qt_qpa_set_cursor(QWidget *w, bool force)
Definition qwidget.cpp:5030
int qstrncmp(const char *str1, const char *str2, size_t len)
#define Q_FALLTHROUGH()
#define Q_UNLIKELY(x)
#define Q_FUNC_INFO
#define qApp
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char return DBusMessage return DBusMessage const char return DBusMessage dbus_bool_t return DBusMessage dbus_uint32_t return DBusMessage void
EGLStreamKHR stream
EGLConfig config
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
EGLOutputLayerEXT EGLint attribute
#define QT_RETHROW
#define QT_CATCH(A)
#define QT_TRY
bool qFuzzyIsNull(qfloat16 f) noexcept
Definition qfloat16.h:349
int qRound(qfloat16 d) noexcept
Definition qfloat16.h:327
#define qDebug
[1]
Definition qlogging.h:165
@ QtWarningMsg
Definition qlogging.h:32
#define qWarning
Definition qlogging.h:167
#define qFatal
Definition qlogging.h:169
#define Q_LOGGING_CATEGORY(name,...)
#define qCInfo(category,...)
#define qCWarning(category,...)
#define qCDebug(category,...)
#define Q_STATIC_LOGGING_CATEGORY(name,...)
return ret
static const QMetaObjectPrivate * priv(const uint *data)
QT_BEGIN_NAMESPACE constexpr const T & qMin(const T &a, const T &b)
Definition qminmax.h:19
constexpr const T & qBound(const T &min, const T &val, const T &max)
Definition qminmax.h:23
constexpr const T & qMax(const T &a, const T &b)
Definition qminmax.h:21
@ QObjectPrivateVersion
Definition qobject_p.h:61
#define SIGNAL(a)
Definition qobjectdefs.h:53
static bool contains(const QJsonArray &haystack, unsigned needle)
Definition qopengl.cpp:116
GLsizei const GLfloat * v
[13]
GLuint64 GLenum void * handle
GLint GLint GLint GLint GLint x
[0]
GLint GLenum GLsizei GLsizei GLsizei depth
GLenum mode
const GLfloat * m
GLenum GLuint GLint level
GLuint64 key
GLfloat GLfloat GLfloat w
[0]
GLint GLsizei GLsizei height
GLboolean GLboolean GLboolean GLboolean a
[7]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLuint index
[2]
GLboolean r
[2]
GLuint GLuint end
GLenum GLuint id
[7]
GLdouble GLdouble GLdouble GLdouble top
GLenum GLenum GLsizei count
GLdouble GLdouble right
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLenum GLenum GLsizei const GLuint GLboolean enabled
GLfloat GLfloat f
GLint left
GLenum type
GLint GLint bottom
GLenum target
GLbitfield flags
GLboolean enable
GLuint GLsizei const GLchar * message
GLenum GLuint GLintptr offset
GLboolean GLboolean g
GLuint name
GLint first
GLint GLint GLint GLint GLint GLint GLint GLbitfield mask
GLint GLsizei GLsizei GLenum format
GLint y
GLfloat GLfloat GLfloat GLfloat h
GLsizei GLsizei GLchar * source
struct _cl_event * event
GLuint GLenum GLenum transform
GLdouble s
[6]
Definition qopenglext.h:235
GLenum query
GLuint res
const GLubyte * c
GLint void * img
Definition qopenglext.h:233
GLenum array
GLsizei GLfixed GLfixed GLfixed GLfixed const GLubyte * bitmap
GLdouble GLdouble t
Definition qopenglext.h:243
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259
GLsizei const GLchar *const * path
GLuint64EXT * result
[6]
GLfloat GLfloat p
[1]
GLenum cap
static const QRectF boundingRect(const QPointF *points, int pointCount)
static constexpr quint16 currentMajorVersion
\qmltype FileInstancing \inherits Instancing \inqmlmodule QtQuick3D
static qreal position(const QQuickItem *item, QQuickAnchors::Anchor anchorLine)
static QT_BEGIN_NAMESPACE qreal dpr(const QWindow *w)
void forceUpdate(QQuickItem *item)
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
#define Q_ASSERT_X(cond, x, msg)
Definition qrandom.cpp:48
QScopeGuard< typename std::decay< F >::type > qScopeGuard(F &&f)
[qScopeGuard]
Definition qscopeguard.h:60
bool qWidgetShortcutContextMatcher(QObject *object, Qt::ShortcutContext context)
#define qPrintable(string)
Definition qstring.h:1531
static char * toLocal8Bit(char *out, QStringView in, QStringConverter::State *state)
QStyleSheetStyle * qt_styleSheet(QStyle *style)
#define sp
#define fp
QScreen * screen
[1]
Definition main.cpp:29
#define QT_CONFIG(feature)
Q_CORE_EXPORT bool qEnvironmentVariableIsSet(const char *varName) noexcept
Q_CORE_EXPORT int qEnvironmentVariableIntValue(const char *varName, bool *ok=nullptr) noexcept
#define emit
#define Q_UNUSED(x)
unsigned int quint32
Definition qtypes.h:50
unsigned short quint16
Definition qtypes.h:48
int qint32
Definition qtypes.h:49
unsigned int uint
Definition qtypes.h:34
double qreal
Definition qtypes.h:187
unsigned char quint8
Definition qtypes.h:46
ptrdiff_t qintptr
Definition qtypes.h:166
static bool canMapPosition(QWindow *window)
static void unsetCursor(QWidget *w)
Definition qwidget.cpp:5024
static QWidget * keyboardGrb
void q_createNativeChildrenAndSetParent(const QWidget *parentWidget)
Definition qwidget.cpp:1252
Q_WIDGETS_EXPORT QWidgetData * qt_qwidget_data(QWidget *widget)
QString qt_setWindowTitle_helperHelper(const QString &title, const QWidget *widget)
Returns a modified window title with the [*] place holder replaced according to the rules described i...
Definition qwidget.cpp:6008
QDebug operator<<(QDebug debug, const QWidget *widget)
Q_WIDGETS_EXPORT QWidgetPrivate * qt_widget_private(QWidget *widget)
static bool mouseGrabWithCursor
static void sendResizeEvents(QWidget *target)
Definition qwidget.cpp:5204
static void applyCursor(QWidget *w, const QCursor &c)
Definition qwidget.cpp:5018
#define FOCUS_PREV(w)
static bool isEmbedded(const QWindow *w)
Definition qwidget.cpp:6642
static void releaseMouseGrabOfWidget(QWidget *widget)
#define FOCUS_NEXT(w)
static void grabMouseForWidget(QWidget *widget, const QCursor *cursor=nullptr)
QWidget * qt_button_down
static MapToGlobalTransformResult mapToGlobalTransform(const QWidget *w)
static void setAttribute_internal(Qt::WidgetAttribute attribute, bool on, QWidgetData *data, QWidgetPrivate *d)
void qSendWindowChangeToTextureChildrenRecursively(QWidget *widget, QEvent::Type eventType)
static bool qRectIntersects(const QRect &r1, const QRect &r2)
Definition qwidget.cpp:97
QWidgetList focusPath(QWidget *from, QWidget *to, QWidgetPrivate::FocusDirection direction)
QWidget * qt_pressGrab
void qt_qpa_set_cursor(QWidget *w, bool force)
Definition qwidget.cpp:5030
bool q_evaluateRhiConfig(const QWidget *w, QPlatformBackingStoreRhiConfig *outConfig, QSurface::SurfaceType *outType)
Definition qwidget.cpp:1132
static QWindow * grabberWindow(const QWidget *w)
static void fillRegion(QPainter *painter, const QRegion &rgn, const QBrush &brush)
Definition qwidget.cpp:2237
static bool q_evaluateRhiConfigRecursive(const QWidget *w, QPlatformBackingStoreRhiConfig *outConfig, QSurface::SurfaceType *outType)
Definition qwidget.cpp:1106
QWidget * qt_mouseGrb
bool qt_sendSpontaneousEvent(QObject *, QEvent *)
#define QWIDGETSIZE_MAX
Definition qwidget.h:917
const QWidget * qobject_cast< const QWidget * >(const QObject *o)
Definition qwidget.h:791
QWidget * qobject_cast< QWidget * >(QObject *o)
Definition qwidget.h:786
static bool bypassGraphicsProxyWidget(const QWidget *p)
Definition qwidget_p.h:169
Q_GUI_EXPORT QWindowPrivate * qt_window_private(QWindow *window)
Definition qwindow.cpp:3011
QT_BEGIN_NAMESPACE typedef QHash< WId, QWidget * > QWidgetMapper
Definition qwindowdefs.h:68
QList< QWidget * > QWidgetList
Definition qwindowdefs.h:47
static QWindowsDirect2DWindow * nativeWindow(QWindow *window)
static QRect frameGeometry(HWND hwnd, bool topLevel)
const char property[13]
Definition qwizard.cpp:100
const char className[16]
[1]
Definition qwizard.cpp:99
QWidget * win
Definition settings.cpp:6
if(qFloatDistance(a, b)<(1<< 7))
[0]
obj metaObject() -> className()
QList< QWidget * > widgets
[11]
QObject::connect nullptr
QVBoxLayout * layout
QString title
[35]
QRect r1(100, 200, 11, 16)
[0]
QRect r2(QPoint(100, 200), QSize(11, 16))
QGraphicsOpacityEffect * effect
the effect attached to this item
QGraphicsScene scene
[0]
edit isVisible()
QLayoutItem * child
[0]
widget render & pixmap
QPainter painter(this)
[7]
aWidget window() -> setWindowTitle("New Window Title")
[2]
QSizePolicy policy
QNetworkAccessManager manager
QNetworkProxy proxy
[0]
view create()
QJSEngine engine
[0]
qsizetype indexOf(const AT &t, qsizetype from=0) const noexcept
Definition qlist.h:963
\inmodule QtCore
QRect frameStrut
Definition qwidget_p.h:109
uint posIncludesFrame
Definition qwidget_p.h:118
QRect normalGeometry
Definition qwidget_p.h:110
uint opacity
Definition qwidget_p.h:117
QScreen * initialScreen
Definition qwidget_p.h:112
QBackingStore * backingStore
Definition qwidget_p.h:95
short basew
Definition qwidget_p.h:107
QWidgetWindow * window
Definition qwidget_p.h:97
short incw
Definition qwidget_p.h:106
static void cleanup(QWidget *that, QWidgetPrivate *d)
Definition qwidget.cpp:816