Qt 6.x
The Qt SDK
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 "qevent.h"
10#include "qlayout.h"
11#if QT_CONFIG(menu)
12#include "qmenu.h"
13#endif
14#include "qmetaobject.h"
15#include "qpixmap.h"
16#include "qpointer.h"
17#include "qstack.h"
18#include "qstyle.h"
19#include "qstylefactory.h"
20#include "qvariant.h"
21#include "qwidget.h"
22#include "qstyleoption.h"
23#include "qstylehints.h"
24#if QT_CONFIG(accessibility)
25# include "qaccessible.h"
26#endif
27#include <qpa/qplatformwindow.h>
28#include <qpa/qplatformwindow_p.h>
29#include "private/qwidgetwindow_p.h"
30#include "qpainter.h"
31#if QT_CONFIG(tooltip)
32#include "qtooltip.h"
33#endif
34#if QT_CONFIG(whatsthis)
35#include "qwhatsthis.h"
36#endif
37#include "qdebug.h"
38#include "private/qstylesheetstyle_p.h"
39#include "private/qstyle_p.h"
40#include "qfileinfo.h"
41#include "qscopeguard.h"
42#include <QtGui/private/qhighdpiscaling_p.h>
43#include <QtGui/qinputmethod.h>
44
45#if QT_CONFIG(graphicseffect)
46#include <private/qgraphicseffect_p.h>
47#endif
48#include <qbackingstore.h>
49#include <private/qwidgetrepaintmanager_p.h>
50#include <private/qpaintengine_raster_p.h>
51
52#include "qwidget_p.h"
53#include <QtGui/private/qwindow_p.h>
54#if QT_CONFIG(action)
55# include "QtGui/private/qaction_p.h"
56#endif
57#include "qlayout_p.h"
58#if QT_CONFIG(graphicsview)
59#include "QtWidgets/qgraphicsproxywidget.h"
60#include "QtWidgets/qgraphicsscene.h"
61#include "private/qgraphicsproxywidget_p.h"
62#endif
63#include "QtWidgets/qabstractscrollarea.h"
64#include "private/qabstractscrollarea_p.h"
65#include "private/qevent_p.h"
66
67#include "private/qgesturemanager_p.h"
68
69#ifdef QT_KEYPAD_NAVIGATION
70#if QT_CONFIG(tabwidget)
71#include "qtabwidget.h" // Needed in inTabWidget()
72#endif
73#endif // QT_KEYPAD_NAVIGATION
74
75#include "qwindowcontainer_p.h"
76
77#include <sstream>
78
80
81using namespace QNativeInterface::Private;
82using namespace Qt::StringLiterals;
83
84Q_LOGGING_CATEGORY(lcWidgetPainting, "qt.widgets.painting", QtWarningMsg);
85
86static inline bool qRectIntersects(const QRect &r1, const QRect &r2)
87{
88 return (qMax(r1.left(), r2.left()) <= qMin(r1.right(), r2.right()) &&
89 qMax(r1.top(), r2.top()) <= qMin(r1.bottom(), r2.bottom()));
90}
91
92extern bool qt_sendSpontaneousEvent(QObject*, QEvent*); // qapplication.cpp
93
95 : QObjectPrivate(version)
96 , focus_next(nullptr)
97 , focus_prev(nullptr)
98 , focus_child(nullptr)
100 , needsFlush(nullptr)
101 , redirectDev(nullptr)
102 , widgetItem(nullptr)
103 , extraPaintEngine(nullptr)
104 , polished(nullptr)
105 , graphicsEffect(nullptr)
106#if !defined(QT_NO_IM)
107 , imHints(Qt::ImhNone)
108#endif
109#if QT_CONFIG(tooltip)
110 , toolTipDuration(-1)
111#endif
112 , directFontResolveMask(0)
113 , inheritedFontResolveMask(0)
114 , directPaletteResolveMask(0)
115 , inheritedPaletteResolveMask(0)
116 , leftmargin(0)
117 , topmargin(0)
118 , rightmargin(0)
119 , bottommargin(0)
120 , leftLayoutItemMargin(0)
121 , topLayoutItemMargin(0)
122 , rightLayoutItemMargin(0)
123 , bottomLayoutItemMargin(0)
124 , hd(nullptr)
125 , size_policy(QSizePolicy::Preferred, QSizePolicy::Preferred)
126 , fg_role(QPalette::NoRole)
127 , bg_role(QPalette::NoRole)
128 , dirtyOpaqueChildren(1)
129 , isOpaque(0)
130 , retainSizeWhenHiddenChanged(0)
131 , inDirtyList(0)
132 , isScrolled(0)
133 , isMoved(0)
134 , usesDoubleBufferedGLContext(0)
135 , mustHaveWindowHandle(0)
136 , renderToTexture(0)
137 , textureChildSeen(0)
138#ifndef QT_NO_IM
139 , inheritsInputMethodHints(0)
140#endif
141 , renderToTextureReallyDirty(1)
142 , usesRhiFlush(0)
143 , childrenHiddenByWState(0)
144 , childrenShownByExpose(0)
145#if defined(Q_OS_WIN)
146 , noPaintOnScreen(0)
147#endif
148{
149 if (Q_UNLIKELY(!qApp)) {
150 qFatal("QWidget: Must construct a QApplication before a QWidget");
151 return;
152 }
153
154#ifdef QT_BUILD_INTERNAL
155 // Don't check the version parameter in internal builds.
156 // This allows incompatible versions to be loaded, possibly for testing.
157 Q_UNUSED(version);
158#else
159 if (Q_UNLIKELY(version != QObjectPrivateVersion))
160 qFatal("Cannot mix incompatible Qt library (version 0x%x) with this library (version 0x%x)",
161 version, QObjectPrivateVersion);
162#endif
163
164 willBeWidget = true; // used in QObject's ctor
165 memset(high_attributes, 0, sizeof(high_attributes));
166
167#ifdef QWIDGET_EXTRA_DEBUG
168 static int count = 0;
169 qDebug() << "widgets" << ++count;
170#endif
171}
172
173
175{
176 if (widgetItem)
177 widgetItem->wid = nullptr;
178
179 if (extra)
180 deleteExtra();
181}
182
187{
188 Q_Q(QWidget);
189 if (q->children().size() > 0) { // scroll children
190 QPoint pd(dx, dy);
191 QObjectList childObjects = q->children();
192 for (int i = 0; i < childObjects.size(); ++i) { // move all children
193 QWidget *w = qobject_cast<QWidget*>(childObjects.at(i));
194 if (w && !w->isWindow()) {
195 QPoint oldp = w->pos();
196 QRect r(w->pos() + pd, w->size());
197 w->data->crect = r;
198 if (w->testAttribute(Qt::WA_WState_Created))
199 w->d_func()->setWSGeometry();
200 w->d_func()->setDirtyOpaqueRegion();
201 QMoveEvent e(r.topLeft(), oldp);
203 }
204 }
205 }
206}
207
209{
210 Q_Q(QWidget);
211 if (QWindow *window = q->windowHandle())
212 window->setGeometry(data.crect);
213}
214
216{
217 Q_Q(QWidget);
218 if (q == QGuiApplication::focusObject() || event->type() == QEvent::FocusIn) {
220 QPoint p = q->mapTo(q->topLevelWidget(), QPoint(0,0));
221 t.translate(p.x(), p.y());
225 }
226}
227
228#ifdef QT_KEYPAD_NAVIGATION
229QPointer<QWidget> QWidgetPrivate::editingWidget;
230
238bool QWidget::hasEditFocus() const
239{
240 const QWidget* w = this;
241 while (w->d_func()->extra && w->d_func()->extra->focus_proxy)
242 w = w->d_func()->extra->focus_proxy;
243 return QWidgetPrivate::editingWidget == w;
244}
245
258void QWidget::setEditFocus(bool on)
259{
260 QWidget *f = this;
261 while (f->d_func()->extra && f->d_func()->extra->focus_proxy)
262 f = f->d_func()->extra->focus_proxy;
263
264 if (QWidgetPrivate::editingWidget && QWidgetPrivate::editingWidget != f)
265 QWidgetPrivate::editingWidget->setEditFocus(false);
266
267 if (on && !f->hasFocus())
268 f->setFocus();
269
270 if ((!on && !QWidgetPrivate::editingWidget)
271 || (on && QWidgetPrivate::editingWidget == f)) {
272 return;
273 }
274
275 if (!on && QWidgetPrivate::editingWidget == f) {
276 QWidgetPrivate::editingWidget = 0;
277 QEvent event(QEvent::LeaveEditFocus);
280 } else if (on) {
281 QWidgetPrivate::editingWidget = f;
282 QEvent event(QEvent::EnterEditFocus);
285 }
286}
287#endif
288
314{
315 Q_D(const QWidget);
316 return d->extra && d->extra->autoFillBackground;
317}
318
320{
321 Q_D(QWidget);
322 if (!d->extra)
323 d->createExtra();
324 if (d->extra->autoFillBackground == enabled)
325 return;
326
327 d->extra->autoFillBackground = enabled;
328 d->updateIsOpaque();
329 update();
330 d->updateIsOpaque();
331}
332
783QWidgetMapper *QWidgetPrivate::mapper = nullptr; // widget with wid
784QWidgetSet *QWidgetPrivate::allWidgets = nullptr; // widgets with no wid
785
786
787/*****************************************************************************
788 QWidget member functions
789 *****************************************************************************/
790
791/*
792 Widget state flags:
793 \list
794 \li Qt::WA_WState_Created The widget has a valid winId().
795 \li Qt::WA_WState_Visible The widget is currently visible.
796 \li Qt::WA_WState_Hidden The widget is hidden, i.e. it won't
797 become visible unless you call show() on it. Qt::WA_WState_Hidden
798 implies !Qt::WA_WState_Visible.
799 \li Qt::WA_WState_CompressKeys Compress keyboard events.
800 \li Qt::WA_WState_BlockUpdates Repaints and updates are disabled.
801 \li Qt::WA_WState_InPaintEvent Currently processing a paint event.
802 \li Qt::WA_WState_Reparented The widget has been reparented.
803 \li Qt::WA_WState_ConfigPending A configuration (resize/move) event is pending.
804 \endlist
805*/
806
808{
809 /* this cleans up when the constructor throws an exception */
810 static inline void cleanup(QWidget *that, QWidgetPrivate *d)
811 {
812#ifdef QT_NO_EXCEPTIONS
813 Q_UNUSED(that);
814 Q_UNUSED(d);
815#else
817 if (d->focus_next != that) {
818 if (d->focus_next)
819 d->focus_next->d_func()->focus_prev = d->focus_prev;
820 if (d->focus_prev)
821 d->focus_prev->d_func()->focus_next = d->focus_next;
822 }
823#endif
824 }
825};
826
854{
855 QT_TRY {
856 d_func()->init(parent, f);
857 } QT_CATCH(...) {
858 QWidgetExceptionCleaner::cleanup(this, d_func());
860 }
861}
862
863
868{
869 Q_D(QWidget);
870 QT_TRY {
871 d->init(parent, f);
872 } QT_CATCH(...) {
873 QWidgetExceptionCleaner::cleanup(this, d_func());
875 }
876}
877
882{
883 return QInternal::Widget;
884}
885
886
887//### w is a "this" ptr, passed as a param because QWorkspace needs special logic
889{
890 bool customize = (flags & (Qt::CustomizeWindowHint
898
900
901 if ((type == Qt::Widget || type == Qt::SubWindow) && w && !w->parent()) {
903 flags |= Qt::Window;
904 }
905
907 // modify window flags to make them consistent.
908 // Only enable this on non-Mac platforms. Since the old way of doing this would
909 // interpret WindowSystemMenuHint as a close button and we can't change that behavior
910 // we can't just add this in.
912# ifdef Q_OS_WIN
913 && type != Qt::Dialog // QTBUG-2027, allow for menu-less dialogs.
914# endif
915 ) {
918 flags &= ~Qt::FramelessWindowHint;
919 }
920 } else if (customize && !(flags & Qt::FramelessWindowHint)) {
921 // if any of the window hints that affect the titlebar are set
922 // and the window is supposed to have frame, we add a titlebar
923 // and system menu by default.
926 }
927 if (!customize) { // don't modify window flags if the user explicitly set them.
929 if (type != Qt::Dialog && type != Qt::Sheet && type != Qt::Tool)
931 }
932 if (w->testAttribute(Qt::WA_TransparentForMouseEvents))
934}
935
936void QWidgetPrivate::init(QWidget *parentWidget, Qt::WindowFlags f)
937{
938 Q_Q(QWidget);
939 isWidget = true;
940 wasWidget = true;
941
942 Q_ASSERT_X(q != parentWidget, Q_FUNC_INFO, "Cannot parent a QWidget to itself");
943
944 if (Q_UNLIKELY(!qobject_cast<QApplication *>(QCoreApplication::instance())))
945 qFatal("QWidget: Cannot create a QWidget without QApplication");
946
948 if (allWidgets)
950
951 q->data = &data;
952
953#if QT_CONFIG(thread)
954 if (!parent) {
955 Q_ASSERT_X(q->thread() == qApp->thread(), "QWidget",
956 "Widgets must be created in the GUI thread.");
957 }
958#endif
959
960 data.fstrut_dirty = true;
961
962 data.winid = 0;
963 data.widget_attributes = 0;
964 data.window_flags = f;
965 data.window_state = 0;
966 data.focus_policy = 0;
967 data.context_menu_policy = Qt::DefaultContextMenu;
968 data.window_modality = Qt::NonModal;
969
970 data.sizehint_forced = 0;
971 data.is_closing = false;
972 data.in_show = 0;
973 data.in_set_window_state = 0;
974 data.in_destructor = false;
975
976 // Widgets with Qt::MSWindowsOwnDC (typically QGLWidget) must have a window handle.
977 if (f & Qt::MSWindowsOwnDC) {
979 q->setAttribute(Qt::WA_NativeWindow);
980 }
981
982 q->setAttribute(Qt::WA_QuitOnClose); // might be cleared in adjustQuitOnCloseAttribute()
984
986 q->setAttribute(Qt::WA_WState_Hidden);
987
988 //give potential windows a bigger "pre-initial" size; create() will give them a new size later
989 data.crect = parentWidget ? QRect(0,0,100,30) : QRect(0,0,640,480);
991
993 q->create();
994 else if (parentWidget)
995 q->setParent(parentWidget, data.window_flags);
996 else {
997 adjustFlags(data.window_flags, q);
999 // opaque system background?
1000 const QBrush &background = q->palette().brush(QPalette::Window);
1001 setOpaque(q->isWindow() && background.style() != Qt::NoBrush && background.isOpaque());
1002 }
1003 data.fnt = QFont(data.fnt, q);
1004
1005 q->setAttribute(Qt::WA_PendingMoveEvent);
1006 q->setAttribute(Qt::WA_PendingResizeEvent);
1007
1010
1014
1015 extraPaintEngine = nullptr;
1016}
1017
1019{
1020 Q_Q(QWidget);
1021 q->create(0, true, true);
1022 for (int i = 0; i < children.size(); ++i) {
1024 if (child && !child->isHidden() && !child->isWindow() && !child->testAttribute(Qt::WA_WState_Created))
1025 child->d_func()->createRecursively();
1026 }
1027}
1028
1030{
1032 if (QTLWExtra *x = maybeTopData()) {
1033 if (x->window != nullptr || mode == WindowHandleMode::Direct)
1034 return x->window;
1035 }
1036 }
1038 if (auto nativeParent = q_func()->nativeParentWidget()) {
1039 if (auto window = nativeParent->windowHandle())
1040 return window;
1041 }
1042 }
1044 if (auto topLevel = q_func()->topLevelWidget()) {
1045 if (auto window = topLevel ->windowHandle())
1046 return window;
1047 }
1048 }
1049 return nullptr;
1050}
1051
1059{
1061}
1062
1064{
1065#if QT_CONFIG(graphicsview)
1066 // embedded widgets never have a screen associated, let QWidget::screen fall back to toplevel
1067 if (nearestGraphicsProxyWidget(q_func()))
1068 return nullptr;
1069#endif
1071 return window->screen();
1072 return nullptr;
1073}
1074
1075// finds the first rhiconfig in the hierarchy that has enable==true
1077{
1079 if (config.isEnabled()) {
1080 if (outConfig)
1081 *outConfig = config;
1082 if (outType)
1084 return true;
1085 }
1086 for (const QObject *child : w->children()) {
1087 if (const QWidget *childWidget = qobject_cast<const QWidget *>(child)) {
1088 if (q_evaluateRhiConfigRecursive(childWidget, outConfig, outType))
1089 return true;
1090 }
1091 }
1092 return false;
1093}
1094
1096{
1097 // First, check env.vars. or other means that force the usage of rhi-based
1098 // flushing with a specific graphics API. This takes precedence over what
1099 // the widgets themselves declare. This is global, applying to all
1100 // top-levels.
1101 if (QBackingStoreRhiSupport::checkForceRhi(outConfig, outType)) {
1102 qCDebug(lcWidgetPainting) << "Tree with root" << w << "evaluated to forced flushing with QRhi";
1103 return true;
1104 }
1105
1106 // Otherwise, check the widget hierarchy to see if there is a child (or
1107 // ourselves) that declare the need for rhi-based composition.
1108 if (q_evaluateRhiConfigRecursive(w, outConfig, outType)) {
1109 qCDebug(lcWidgetPainting) << "Tree with root" << w << "evaluates to flushing with QRhi";
1110 return true;
1111 }
1112
1113 return false;
1114}
1115
1116// ### fixme: Qt 6: Remove parameter window from QWidget::create()
1117
1129void QWidget::create(WId window, bool initializeWindow, bool destroyOldWindow)
1130{
1131 Q_UNUSED(initializeWindow);
1132 Q_UNUSED(destroyOldWindow);
1133
1134 Q_D(QWidget);
1135 if (Q_UNLIKELY(window))
1136 qWarning("QWidget::create(): Parameter 'window' does not have any effect.");
1138 return;
1139
1140 if (d->data.in_destructor)
1141 return;
1142
1144 Qt::WindowFlags &flags = data->window_flags;
1145
1146 if ((type == Qt::Widget || type == Qt::SubWindow) && !parentWidget()) {
1147 type = Qt::Window;
1148 flags |= Qt::Window;
1149 }
1150
1151 if (QWidget *parent = parentWidget()) {
1152 if (type & Qt::Window) {
1153 if (!parent->testAttribute(Qt::WA_WState_Created))
1154 parent->createWinId();
1155 } else if (testAttribute(Qt::WA_NativeWindow) && !parent->internalWinId()
1157 // We're about to create a native child widget that doesn't have a native parent;
1158 // enforce a native handle for the parent unless the Qt::WA_DontCreateNativeAncestors
1159 // attribute is set.
1160 d->createWinId();
1161 // Nothing more to do.
1164 return;
1165 }
1166 }
1167
1168
1169 static const bool paintOnScreenEnv = qEnvironmentVariableIntValue("QT_ONSCREEN_PAINT") > 0;
1170 if (paintOnScreenEnv)
1172
1175
1176 d->updateIsOpaque();
1177
1178 setAttribute(Qt::WA_WState_Created); // set created flag
1179 d->create();
1180
1181 // A real toplevel window needs a paint manager
1182 if (isWindow() && windowType() != Qt::Desktop)
1183 d->topData()->repaintManager.reset(new QWidgetRepaintManager(this));
1184
1185 d->setModal_sys();
1186
1189
1190 // need to force the resting of the icon after changing parents
1192 d->setWindowIcon_sys();
1193
1194 if (isWindow() && !d->topData()->iconText.isEmpty())
1195 d->setWindowIconText_helper(d->topData()->iconText);
1196 if (isWindow() && !d->topData()->caption.isEmpty())
1197 d->setWindowTitle_helper(d->topData()->caption);
1198 if (isWindow() && !d->topData()->filePath.isEmpty())
1199 d->setWindowFilePath_helper(d->topData()->filePath);
1200 if (windowType() != Qt::Desktop) {
1201 d->updateSystemBackground();
1202
1204 d->setWindowIcon_sys();
1205 }
1206
1207 // Frame strut update needed in cases where there are native widgets such as QGLWidget,
1208 // as those force native window creation on their ancestors before they are shown.
1209 // If the strut is not updated, any subsequent move of the top level window before show
1210 // will cause window frame to be ignored when positioning the window.
1211 // Note that this only helps on platforms that handle window creation synchronously.
1212 d->updateFrameStrut();
1213}
1214
1216{
1217 QObjectList children = parentWidget->children();
1218 for (int i = 0; i < children.size(); i++) {
1219 if (children.at(i)->isWidgetType()) {
1220 const QWidget *childWidget = qobject_cast<const QWidget *>(children.at(i));
1221 if (childWidget) { // should not be necessary
1222 if (childWidget->testAttribute(Qt::WA_NativeWindow)) {
1223 if (!childWidget->internalWinId())
1224 childWidget->winId();
1225 if (childWidget->windowHandle()) {
1226 if (childWidget->isWindow()) {
1227 childWidget->windowHandle()->setTransientParent(parentWidget->window()->windowHandle());
1228 } else {
1229 childWidget->windowHandle()->setParent(childWidget->nativeParentWidget()->windowHandle());
1230 }
1231 }
1232 } else {
1234 }
1235 }
1236 }
1237 }
1238
1239}
1240
1242{
1243 Q_Q(QWidget);
1244
1245 if (!q->testAttribute(Qt::WA_NativeWindow) && !q->isWindow())
1246 return; // we only care about real toplevels
1247
1249 // topData() ensures the extra is created but does not ensure 'window' is non-null
1250 // in case the extra was already valid.
1251 if (!win) {
1254 win = topData()->window;
1255 }
1256
1257 const auto dynamicPropertyNames = q->dynamicPropertyNames();
1258 for (const QByteArray &propertyName : dynamicPropertyNames) {
1259 if (!qstrncmp(propertyName, "_q_platform_", 12))
1260 win->setProperty(propertyName, q->property(propertyName));
1261 }
1262
1263 Qt::WindowFlags &flags = data.window_flags;
1264
1265#if defined(Q_OS_IOS) || defined(Q_OS_TVOS)
1266 if (q->testAttribute(Qt::WA_ContentsMarginsRespectsSafeArea))
1268#endif
1269
1270 if (q->testAttribute(Qt::WA_ShowWithoutActivating))
1271 win->setProperty("_q_showWithoutActivating", QVariant(true));
1272 if (q->testAttribute(Qt::WA_MacAlwaysShowToolWindow))
1273 win->setProperty("_q_macAlwaysShowToolWindow", QVariant(true));
1274 setNetWmWindowTypes(true); // do nothing if none of WA_X11NetWmWindowType* is set
1275 win->setFlags(flags);
1277 if (q->testAttribute(Qt::WA_Moved)
1279 win->setGeometry(q->geometry());
1280 else
1281 win->resize(q->size());
1282 if (win->isTopLevel()) {
1283 QScreen *targetScreen = topData()->initialScreen;
1284 topData()->initialScreen = nullptr;
1285 if (!targetScreen) {
1286 targetScreen = q->windowType() != Qt::Desktop
1287 ? q->screen() : nullptr;
1288 }
1289 win->setScreen(targetScreen);
1290 }
1291
1292 QSurfaceFormat format = win->requestedFormat();
1293 if ((flags & Qt::Window) && win->surfaceType() != QSurface::OpenGLSurface
1294 && q->testAttribute(Qt::WA_TranslucentBackground)) {
1295 format.setAlphaBufferSize(8);
1296 }
1297 win->setFormat(format);
1298
1299 if (QWidget *nativeParent = q->nativeParentWidget()) {
1300 if (nativeParent->windowHandle()) {
1301 if (flags & Qt::Window) {
1302 win->setTransientParent(nativeParent->window()->windowHandle());
1303 win->setParent(nullptr);
1304 } else {
1305 win->setTransientParent(nullptr);
1306 win->setParent(nativeParent->windowHandle());
1307 }
1308 }
1309 }
1310
1313
1314 if (q->windowType() != Qt::Desktop || q->testAttribute(Qt::WA_NativeWindow)) {
1315 win->create();
1316 // Enable nonclient-area events for QDockWidget and other NonClientArea-mouse event processing.
1317 if (QPlatformWindow *platformWindow = win->handle())
1318 platformWindow->setFrameStrutEventsEnabled(true);
1319 }
1320
1321 data.window_flags = win->flags();
1322 if (!win->isTopLevel()) // In a Widget world foreign windows can only be top level
1323 data.window_flags &= ~Qt::ForeignWindow;
1324
1325#if QT_CONFIG(xcb)
1326 if (!topData()->role.isNull()) {
1327 if (auto *xcbWindow = dynamic_cast<QXcbWindow*>(win->handle()))
1328 xcbWindow->setWindowRole(topData()->role);
1329 }
1330#endif
1331
1332 QBackingStore *store = q->backingStore();
1333 usesRhiFlush = false;
1334
1335 if (!store) {
1336 if (q->windowType() != Qt::Desktop) {
1337 if (q->isWindow()) {
1338 q->setBackingStore(new QBackingStore(win));
1342 }
1343 } else {
1344 q->setAttribute(Qt::WA_PaintOnScreen, true);
1345 }
1346 } else if (win->handle()) {
1347 usesRhiFlush = q_evaluateRhiConfig(q, nullptr, nullptr);
1348 }
1349
1351
1352 if (win->handle()) {
1353 WId id = win->winId();
1354 // See the QPlatformWindow::winId() documentation
1355 Q_ASSERT(id != WId(0));
1356 setWinId(id);
1357 }
1358
1359 // Check children and create windows for them if necessary
1361
1362 if (extra && !extra->mask.isEmpty())
1363 setMask_sys(extra->mask);
1364
1365 if (data.crect.width() == 0 || data.crect.height() == 0) {
1366 q->setAttribute(Qt::WA_OutsideWSRange, true);
1367 } else if (q->isVisible()) {
1368 // If widget is already shown, set window visible, too
1369 win->setNativeWindowVisibility(true);
1370 }
1371}
1372
1373#ifdef Q_OS_WIN
1374static const char activeXNativeParentHandleProperty[] = "_q_embedded_native_parent_handle";
1375#endif
1376
1378{
1379 Q_Q(QWidget);
1380 if (!extra->topextra->window && (q->testAttribute(Qt::WA_NativeWindow) || q->isWindow())) {
1381 extra->topextra->window = new QWidgetWindow(q);
1382 if (extra->minw || extra->minh)
1383 extra->topextra->window->setMinimumSize(QSize(extra->minw, extra->minh));
1384 if (extra->maxw != QWIDGETSIZE_MAX || extra->maxh != QWIDGETSIZE_MAX)
1385 extra->topextra->window->setMaximumSize(QSize(extra->maxw, extra->maxh));
1386 if (extra->topextra->opacity != 255 && q->isWindow())
1387 extra->topextra->window->setOpacity(qreal(extra->topextra->opacity) / qreal(255));
1388
1389 const bool isTipLabel = q->inherits("QTipLabel");
1390 const bool isAlphaWidget = !isTipLabel && q->inherits("QAlphaWidget");
1391#ifdef Q_OS_WIN
1392 // Pass on native parent handle for Widget embedded into Active X.
1393 const QVariant activeXNativeParentHandle = q->property(activeXNativeParentHandleProperty);
1394 if (activeXNativeParentHandle.isValid())
1395 extra->topextra->window->setProperty(activeXNativeParentHandleProperty, activeXNativeParentHandle);
1396 if (isTipLabel || isAlphaWidget)
1397 extra->topextra->window->setProperty("_q_windowsDropShadow", QVariant(true));
1398#endif
1399 if (isTipLabel || isAlphaWidget || q->inherits("QRollEffect"))
1401
1403 }
1404
1405}
1406
1415{
1416 Q_D(QWidget);
1417 d->data.in_destructor = true;
1418
1419#if defined (QT_CHECK_STATE)
1421 qWarning("QWidget: %s (%s) deleted while being painted", className(), name());
1422#endif
1423
1424#ifndef QT_NO_GESTURES
1426 // \forall Qt::GestureType type : ungrabGesture(type) (inlined)
1427 for (auto it = d->gestureContext.keyBegin(), end = d->gestureContext.keyEnd(); it != end; ++it)
1428 manager->cleanupCachedGestures(this, *it);
1429 }
1430 d->gestureContext.clear();
1431#endif
1432
1433#ifndef QT_NO_ACTION
1434 // remove all actions from this widget
1435 for (auto action : std::as_const(d->actions)) {
1436 QActionPrivate *apriv = action->d_func();
1437 apriv->associatedObjects.removeAll(this);
1438 }
1439 d->actions.clear();
1440#endif
1441
1442#ifndef QT_NO_SHORTCUT
1443 // Remove all shortcuts grabbed by this
1444 // widget, unless application is closing
1446 QGuiApplicationPrivate::instance()->shortcutMap.removeShortcut(0, this, QKeySequence());
1447#endif
1448
1449 // delete layout while we still are a valid widget
1450 delete d->layout;
1451 d->layout = nullptr;
1452 // Remove myself from focus list
1453
1454 Q_ASSERT(d->focus_next->d_func()->focus_prev == this);
1455 Q_ASSERT(d->focus_prev->d_func()->focus_next == this);
1456
1457 if (d->focus_next != this) {
1458 d->focus_next->d_func()->focus_prev = d->focus_prev;
1459 d->focus_prev->d_func()->focus_next = d->focus_next;
1460 d->focus_next = d->focus_prev = nullptr;
1461 }
1462
1463
1464 QT_TRY {
1465#if QT_CONFIG(graphicsview)
1466 const QWidget* w = this;
1467 while (w->d_func()->extra && w->d_func()->extra->focus_proxy)
1468 w = w->d_func()->extra->focus_proxy;
1469 QWidget *window = w->window();
1470 QWExtra *e = window ? window->d_func()->extra.get() : nullptr ;
1471 if (!e || !e->proxyWidget || (w->parentWidget() && w->parentWidget()->d_func()->focus_child == this))
1472#endif
1473 clearFocus();
1474 } QT_CATCH(...) {
1475 // swallow this problem because we are in a destructor
1476 }
1477
1478 d->setDirtyOpaqueRegion();
1479
1480 if (isWindow() && isVisible() && internalWinId()) {
1481 QT_TRY {
1482 d->close();
1483 } QT_CATCH(...) {
1484 // if we're out of memory, at least hide the window.
1485 QT_TRY {
1486 hide();
1487 } QT_CATCH(...) {
1488 // and if that also doesn't work, then give up
1489 }
1490 }
1491 } else if (isVisible()) {
1492 qApp->d_func()->sendSyntheticEnterLeave(this);
1493 }
1494
1495 if (QWidgetRepaintManager *repaintManager = d->maybeRepaintManager()) {
1496 repaintManager->removeDirtyWidget(this);
1498 repaintManager->removeStaticWidget(this);
1499 }
1500
1501 delete d->needsFlush;
1502 d->needsFlush = nullptr;
1503
1504 // The next 20 lines are duplicated from QObject, but required here
1505 // since QWidget deletes is children itself
1506 bool blocked = d->blockSig;
1507 d->blockSig = 0; // unblock signals so we always emit destroyed()
1508
1509 if (d->isSignalConnected(0)) {
1510 QT_TRY {
1511 emit destroyed(this);
1512 } QT_CATCH(...) {
1513 // all the signal/slots connections are still in place - if we don't
1514 // quit now, we will crash pretty soon.
1515 qWarning("Detected an unexpected exception in ~QWidget while emitting destroyed().");
1516 QT_RETHROW;
1517 }
1518 }
1519
1520 if (d->declarativeData) {
1521 d->wasDeleted = true; // needed, so that destroying the declarative data does the right thing
1523 QAbstractDeclarativeData::destroyed(d->declarativeData, this);
1524 d->declarativeData = nullptr; // don't activate again in ~QObject
1525 d->wasDeleted = false;
1526 }
1527
1528 d->blockSig = blocked;
1529
1530 if (!d->children.isEmpty())
1531 d->deleteChildren();
1532
1534
1535 QT_TRY {
1536 destroy(); // platform-dependent cleanup
1537 } QT_CATCH(...) {
1538 // if this fails we can't do anything about it but at least we are not allowed to throw.
1539 }
1541
1542 if (QWidgetPrivate::allWidgets) // might have been deleted by ~QApplication
1544
1545 QT_TRY {
1548 } QT_CATCH(const std::exception&) {
1549 // if this fails we can't do anything about it but at least we are not allowed to throw.
1550 }
1551
1552#if QT_CONFIG(graphicseffect)
1553 delete d->graphicsEffect;
1554#endif
1555
1556 d->isWidget = false;
1557}
1558
1559int QWidgetPrivate::instanceCounter = 0; // Current number of widget instances
1560int QWidgetPrivate::maxInstances = 0; // Maximum number of widget instances
1561
1562void QWidgetPrivate::setWinId(WId id) // set widget identifier
1563{
1564 Q_Q(QWidget);
1565 if (mapper && data.winid) {
1566 mapper->remove(data.winid);
1567 }
1568
1569 const WId oldWinId = data.winid;
1570
1571 data.winid = id;
1572 if (mapper && id) {
1573 mapper->insert(data.winid, q);
1574 }
1575
1576 if (oldWinId != id) {
1579 }
1580}
1581
1583{
1584 if (!extra)
1585 createExtra();
1586 if (!extra->topextra) {
1587 extra->topextra = std::make_unique<QTLWExtra>();
1588 QTLWExtra* x = extra->topextra.get();
1589 x->backingStore = nullptr;
1590 x->sharedPainter = nullptr;
1591 x->incw = x->inch = 0;
1592 x->basew = x->baseh = 0;
1593 x->frameStrut.setCoords(0, 0, 0, 0);
1594 x->normalGeometry = QRect(0,0,-1,-1);
1595 x->savedFlags = { };
1596 x->opacity = 255;
1597 x->posIncludesFrame = 0;
1598 x->sizeAdjusted = false;
1599 x->embedded = 0;
1600 x->window = nullptr;
1601 x->initialScreen = nullptr;
1602
1603#ifdef QWIDGET_EXTRA_DEBUG
1604 static int count = 0;
1605 qDebug() << "tlextra" << ++count;
1606#endif
1607 }
1608}
1609
1616{
1617 if (!extra) { // if not exists
1618 extra = std::make_unique<QWExtra>();
1619 extra->glContext = nullptr;
1620#if QT_CONFIG(graphicsview)
1621 extra->proxyWidget = nullptr;
1622#endif
1623 extra->minw = 0;
1624 extra->minh = 0;
1625 extra->maxw = QWIDGETSIZE_MAX;
1626 extra->maxh = QWIDGETSIZE_MAX;
1627 extra->customDpiX = 0;
1628 extra->customDpiY = 0;
1629 extra->explicitMinSize = 0;
1630 extra->explicitMaxSize = 0;
1631 extra->autoFillBackground = 0;
1632 extra->nativeChildrenForced = 0;
1633 extra->inRenderWithPainter = 0;
1634 extra->hasWindowContainer = false;
1635 extra->hasMask = 0;
1637#ifdef QWIDGET_EXTRA_DEBUG
1638 static int count = 0;
1639 qDebug() << "extra" << ++count;
1640#endif
1641 }
1642}
1643
1645{
1646}
1647
1654{
1655 if (extra) { // if exists
1657#ifndef QT_NO_STYLE_STYLESHEET
1658 // dereference the stylesheet style
1660 proxy->deref();
1661#endif
1662 if (extra->topextra) {
1664 // extra->topextra->backingStore destroyed in QWidgetPrivate::deleteTLSysExtra()
1665 }
1666 // extra->xic destroyed in QWidget::destroy()
1667 extra.reset();
1668 }
1669}
1670
1672{
1673}
1674
1676{
1677 QTLWExtra *topData = d->topData();
1678
1679 delete topData->backingStore;
1680 topData->backingStore = nullptr;
1681}
1682
1684{
1685 if (extra && extra->topextra) {
1686 //the qplatformbackingstore may hold a reference to the window, so the backingstore
1687 //needs to be deleted first.
1688
1689 extra->topextra->repaintManager.reset(nullptr);
1690 deleteBackingStore(this);
1691 extra->topextra->widgetTextures.clear();
1692
1693 //the toplevel might have a context with a "qglcontext associated with it. We need to
1694 //delete the qglcontext before we delete the qplatformopenglcontext.
1695 //One unfortunate thing about this is that we potentially create a glContext just to
1696 //delete it straight afterwards.
1697 if (extra->topextra->window) {
1698 extra->topextra->window->destroy();
1699 }
1700 delete extra->topextra->window;
1701 extra->topextra->window = nullptr;
1702
1703 }
1704}
1705
1706/*
1707 Returns \c region of widgets above this which overlap with
1708 \a rect, which is in parent's coordinate system (same as crect).
1709*/
1710
1711QRegion QWidgetPrivate::overlappedRegion(const QRect &rect, bool breakAfterFirst) const
1712{
1713 Q_Q(const QWidget);
1714
1715 const QWidget *w = q;
1716 QRect r = rect;
1717 QPoint p;
1718 QRegion region;
1719 while (w) {
1720 if (w->isWindow())
1721 break;
1722 QWidgetPrivate *pd = w->parentWidget()->d_func();
1723 bool above = false;
1724 for (int i = 0; i < pd->children.size(); ++i) {
1725 QWidget *sibling = qobject_cast<QWidget *>(pd->children.at(i));
1726 if (!sibling || !sibling->isVisible() || sibling->isWindow())
1727 continue;
1728 if (!above) {
1729 above = (sibling == w);
1730 continue;
1731 }
1732
1733 const QRect siblingRect = sibling->d_func()->effectiveRectFor(sibling->data->crect);
1734 if (qRectIntersects(siblingRect, r)) {
1735 const auto &siblingExtra = sibling->d_func()->extra;
1736 if (siblingExtra && siblingExtra->hasMask && !sibling->d_func()->graphicsEffect
1737 && !siblingExtra->mask.translated(sibling->data->crect.topLeft()).intersects(r)) {
1738 continue;
1739 }
1740 region += siblingRect.translated(-p);
1741 if (breakAfterFirst)
1742 break;
1743 }
1744 }
1745 w = w->parentWidget();
1746 r.translate(pd->data.crect.topLeft());
1747 p += pd->data.crect.topLeft();
1748 }
1749 return region;
1750}
1751
1753{
1754 if (shouldPaintOnScreen()) {
1756 dirty = QRegion();
1757 } else if (QWidgetRepaintManager *repaintManager = maybeRepaintManager()) {
1758 repaintManager->sync();
1759 }
1760}
1761
1763{
1764 if (shouldPaintOnScreen())
1765 paintOnScreen(region);
1766 else if (QWidgetRepaintManager *repaintManager = maybeRepaintManager()) {
1767 repaintManager->sync(q_func(), region);
1768 }
1769}
1770
1772{
1773 if (data.in_destructor)
1774 return;
1775
1777 return;
1778
1779 Q_Q(QWidget);
1780 if (q->testAttribute(Qt::WA_StaticContents)) {
1781 if (!extra)
1782 createExtra();
1783 extra->staticContentsSize = data.crect.size();
1784 }
1785
1786 QPaintEngine *engine = q->paintEngine();
1787
1788 // QGLWidget does not support partial updates if:
1789 // 1) The context is double buffered
1790 // 2) The context is single buffered and auto-fill background is enabled.
1791 const bool noPartialUpdateSupport = (engine && (engine->type() == QPaintEngine::OpenGL
1792 || engine->type() == QPaintEngine::OpenGL2))
1793 && (usesDoubleBufferedGLContext || q->autoFillBackground());
1794 QRegion toBePainted(noPartialUpdateSupport ? q->rect() : rgn);
1795
1796 toBePainted &= clipRect();
1797 clipToEffectiveMask(toBePainted);
1798 if (toBePainted.isEmpty())
1799 return; // Nothing to repaint.
1800
1802
1803 if (Q_UNLIKELY(q->paintingActive()))
1804 qWarning("QWidget::repaint: It is dangerous to leave painters active on a widget outside of the PaintEvent");
1805}
1806
1808{
1809 Q_Q(QWidget);
1810
1811 if (enable && !q->isWindow() && q->parentWidget() && !q->parentWidget()->updatesEnabled())
1812 return; // nothing we can do
1813
1814 if (enable != q->testAttribute(Qt::WA_UpdatesDisabled))
1815 return; // nothing to do
1816
1817 q->setAttribute(Qt::WA_UpdatesDisabled, !enable);
1818 if (enable)
1819 q->update();
1820
1822 for (int i = 0; i < children.size(); ++i) {
1824 if (w && !w->isWindow() && !w->testAttribute(attribute))
1825 w->d_func()->setUpdatesEnabled_helper(enable);
1826 }
1827}
1828
1837{
1838 Q_Q(QWidget);
1839 // Propagate a new inherited mask to all children.
1840#if QT_CONFIG(graphicsview)
1841 if (!q->parentWidget() && extra && extra->proxyWidget) {
1842 QGraphicsProxyWidget *p = extra->proxyWidget;
1843 inheritedPaletteResolveMask = p->d_func()->inheritedPaletteResolveMask | p->palette().resolveMask();
1844 } else
1845#endif // QT_CONFIG(graphicsview)
1846 if (q->isWindow() && !q->testAttribute(Qt::WA_WindowPropagation)) {
1848 }
1849
1850 directPaletteResolveMask = data.pal.resolveMask();
1852
1853 const bool useStyleSheetPropagationInWidgetStyles =
1855
1858 for (int i = 0; i < children.size(); ++i) {
1860 if (w && (!w->testAttribute(Qt::WA_StyleSheet) || useStyleSheetPropagationInWidgetStyles)
1861 && (!w->isWindow() || w->testAttribute(Qt::WA_WindowPropagation))) {
1862 QWidgetPrivate *wd = w->d_func();
1864 wd->resolvePalette();
1865 }
1866 }
1867}
1868
1869/*
1870 Returns the widget's clipping rectangle.
1871*/
1873{
1874 Q_Q(const QWidget);
1875 const QWidget * w = q;
1876 if (!w->isVisible())
1877 return QRect();
1878 QRect r = effectiveRectFor(q->rect());
1879 int ox = 0;
1880 int oy = 0;
1881 while (w
1882 && w->isVisible()
1883 && !w->isWindow()
1884 && w->parentWidget()) {
1885 ox -= w->x();
1886 oy -= w->y();
1887 w = w->parentWidget();
1888 r &= QRect(ox, oy, w->width(), w->height());
1889 }
1890 return r;
1891}
1892
1893/*
1894 Returns the widget's clipping region (without siblings).
1895*/
1897{
1898 Q_Q(const QWidget);
1899 if (!q->isVisible())
1900 return QRegion();
1901 QRegion r(q->rect());
1902 const QWidget * w = q;
1903 const QWidget *ignoreUpTo;
1904 int ox = 0;
1905 int oy = 0;
1906 while (w
1907 && w->isVisible()
1908 && !w->isWindow()
1909 && w->parentWidget()) {
1910 ox -= w->x();
1911 oy -= w->y();
1912 ignoreUpTo = w;
1913 w = w->parentWidget();
1914 r &= QRegion(ox, oy, w->width(), w->height());
1915
1916 int i = 0;
1917 while(w->d_func()->children.at(i++) != static_cast<const QObject *>(ignoreUpTo))
1918 ;
1919 for ( ; i < w->d_func()->children.size(); ++i) {
1920 if (QWidget *sibling = qobject_cast<QWidget *>(w->d_func()->children.at(i))) {
1921 if (sibling->isVisible() && !sibling->isWindow()) {
1922 QRect siblingRect(ox+sibling->x(), oy+sibling->y(),
1923 sibling->width(), sibling->height());
1924 if (qRectIntersects(siblingRect, q->rect()))
1925 r -= QRegion(siblingRect);
1926 }
1927 }
1928 }
1929 }
1930 return r;
1931}
1932
1933void QWidgetPrivate::setSystemClip(QPaintEngine *paintEngine, qreal devicePixelRatio, const QRegion &region)
1934{
1935// Transform the system clip region from device-independent pixels to device pixels
1936 QTransform scaleTransform;
1937 scaleTransform.scale(devicePixelRatio, devicePixelRatio);
1938
1939 paintEngine->d_func()->baseSystemClip = region;
1940 paintEngine->d_func()->setSystemTransform(scaleTransform);
1941
1942}
1943
1944#if QT_CONFIG(graphicseffect)
1945void QWidgetPrivate::invalidateGraphicsEffectsRecursively()
1946{
1947 Q_Q(QWidget);
1948 QWidget *w = q;
1949 do {
1950 if (w->graphicsEffect()) {
1951 QWidgetEffectSourcePrivate *sourced =
1952 static_cast<QWidgetEffectSourcePrivate *>(w->graphicsEffect()->source()->d_func());
1953 if (!sourced->updateDueToGraphicsEffect)
1954 w->graphicsEffect()->source()->d_func()->invalidateCache();
1955 }
1956 w = w->parentWidget();
1957 } while (w);
1958}
1959#endif // QT_CONFIG(graphicseffect)
1960
1962{
1963 Q_Q(QWidget);
1964
1965 dirtyOpaqueChildren = true;
1966
1967#if QT_CONFIG(graphicseffect)
1968 invalidateGraphicsEffectsRecursively();
1969#endif // QT_CONFIG(graphicseffect)
1970
1971 if (q->isWindow())
1972 return;
1973
1974 QWidget *parent = q->parentWidget();
1975 if (!parent)
1976 return;
1977
1978 // TODO: instead of setting dirtyflag, manipulate the dirtyregion directly?
1979 QWidgetPrivate *pd = parent->d_func();
1980 if (!pd->dirtyOpaqueChildren)
1982}
1983
1985{
1987 return opaqueChildren;
1988
1989 QWidgetPrivate *that = const_cast<QWidgetPrivate*>(this);
1990 that->opaqueChildren = QRegion();
1991
1992 for (int i = 0; i < children.size(); ++i) {
1994 if (!child || !child->isVisible() || child->isWindow())
1995 continue;
1996
1997 const QPoint offset = child->geometry().topLeft();
1998 QWidgetPrivate *childd = child->d_func();
1999 QRegion r = childd->isOpaque ? child->rect() : childd->getOpaqueChildren();
2000 if (childd->extra && childd->extra->hasMask)
2001 r &= childd->extra->mask;
2002 if (r.isEmpty())
2003 continue;
2004 r.translate(offset);
2005 that->opaqueChildren += r;
2006 }
2007
2008 that->opaqueChildren &= q_func()->rect();
2009 that->dirtyOpaqueChildren = false;
2010
2011 return that->opaqueChildren;
2012}
2013
2015{
2016 if (children.isEmpty() || clipRect.isEmpty())
2017 return;
2018
2019 const QRegion &r = getOpaqueChildren();
2020 if (!r.isEmpty())
2021 source -= (r & clipRect);
2022}
2023
2024//subtract any relatives that are higher up than me --- this is too expensive !!!
2025void QWidgetPrivate::subtractOpaqueSiblings(QRegion &sourceRegion, bool *hasDirtySiblingsAbove,
2026 bool alsoNonOpaque) const
2027{
2028 Q_Q(const QWidget);
2029 static int disableSubtractOpaqueSiblings = qEnvironmentVariableIntValue("QT_NO_SUBTRACTOPAQUESIBLINGS");
2030 if (disableSubtractOpaqueSiblings || q->isWindow())
2031 return;
2032
2033 QRect clipBoundingRect;
2034 bool dirtyClipBoundingRect = true;
2035
2036 QRegion parentClip;
2037 bool dirtyParentClip = true;
2038
2039 QPoint parentOffset = data.crect.topLeft();
2040
2041 const QWidget *w = q;
2042
2043 while (w) {
2044 if (w->isWindow())
2045 break;
2046 QWidgetPrivate *pd = w->parentWidget()->d_func();
2047 const int myIndex = pd->children.indexOf(const_cast<QWidget *>(w));
2048 const QRect widgetGeometry = w->d_func()->effectiveRectFor(w->data->crect);
2049 for (int i = myIndex + 1; i < pd->children.size(); ++i) {
2050 QWidget *sibling = qobject_cast<QWidget *>(pd->children.at(i));
2051 if (!sibling || !sibling->isVisible() || sibling->isWindow())
2052 continue;
2053
2054 const QRect siblingGeometry = sibling->d_func()->effectiveRectFor(sibling->data->crect);
2055 if (!qRectIntersects(siblingGeometry, widgetGeometry))
2056 continue;
2057
2058 if (dirtyClipBoundingRect) {
2059 clipBoundingRect = sourceRegion.boundingRect();
2060 dirtyClipBoundingRect = false;
2061 }
2062
2063 if (!qRectIntersects(siblingGeometry, clipBoundingRect.translated(parentOffset)))
2064 continue;
2065
2066 if (dirtyParentClip) {
2067 parentClip = sourceRegion.translated(parentOffset);
2068 dirtyParentClip = false;
2069 }
2070
2071 const QPoint siblingPos(sibling->data->crect.topLeft());
2072 const QRect siblingClipRect(sibling->d_func()->clipRect());
2073 QRegion siblingDirty(parentClip);
2074 siblingDirty &= (siblingClipRect.translated(siblingPos));
2075 const bool hasMask = sibling->d_func()->extra && sibling->d_func()->extra->hasMask
2076 && !sibling->d_func()->graphicsEffect;
2077 if (hasMask)
2078 siblingDirty &= sibling->d_func()->extra->mask.translated(siblingPos);
2079 if (siblingDirty.isEmpty())
2080 continue;
2081
2082 if (sibling->d_func()->isOpaque || alsoNonOpaque) {
2083 if (hasMask) {
2084 siblingDirty.translate(-parentOffset);
2085 sourceRegion -= siblingDirty;
2086 } else {
2087 sourceRegion -= siblingGeometry.translated(-parentOffset);
2088 }
2089 } else {
2090 if (hasDirtySiblingsAbove)
2091 *hasDirtySiblingsAbove = true;
2092 if (sibling->d_func()->children.isEmpty())
2093 continue;
2094 QRegion opaqueSiblingChildren(sibling->d_func()->getOpaqueChildren());
2095 opaqueSiblingChildren.translate(-parentOffset + siblingPos);
2096 sourceRegion -= opaqueSiblingChildren;
2097 }
2098 if (sourceRegion.isEmpty())
2099 return;
2100
2101 dirtyClipBoundingRect = true;
2102 dirtyParentClip = true;
2103 }
2104
2105 w = w->parentWidget();
2106 parentOffset += pd->data.crect.topLeft();
2107 dirtyParentClip = true;
2108 }
2109}
2110
2112{
2113 Q_Q(const QWidget);
2114
2115 const QWidget *w = q;
2116 QPoint offset;
2117
2118#if QT_CONFIG(graphicseffect)
2119 if (graphicsEffect) {
2120 w = q->parentWidget();
2121 offset -= data.crect.topLeft();
2122 }
2123#endif // QT_CONFIG(graphicseffect)
2124
2125 while (w) {
2126 const QWidgetPrivate *wd = w->d_func();
2127 if (wd->extra && wd->extra->hasMask)
2128 region &= (w != q) ? wd->extra->mask.translated(offset) : wd->extra->mask;
2129 if (w->isWindow())
2130 return;
2131 offset -= wd->data.crect.topLeft();
2132 w = w->parentWidget();
2133 }
2134}
2135
2137{
2138#if defined(QT_NO_BACKINGSTORE)
2139 return true;
2140#else
2141 Q_Q(const QWidget);
2142 if (q->testAttribute(Qt::WA_PaintOnScreen)
2143 || (!q->isWindow() && q->window()->testAttribute(Qt::WA_PaintOnScreen))) {
2144 return true;
2145 }
2146
2147 return false;
2148#endif
2149}
2150
2152{
2153 // hw: todo: only needed if opacity actually changed
2155
2156#if QT_CONFIG(graphicseffect)
2157 if (graphicsEffect) {
2158 // ### We should probably add QGraphicsEffect::isOpaque at some point.
2159 setOpaque(false);
2160 return;
2161 }
2162#endif // QT_CONFIG(graphicseffect)
2163
2164 Q_Q(QWidget);
2165 if (q->testAttribute(Qt::WA_OpaquePaintEvent) || q->testAttribute(Qt::WA_PaintOnScreen)) {
2166 setOpaque(true);
2167 return;
2168 }
2169
2170 const QPalette &pal = q->palette();
2171
2172 if (q->autoFillBackground()) {
2173 const QBrush &autoFillBrush = pal.brush(q->backgroundRole());
2174 if (autoFillBrush.style() != Qt::NoBrush && autoFillBrush.isOpaque()) {
2175 setOpaque(true);
2176 return;
2177 }
2178 }
2179
2180 if (q->isWindow() && !q->testAttribute(Qt::WA_NoSystemBackground)) {
2181 const QBrush &windowBrush = q->palette().brush(QPalette::Window);
2182 if (windowBrush.style() != Qt::NoBrush && windowBrush.isOpaque()) {
2183 setOpaque(true);
2184 return;
2185 }
2186 }
2187 setOpaque(false);
2188}
2189
2191{
2192 if (isOpaque != opaque) {
2193 isOpaque = opaque;
2195 }
2196}
2197
2199{
2200 Q_Q(QWidget);
2201 if (QWindow *window = q->windowHandle()) {
2202 QSurfaceFormat format = window->format();
2203 const int oldAlpha = format.alphaBufferSize();
2204 const int newAlpha = q->testAttribute(Qt::WA_TranslucentBackground) ? 8 : -1;
2205 if (oldAlpha != newAlpha) {
2206 // QTBUG-85714: Do this only when the QWindow has not yet been create()'ed yet.
2207 //
2208 // If that is not the case, then the setFormat() is not just futile
2209 // but downright dangerous. Futile because the format matters only
2210 // when creating the native window, no point in changing it
2211 // afterwards. Dangerous because a QOpenGLContext or something else
2212 // may eventually query the QWindow's format(), in order to ensure
2213 // compatibility (in terms of native concepts such as pixel format,
2214 // EGLConfig, etc.), and if we change it here, then the returned
2215 // format does not describe reality anymore. (reality being the
2216 // settings with which the native resource was created).
2217 //
2218 // Whereas if one does a destroy()-create() then this all here
2219 // won't matter because the format is updated in
2220 // QWidgetPrivate::create() again.
2221 //
2222 if (!window->handle()) {
2223 format.setAlphaBufferSize(newAlpha);
2224 window->setFormat(format);
2225 }
2226 }
2227 }
2228}
2229
2230static inline void fillRegion(QPainter *painter, const QRegion &rgn, const QBrush &brush)
2231{
2233
2234 if (brush.style() == Qt::TexturePattern) {
2235 const QRect rect(rgn.boundingRect());
2236 painter->setClipRegion(rgn);
2237 painter->drawTiledPixmap(rect, brush.texture(), rect.topLeft());
2238 } else if (brush.gradient()
2239 && (brush.gradient()->coordinateMode() == QGradient::ObjectBoundingMode
2240 || brush.gradient()->coordinateMode() == QGradient::ObjectMode)) {
2241 painter->save();
2242 painter->setClipRegion(rgn);
2244 painter->restore();
2245 } else {
2246 for (const QRect &rect : rgn)
2248 }
2249}
2250
2252{
2253#if QT_CONFIG(scrollarea)
2254 Q_Q(const QWidget);
2255 //If we are painting the viewport of a scrollarea, we must apply an offset to the brush in case we are drawing a texture
2256 if (brush.style() == Qt::NoBrush || brush.style() == Qt::SolidPattern)
2257 return false;
2258 QAbstractScrollArea *scrollArea = qobject_cast<QAbstractScrollArea *>(parent);
2259 if (scrollArea && scrollArea->viewport() == q) {
2260 QObjectData *scrollPrivate = static_cast<QWidget *>(scrollArea)->d_ptr.data();
2261 QAbstractScrollAreaPrivate *priv = static_cast<QAbstractScrollAreaPrivate *>(scrollPrivate);
2262 painter->setBrushOrigin(-priv->contentsOffset());
2263 }
2264#endif // QT_CONFIG(scrollarea)
2265 return true;
2266}
2267
2268void QWidgetPrivate::paintBackground(QPainter *painter, const QRegion &rgn, DrawWidgetFlags flags) const
2269{
2270 Q_Q(const QWidget);
2271
2272 bool brushOriginSet = false;
2273 const QBrush autoFillBrush = q->palette().brush(q->backgroundRole());
2274
2275 if ((flags & DrawAsRoot) && !(q->autoFillBackground() && autoFillBrush.isOpaque())) {
2276 const QBrush bg = q->palette().brush(QPalette::Window);
2277 if (!brushOriginSet)
2278 brushOriginSet = updateBrushOrigin(painter, bg);
2279 if (!(flags & DontSetCompositionMode)) {
2280 //copy alpha straight in
2283 fillRegion(painter, rgn, bg);
2284 painter->setCompositionMode(oldMode);
2285 } else {
2286 fillRegion(painter, rgn, bg);
2287 }
2288 }
2289
2290 if (q->autoFillBackground()) {
2291 if (!brushOriginSet)
2292 brushOriginSet = updateBrushOrigin(painter, autoFillBrush);
2293 fillRegion(painter, rgn, autoFillBrush);
2294 }
2295
2296 if (q->testAttribute(Qt::WA_StyledBackground)) {
2297 painter->setClipRegion(rgn);
2299 opt.initFrom(q);
2300 q->style()->drawPrimitive(QStyle::PE_Widget, &opt, painter, q);
2301 }
2302}
2303
2304/*
2305 \internal
2306 This function is called when a widget is hidden or destroyed.
2307 It resets some application global pointers that should only refer active,
2308 visible widgets.
2309*/
2310
2311extern QWidget *qt_button_down;
2312
2314{
2315 Q_Q(QWidget);
2316 // If this was the active application window, reset it
2319 // If the is the active mouse press widget, reset it
2320 if (q == qt_button_down)
2321 qt_button_down = nullptr;
2322}
2323
2324
2335{
2336 return QWidgetPrivate::mapper ? QWidgetPrivate::mapper->value(id, 0) : nullptr;
2337}
2338
2339
2340
2365{
2366 if (!data->in_destructor
2368 {
2369 QWidget *that = const_cast<QWidget*>(this);
2371 that->d_func()->createWinId();
2372 return that->data->winid;
2373 }
2374 return data->winid;
2375}
2376
2378{
2379 Q_Q(QWidget);
2380
2381 const bool forceNativeWindow = q->testAttribute(Qt::WA_NativeWindow);
2382 if (!q->testAttribute(Qt::WA_WState_Created) || (forceNativeWindow && !q->internalWinId())) {
2383 if (!q->isWindow()) {
2384 QWidget *parent = q->parentWidget();
2385 QWidgetPrivate *pd = parent->d_func();
2386 if (forceNativeWindow && !q->testAttribute(Qt::WA_DontCreateNativeAncestors))
2387 parent->setAttribute(Qt::WA_NativeWindow);
2388 if (!parent->internalWinId()) {
2389 pd->createWinId();
2390 }
2391
2392 for (int i = 0; i < pd->children.size(); ++i) {
2394 if (w && !w->isWindow() && (!w->testAttribute(Qt::WA_WState_Created)
2395 || (!w->internalWinId() && w->testAttribute(Qt::WA_NativeWindow)))) {
2396 w->create();
2397 }
2398 }
2399 } else {
2400 q->create();
2401 }
2402 }
2403}
2404
2413{
2414 Q_Q(QWidget);
2415 if (!q->isWindow())
2416 return false;
2417 // Find the screen for pos and make the widget understand it is on that screen.
2419}
2420
2428{
2429 Q_Q(QWidget);
2430 if (!screen || !q->isWindow())
2431 return false;
2432 const QScreen *currentScreen = windowHandle() ? windowHandle()->screen() : nullptr;
2433 if (currentScreen != screen) {
2435 if (windowHandle())
2436 windowHandle()->setScreen(screen);
2437 return true;
2438 }
2439 return false;
2440}
2441
2449{
2450 Q_D(QWidget);
2451 d->createWinId();
2452}
2453
2470{
2471 const WId id = internalWinId();
2473 return id;
2474 if (const QWidget *realParent = nativeParentWidget())
2475 return realParent->internalWinId();
2476 return 0;
2477}
2478
2491{
2492 Q_D(const QWidget);
2493 return d->windowHandle();
2494}
2495
2504{
2505 Q_D(const QWidget);
2506 if (auto associatedScreen = d->associatedScreen())
2507 return associatedScreen;
2508 if (auto topLevel = window()) {
2509 if (auto topData = qt_widget_private(topLevel)->topData()) {
2510 if (topData->initialScreen)
2511 return topData->initialScreen;
2512 }
2513 if (auto screenByPos = QGuiApplication::screenAt(topLevel->geometry().center()))
2514 return screenByPos;
2515 }
2517}
2518
2532{
2533 Q_D(QWidget);
2534 d->setScreen(screen);
2535}
2536
2537#ifndef QT_NO_STYLE_STYLESHEET
2538
2555{
2556 Q_D(const QWidget);
2557 if (!d->extra)
2558 return QString();
2559 return d->extra->styleSheet;
2560}
2561
2562void QWidget::setStyleSheet(const QString& styleSheet)
2563{
2564 Q_D(QWidget);
2565 if (data->in_destructor)
2566 return;
2567 d->createExtra();
2568
2569 QStyleSheetStyle *proxy = qt_styleSheet(d->extra->style);
2570 d->extra->styleSheet = styleSheet;
2571 if (styleSheet.isEmpty()) { // stylesheet removed
2572 if (!proxy)
2573 return;
2574
2575 d->inheritStyle();
2576 return;
2577 }
2578
2579 if (proxy) { // style sheet update
2580 bool repolish = d->polished;
2581 if (!repolish) {
2582 const auto childWidgets = findChildren<QWidget*>();
2583 for (auto child : childWidgets) {
2584 repolish = child->d_func()->polished;
2585 if (repolish)
2586 break;
2587 }
2588 }
2589 if (repolish)
2590 proxy->repolish(this);
2591 return;
2592 }
2593
2595 d->setStyle_helper(new QStyleSheetStyle(d->extra->style), true);
2596 } else {
2597 d->setStyle_helper(new QStyleSheetStyle(nullptr), true);
2598 }
2599}
2600
2601#endif // QT_NO_STYLE_STYLESHEET
2602
2608{
2609 Q_D(const QWidget);
2610
2611 if (d->extra && d->extra->style)
2612 return d->extra->style;
2613 return QApplication::style();
2614}
2615
2638{
2639 Q_D(QWidget);
2640 setAttribute(Qt::WA_SetStyle, style != nullptr);
2641 d->createExtra();
2642#ifndef QT_NO_STYLE_STYLESHEET
2643 if (QStyleSheetStyle *styleSheetStyle = qt_styleSheet(style)) {
2644 //if for some reason someone try to set a QStyleSheetStyle, ref it
2645 //(this may happen for example in QButtonDialogBox which propagates its style)
2646 styleSheetStyle->ref();
2647 d->setStyle_helper(style, false);
2648 } else if (qt_styleSheet(d->extra->style) || !qApp->styleSheet().isEmpty()) {
2649 // if we have an application stylesheet or have a proxy already, propagate
2650 d->setStyle_helper(new QStyleSheetStyle(style), true);
2651 } else
2652#endif
2653 d->setStyle_helper(style, false);
2654}
2655
2656void QWidgetPrivate::setStyle_helper(QStyle *newStyle, bool propagate)
2657{
2658 Q_Q(QWidget);
2659 QStyle *oldStyle = q->style();
2660
2661 createExtra();
2662
2663#ifndef QT_NO_STYLE_STYLESHEET
2664 QPointer<QStyle> origStyle = extra->style;
2665#endif
2666 extra->style = newStyle;
2667
2668 // repolish
2669 if (polished && q->windowType() != Qt::Desktop) {
2670 oldStyle->unpolish(q);
2671 q->style()->polish(q);
2672 }
2673
2674 if (propagate) {
2675 // We copy the list because the order may be modified
2676 const QObjectList childrenList = children;
2677 for (int i = 0; i < childrenList.size(); ++i) {
2678 QWidget *c = qobject_cast<QWidget*>(childrenList.at(i));
2679 if (c)
2680 c->d_func()->inheritStyle();
2681 }
2682 }
2683
2684#ifndef QT_NO_STYLE_STYLESHEET
2685 if (!qt_styleSheet(newStyle)) {
2686 if (const QStyleSheetStyle* cssStyle = qt_styleSheet(origStyle)) {
2687 cssStyle->clearWidgetFont(q);
2688 }
2689 }
2690#endif
2691
2694
2695#ifndef QT_NO_STYLE_STYLESHEET
2696 // dereference the old stylesheet style
2697 if (QStyleSheetStyle *proxy = qt_styleSheet(origStyle))
2698 proxy->deref();
2699#endif
2700}
2701
2702// Inherits style from the current parent and propagates it as necessary
2704{
2705#ifndef QT_NO_STYLE_STYLESHEET
2706 Q_Q(QWidget);
2707
2708 QStyle *extraStyle = extra ? (QStyle*)extra->style : nullptr;
2709
2710 QStyleSheetStyle *proxy = qt_styleSheet(extraStyle);
2711
2712 if (!q->styleSheet().isEmpty()) {
2713 Q_ASSERT(proxy);
2714 proxy->repolish(q);
2715 return;
2716 }
2717
2718 QStyle *origStyle = proxy ? proxy->base : extraStyle;
2719 QWidget *parent = q->parentWidget();
2720 QStyle *parentStyle = (parent && parent->d_func()->extra) ? (QStyle*)parent->d_func()->extra->style : nullptr;
2721 // If we have stylesheet on app or parent has stylesheet style, we need
2722 // to be running a proxy
2723 if (!qApp->styleSheet().isEmpty() || qt_styleSheet(parentStyle)) {
2724 QStyle *newStyle = parentStyle;
2725 if (q->testAttribute(Qt::WA_SetStyle))
2726 newStyle = new QStyleSheetStyle(origStyle);
2727 else if (QStyleSheetStyle *newProxy = qt_styleSheet(parentStyle))
2728 newProxy->ref();
2729
2730 setStyle_helper(newStyle, true);
2731 return;
2732 }
2733
2734 // So, we have no stylesheet on parent/app and we have an empty stylesheet
2735 // we just need our original style back
2736 if (origStyle == extraStyle) // is it any different?
2737 return;
2738
2739 // We could have inherited the proxy from our parent (which has a custom style)
2740 // In such a case we need to start following the application style (i.e revert
2741 // the propagation behavior of QStyleSheetStyle)
2742 if (!q->testAttribute(Qt::WA_SetStyle))
2743 origStyle = nullptr;
2744
2745 setStyle_helper(origStyle, true);
2746#endif // QT_NO_STYLE_STYLESHEET
2747}
2748
2749
2802{
2803 return static_cast<Qt::WindowModality>(data->window_modality);
2804}
2805
2807{
2808 data->window_modality = windowModality;
2809 // setModal_sys() will be called by setAttribute()
2810 setAttribute(Qt::WA_ShowModal, (data->window_modality != Qt::NonModal));
2812}
2813
2815{
2816 Q_Q(QWidget);
2817 if (q->windowHandle())
2818 q->windowHandle()->setModality(q->windowModality());
2819}
2820
2844{ return data->window_state & Qt::WindowMinimized; }
2845
2855{
2856 bool isMin = isMinimized();
2857 if (isMin && isVisible())
2858 return;
2859
2861
2862 if (!isMin)
2864 setVisible(true);
2865}
2866
2884{ return data->window_state & Qt::WindowMaximized; }
2885
2886
2887
2895Qt::WindowStates QWidget::windowState() const
2896{
2897 return Qt::WindowStates(data->window_state);
2898}
2899
2907void QWidget::overrideWindowState(Qt::WindowStates newstate)
2908{
2909 QWindowStateChangeEvent e(Qt::WindowStates(data->window_state), true);
2910 data->window_state = newstate;
2912}
2913
2944void QWidget::setWindowState(Qt::WindowStates newstate)
2945{
2946 Q_D(QWidget);
2947 Qt::WindowStates oldstate = windowState();
2948 if (newstate.testFlag(Qt::WindowMinimized)) // QTBUG-46763
2949 newstate.setFlag(Qt::WindowActive, false);
2950 if (oldstate == newstate)
2951 return;
2953 create();
2954
2955 data->window_state = newstate;
2956 data->in_set_window_state = 1;
2957 if (isWindow()) {
2958 // Ensure the initial size is valid, since we store it as normalGeometry below.
2960 adjustSize();
2961
2962 d->createTLExtra();
2964 d->topData()->normalGeometry = geometry();
2965
2967 windowHandle()->setWindowStates(newstate & ~Qt::WindowActive);
2968 }
2969 data->in_set_window_state = 0;
2970
2971 if (newstate & Qt::WindowActive)
2973
2974 QWindowStateChangeEvent e(oldstate);
2976}
2977
2990{ return data->window_state & Qt::WindowFullScreen; }
2991
3029{
3031
3034 setVisible(true);
3035#if !defined Q_OS_QNX // On QNX this window will be activated anyway from libscreen
3036 // activating it here before libscreen activates it causes problems
3038#endif
3039}
3040
3052{
3054
3057 setVisible(true);
3058}
3059
3068{
3070
3074 setVisible(true);
3075}
3076
3097bool QWidget::isEnabledTo(const QWidget *ancestor) const
3098{
3099 const QWidget * w = this;
3100 while (!w->testAttribute(Qt::WA_ForceDisabled)
3101 && !w->isWindow()
3102 && w->parentWidget()
3103 && w->parentWidget() != ancestor)
3104 w = w->parentWidget();
3106}
3107
3108#ifndef QT_NO_ACTION
3125{
3126 insertAction(nullptr, action);
3127}
3128
3135{
3136 for(int i = 0; i < actions.size(); i++)
3137 insertAction(nullptr, actions.at(i));
3138}
3139
3150{
3151 if (Q_UNLIKELY(!action)) {
3152 qWarning("QWidget::insertAction: Attempt to insert null action");
3153 return;
3154 }
3155
3156 Q_D(QWidget);
3157 if (d->actions.contains(action))
3158 removeAction(action);
3159
3160 int pos = d->actions.indexOf(before);
3161 if (pos < 0) {
3162 before = nullptr;
3163 pos = d->actions.size();
3164 }
3165 d->actions.insert(pos, action);
3166
3167 QActionPrivate *apriv = action->d_func();
3168 apriv->associatedObjects.append(this);
3169
3170 QActionEvent e(QEvent::ActionAdded, action, before);
3172}
3173
3184{
3185 for(int i = 0; i < actions.size(); ++i)
3186 insertAction(before, actions.at(i));
3187}
3188
3194{
3195 if (!action)
3196 return;
3197
3198 Q_D(QWidget);
3199
3200 QActionPrivate *apriv = action->d_func();
3201 apriv->associatedObjects.removeAll(this);
3202
3203 if (d->actions.removeAll(action)) {
3206 }
3207}
3208
3215{
3216 Q_D(const QWidget);
3217 return d->actions;
3218}
3219
3237{
3238 QAction *ret = new QAction(text, this);
3239 addAction(ret);
3240 return ret;
3241}
3242
3244{
3245 QAction *ret = new QAction(icon, text, this);
3246 addAction(ret);
3247 return ret;
3248}
3249
3250#if QT_CONFIG(shortcut)
3252{
3254 ret->setShortcut(shortcut);
3255 return ret;
3256}
3257
3259{
3261 ret->setShortcut(shortcut);
3262 return ret;
3263}
3264#endif
3265
3284QAction *QWidget::addAction(const QString &text, const QObject *receiver, const char* member,
3286{
3287 QAction *action = addAction(text);
3288 QObject::connect(action, SIGNAL(triggered(bool)), receiver, member, type);
3289 return action;
3290}
3291
3293 const QObject *receiver, const char* member,
3295{
3296 QAction *action = addAction(icon, text);
3297 QObject::connect(action, SIGNAL(triggered(bool)), receiver, member, type);
3298 return action;
3299}
3300
3301#if QT_CONFIG(shortcut)
3303 const QObject *receiver, const char* member,
3305{
3306 QAction *action = addAction(text, receiver, member, type);
3307 action->setShortcut(shortcut);
3308 return action;
3309}
3310
3312 const QObject *receiver, const char* member,
3314{
3315 QAction *action = addAction(icon, text, receiver, member, type);
3316 action->setShortcut(shortcut);
3317 return action;
3318}
3319#endif // QT_CONFIG(shortcut)
3320
3342#endif // QT_NO_ACTION
3343
3366{
3367 Q_D(QWidget);
3369 d->setEnabled_helper(enable);
3370}
3371
3373{
3374 Q_Q(QWidget);
3375
3376 if (enable && !q->isWindow() && q->parentWidget() && !q->parentWidget()->isEnabled())
3377 return; // nothing we can do
3378
3379 if (enable != q->testAttribute(Qt::WA_Disabled))
3380 return; // nothing to do
3381
3382 q->setAttribute(Qt::WA_Disabled, !enable);
3384
3385 if (!enable && q->window()->focusWidget() == q) {
3386 bool parentIsEnabled = (!q->parentWidget() || q->parentWidget()->isEnabled());
3387 if (!parentIsEnabled || !q->focusNextChild())
3388 q->clearFocus();
3389 }
3390
3392 for (int i = 0; i < children.size(); ++i) {
3394 if (w && !w->testAttribute(attribute))
3395 w->d_func()->setEnabled_helper(enable);
3396 }
3397#ifndef QT_NO_CURSOR
3398 if (q->testAttribute(Qt::WA_SetCursor) || q->isWindow()) {
3399 // enforce the windows behavior of clearing the cursor on
3400 // disabled widgets
3401 qt_qpa_set_cursor(q, false);
3402 }
3403#endif
3404#ifndef QT_NO_IM
3405 if (q->testAttribute(Qt::WA_InputMethodEnabled) && q->hasFocus()) {
3406 QWidget *focusWidget = effectiveFocusWidget();
3407
3408 if (enable) {
3409 if (focusWidget->testAttribute(Qt::WA_InputMethodEnabled))
3411 } else {
3414 }
3415 }
3416#endif //QT_NO_IM
3419}
3420
3439{
3441}
3442
3444{
3446
3447}
3448
3457void QWidget::setDisabled(bool disable)
3458{
3459 setEnabled(!disable);
3460}
3461
3476{
3477 Q_D(const QWidget);
3478 if (isWindow() && ! (windowType() == Qt::Popup)) {
3479 QRect fs = d->frameStrut();
3480 return QRect(data->crect.x() - fs.left(),
3481 data->crect.y() - fs.top(),
3482 data->crect.width() + fs.left() + fs.right(),
3483 data->crect.height() + fs.top() + fs.bottom());
3484 }
3485 return data->crect;
3486}
3487
3501int QWidget::x() const
3502{
3503 Q_D(const QWidget);
3504 if (isWindow() && ! (windowType() == Qt::Popup))
3505 return data->crect.x() - d->frameStrut().left();
3506 return data->crect.x();
3507}
3508
3521int QWidget::y() const
3522{
3523 Q_D(const QWidget);
3524 if (isWindow() && ! (windowType() == Qt::Popup))
3525 return data->crect.y() - d->frameStrut().top();
3526 return data->crect.y();
3527}
3528
3557{
3558 Q_D(const QWidget);
3559 QPoint result = data->crect.topLeft();
3560 if (isWindow() && ! (windowType() == Qt::Popup))
3561 if (!d->maybeTopData() || !d->maybeTopData()->posIncludesFrame)
3562 result -= d->frameStrut().topLeft();
3563 return result;
3564}
3565
3676{
3677 Q_D(const QWidget);
3678 if (!isWindow())
3679 return QRect();
3680
3681 if (!isMaximized() && !isFullScreen())
3682 return geometry();
3683
3684 return d->topData()->normalGeometry;
3685}
3686
3687
3701{
3702 Q_D(const QWidget);
3703 QRect r(0, 0, 0, 0);
3704 for (int i = 0; i < d->children.size(); ++i) {
3705 QWidget *w = qobject_cast<QWidget *>(d->children.at(i));
3706 if (w && !w->isWindow() && !w->isHidden())
3707 r |= w->geometry();
3708 }
3709 return r;
3710}
3711
3725{
3726 Q_D(const QWidget);
3727 QRegion r;
3728 for (int i = 0; i < d->children.size(); ++i) {
3729 QWidget *w = qobject_cast<QWidget *>(d->children.at(i));
3730 if (w && !w->isWindow() && !w->isHidden()) {
3731 QRegion mask = w->mask();
3732 if (mask.isEmpty())
3733 r |= w->geometry();
3734 else
3735 r |= mask.translated(w->pos());
3736 }
3737 }
3738 return r;
3739}
3740
3741
3760{
3761 Q_D(const QWidget);
3762 return d->extra ? QSize(d->extra->minw, d->extra->minh) : QSize(0, 0);
3763}
3764
3782{
3783 Q_D(const QWidget);
3784 return d->extra ? QSize(d->extra->maxw, d->extra->maxh)
3786}
3787
3788
3861{
3862 Q_D(const QWidget);
3863 return (d->extra && d->extra->topextra)
3864 ? QSize(d->extra->topextra->incw, d->extra->topextra->inch)
3865 : QSize(0, 0);
3866}
3867
3882{
3883 Q_D(const QWidget);
3884 return (d->extra && d->extra->topextra)
3885 ? QSize(d->extra->topextra->basew, d->extra->topextra->baseh)
3886 : QSize(0, 0);
3887}
3888
3890{
3891 Q_Q(QWidget);
3892
3893 int mw = minw, mh = minh;
3894 if (mw == QWIDGETSIZE_MAX)
3895 mw = 0;
3896 if (mh == QWIDGETSIZE_MAX)
3897 mh = 0;
3898 if (Q_UNLIKELY(minw > QWIDGETSIZE_MAX || minh > QWIDGETSIZE_MAX)) {
3899 qWarning("QWidget::setMinimumSize: (%s/%s) "
3900 "The largest allowed size is (%d,%d)",
3901 q->objectName().toLocal8Bit().data(), q->metaObject()->className(), QWIDGETSIZE_MAX,
3903 minw = mw = qMin<int>(minw, QWIDGETSIZE_MAX);
3904 minh = mh = qMin<int>(minh, QWIDGETSIZE_MAX);
3905 }
3906 if (Q_UNLIKELY(minw < 0 || minh < 0)) {
3907 qWarning("QWidget::setMinimumSize: (%s/%s) Negative sizes (%d,%d) "
3908 "are not possible",
3909 q->objectName().toLocal8Bit().data(), q->metaObject()->className(), minw, minh);
3910 minw = mw = qMax(minw, 0);
3911 minh = mh = qMax(minh, 0);
3912 }
3913 createExtra();
3914 if (extra->minw == mw && extra->minh == mh)
3915 return false;
3916 extra->minw = mw;
3917 extra->minh = mh;
3918 extra->explicitMinSize = (mw ? Qt::Horizontal : 0) | (mh ? Qt::Vertical : 0);
3919 return true;
3920}
3921
3923{
3924 Q_Q(QWidget);
3925 if (extra && q->windowHandle()) {
3926 QWindow *win = q->windowHandle();
3928
3929 winp->minimumSize = QSize(extra->minw, extra->minh);
3930 winp->maximumSize = QSize(extra->maxw, extra->maxh);
3931
3932 if (extra->topextra) {
3933 winp->baseSize = QSize(extra->topextra->basew, extra->topextra->baseh);
3934 winp->sizeIncrement = QSize(extra->topextra->incw, extra->topextra->inch);
3935 }
3936
3937 if (winp->platformWindow) {
3940 }
3941 }
3942}
3943
3952void QWidget::setMinimumSize(int minw, int minh)
3953{
3954 Q_D(QWidget);
3955 if (!d->setMinimumSize_helper(minw, minh))
3956 return;
3957
3958 if (isWindow())
3959 d->setConstraints_sys();
3960 if (minw > width() || minh > height()) {
3961 bool resized = testAttribute(Qt::WA_Resized);
3962 bool maximized = isMaximized();
3963 resize(qMax(minw,width()), qMax(minh,height()));
3964 setAttribute(Qt::WA_Resized, resized); //not a user resize
3965 if (maximized)
3966 data->window_state = data->window_state | Qt::WindowMaximized;
3967 }
3968#if QT_CONFIG(graphicsview)
3969 if (d->extra) {
3970 if (d->extra->proxyWidget)
3971 d->extra->proxyWidget->setMinimumSize(minw, minh);
3972 }
3973#endif
3974 d->updateGeometry_helper(d->extra->minw == d->extra->maxw && d->extra->minh == d->extra->maxh);
3975}
3976
3978{
3979 Q_Q(QWidget);
3980 if (Q_UNLIKELY(maxw > QWIDGETSIZE_MAX || maxh > QWIDGETSIZE_MAX)) {
3981 qWarning("QWidget::setMaximumSize: (%s/%s) "
3982 "The largest allowed size is (%d,%d)",
3983 q->objectName().toLocal8Bit().data(), q->metaObject()->className(), QWIDGETSIZE_MAX,
3985 maxw = qMin<int>(maxw, QWIDGETSIZE_MAX);
3986 maxh = qMin<int>(maxh, QWIDGETSIZE_MAX);
3987 }
3988 if (Q_UNLIKELY(maxw < 0 || maxh < 0)) {
3989 qWarning("QWidget::setMaximumSize: (%s/%s) Negative sizes (%d,%d) "
3990 "are not possible",
3991 q->objectName().toLocal8Bit().data(), q->metaObject()->className(), maxw, maxh);
3992 maxw = qMax(maxw, 0);
3993 maxh = qMax(maxh, 0);
3994 }
3995 createExtra();
3996 if (extra->maxw == maxw && extra->maxh == maxh)
3997 return false;
3998 extra->maxw = maxw;
3999 extra->maxh = maxh;
4000 extra->explicitMaxSize = (maxw != QWIDGETSIZE_MAX ? Qt::Horizontal : 0) |
4001 (maxh != QWIDGETSIZE_MAX ? Qt::Vertical : 0);
4002 return true;
4003}
4004
4012void QWidget::setMaximumSize(int maxw, int maxh)
4013{
4014 Q_D(QWidget);
4015 if (!d->setMaximumSize_helper(maxw, maxh))
4016 return;
4017
4018 if (isWindow())
4019 d->setConstraints_sys();
4020 if (maxw < width() || maxh < height()) {
4021 bool resized = testAttribute(Qt::WA_Resized);
4022 resize(qMin(maxw,width()), qMin(maxh,height()));
4023 setAttribute(Qt::WA_Resized, resized); //not a user resize
4024 }
4025
4026#if QT_CONFIG(graphicsview)
4027 if (d->extra) {
4028 if (d->extra->proxyWidget)
4029 d->extra->proxyWidget->setMaximumSize(maxw, maxh);
4030 }
4031#endif
4032
4033 d->updateGeometry_helper(d->extra->minw == d->extra->maxw && d->extra->minh == d->extra->maxh);
4034}
4035
4043{
4044 Q_D(QWidget);
4045 d->createTLExtra();
4046 QTLWExtra* x = d->topData();
4047 if (x->incw == w && x->inch == h)
4048 return;
4049 x->incw = w;
4050 x->inch = h;
4051 if (isWindow())
4052 d->setConstraints_sys();
4053}
4054
4061void QWidget::setBaseSize(int basew, int baseh)
4062{
4063 Q_D(QWidget);
4064 d->createTLExtra();
4065 QTLWExtra* x = d->topData();
4066 if (x->basew == basew && x->baseh == baseh)
4067 return;
4068 x->basew = basew;
4069 x->baseh = baseh;
4070 if (isWindow())
4071 d->setConstraints_sys();
4072}
4073
4090{
4091 setFixedSize(s.width(), s.height());
4092}
4093
4094
4103{
4104 Q_D(QWidget);
4105 bool minSizeSet = d->setMinimumSize_helper(w, h);
4106 bool maxSizeSet = d->setMaximumSize_helper(w, h);
4107 if (!minSizeSet && !maxSizeSet)
4108 return;
4109
4110 if (isWindow())
4111 d->setConstraints_sys();
4112 else
4113 d->updateGeometry_helper(true);
4114
4115 if (w != QWIDGETSIZE_MAX || h != QWIDGETSIZE_MAX)
4116 resize(w, h);
4117}
4118
4120{
4121 Q_D(QWidget);
4122 d->createExtra();
4123 uint expl = d->extra->explicitMinSize | (w ? Qt::Horizontal : 0);
4125 d->extra->explicitMinSize = expl;
4126}
4127
4129{
4130 Q_D(QWidget);
4131 d->createExtra();
4132 uint expl = d->extra->explicitMinSize | (h ? Qt::Vertical : 0);
4134 d->extra->explicitMinSize = expl;
4135}
4136
4138{
4139 Q_D(QWidget);
4140 d->createExtra();
4141 uint expl = d->extra->explicitMaxSize | (w == QWIDGETSIZE_MAX ? 0 : Qt::Horizontal);
4143 d->extra->explicitMaxSize = expl;
4144}
4145
4147{
4148 Q_D(QWidget);
4149 d->createExtra();
4150 uint expl = d->extra->explicitMaxSize | (h == QWIDGETSIZE_MAX ? 0 : Qt::Vertical);
4152 d->extra->explicitMaxSize = expl;
4153}
4154
4163{
4164 Q_D(QWidget);
4165 d->createExtra();
4166 uint explMin = d->extra->explicitMinSize | Qt::Horizontal;
4167 uint explMax = d->extra->explicitMaxSize | Qt::Horizontal;
4170 d->extra->explicitMinSize = explMin;
4171 d->extra->explicitMaxSize = explMax;
4172}
4173
4174
4183{
4184 Q_D(QWidget);
4185 d->createExtra();
4186 uint explMin = d->extra->explicitMinSize | Qt::Vertical;
4187 uint explMax = d->extra->explicitMaxSize | Qt::Vertical;
4190 d->extra->explicitMinSize = explMin;
4191 d->extra->explicitMaxSize = explMax;
4192}
4193
4194
4205{
4206 QPointF p = pos;
4207 if (parent) {
4208 const QWidget * w = this;
4209 while (w != parent) {
4210 Q_ASSERT_X(w, "QWidget::mapTo(const QWidget *parent, const QPointF &pos)",
4211 "parent must be in parent hierarchy");
4212 p = w->mapToParent(p);
4213 w = w->parentWidget();
4214 }
4215 }
4216 return p;
4217}
4218
4223{
4224 return mapTo(parent, QPointF(pos)).toPoint();
4225}
4226
4237{
4238 QPointF p(pos);
4239 if (parent) {
4240 const QWidget * w = this;
4241 while (w != parent) {
4242 Q_ASSERT_X(w, "QWidget::mapFrom(const QWidget *parent, const QPoint &pos)",
4243 "parent must be in parent hierarchy");
4244
4245 p = w->mapFromParent(p);
4246 w = w->parentWidget();
4247 }
4248 }
4249 return p;
4250}
4251
4256{
4257 return mapFrom(parent, QPointF(pos)).toPoint();
4258}
4259
4271{
4272 return pos + QPointF(data->crect.topLeft());
4273}
4274
4279{
4280 return pos + data->crect.topLeft();
4281}
4282
4294{
4295 return pos - QPointF(data->crect.topLeft());
4296}
4297
4302{
4303 return pos - data->crect.topLeft();
4304}
4305
4306
4321{
4322 QWidget *w = const_cast<QWidget *>(this);
4323 QWidget *p = w->parentWidget();
4324 while (!w->isWindow() && p) {
4325 w = p;
4326 p = p->parentWidget();
4327 }
4328 return w;
4329}
4330
4341{
4343 while (parent && !parent->internalWinId())
4344 parent = parent->parentWidget();
4345 return parent;
4346}
4347
4368{
4369
4370 const QWidget *w = this;
4371 do {
4372 QPalette::ColorRole role = w->d_func()->bg_role;
4373 if (role != QPalette::NoRole)
4374 return role;
4375 if (w->isWindow() || w->windowType() == Qt::SubWindow)
4376 break;
4377 w = w->parentWidget();
4378 } while (w);
4379 return QPalette::Window;
4380}
4381
4399{
4400 Q_D(QWidget);
4401 d->bg_role = role;
4402 d->updateSystemBackground();
4403 d->propagatePaletteChange();
4404 d->updateIsOpaque();
4405}
4406
4419{
4420 Q_D(const QWidget);
4422 if (rl != QPalette::NoRole)
4423 return rl;
4425 switch (backgroundRole()) {
4426 case QPalette::Button:
4427 role = QPalette::ButtonText;
4428 break;
4429 case QPalette::Base:
4430 role = QPalette::Text;
4431 break;
4432 case QPalette::Dark:
4433 case QPalette::Shadow:
4434 role = QPalette::Light;
4435 break;
4438 break;
4440 role = QPalette::ToolTipText;
4441 break;
4442 default:
4443 ;
4444 }
4445 return role;
4446}
4447
4464{
4465 Q_D(QWidget);
4466 d->fg_role = role;
4467 d->updateSystemBackground();
4468 d->propagatePaletteChange();
4469}
4470
4522{
4523 if (!isEnabled()) {
4525 } else if ((!isVisible() || isActiveWindow())
4526#if defined(Q_OS_WIN)
4527 && !QApplicationPrivate::isBlockedByModal(const_cast<QWidget *>(this))
4528#endif
4529 ) {
4530 data->pal.setCurrentColorGroup(QPalette::Active);
4531 } else {
4532 data->pal.setCurrentColorGroup(QPalette::Inactive);
4533 }
4534 return data->pal;
4535}
4536
4538{
4539 Q_D(QWidget);
4541
4542 // Determine which palette is inherited from this widget's ancestors and
4543 // QApplication::palette, resolve this against \a palette (attributes from
4544 // the inherited palette are copied over this widget's palette). Then
4545 // propagate this palette to this widget's children.
4546 QPalette naturalPalette = d->naturalWidgetPalette(d->inheritedPaletteResolveMask);
4547 QPalette resolvedPalette = palette.resolve(naturalPalette);
4548 d->setPalette_helper(resolvedPalette);
4549}
4550
4561{
4562 Q_Q(const QWidget);
4563
4564 const bool useStyleSheetPropagationInWidgetStyles =
4566
4567 QPalette naturalPalette = QApplication::palette(q);
4568 if ((!q->testAttribute(Qt::WA_StyleSheet) || useStyleSheetPropagationInWidgetStyles)
4569 && (!q->isWindow() || q->testAttribute(Qt::WA_WindowPropagation)
4570#if QT_CONFIG(graphicsview)
4571 || (extra && extra->proxyWidget)
4572#endif // QT_CONFIG(graphicsview)
4573 )) {
4574 if (QWidget *p = q->parentWidget()) {
4575 if (!p->testAttribute(Qt::WA_StyleSheet) || useStyleSheetPropagationInWidgetStyles) {
4576 if (!naturalPalette.isCopyOf(QGuiApplication::palette())) {
4577 QPalette inheritedPalette = p->palette();
4578 inheritedPalette.setResolveMask(inheritedMask);
4579 naturalPalette = inheritedPalette.resolve(naturalPalette);
4580 } else {
4581 naturalPalette = p->palette();
4582 }
4583 }
4584 }
4585#if QT_CONFIG(graphicsview)
4586 else if (extra && extra->proxyWidget) {
4587 QPalette inheritedPalette = extra->proxyWidget->palette();
4588 inheritedPalette.setResolveMask(inheritedMask);
4589 naturalPalette = inheritedPalette.resolve(naturalPalette);
4590 }
4591#endif // QT_CONFIG(graphicsview)
4592 }
4593 naturalPalette.setResolveMask(0);
4594 return naturalPalette;
4595}
4605{
4607 QPalette resolvedPalette = data.pal.resolve(naturalPalette);
4608 setPalette_helper(resolvedPalette);
4609}
4610
4612{
4613 Q_Q(QWidget);
4614 if (data.pal == palette && data.pal.resolveMask() == palette.resolveMask())
4615 return;
4616 data.pal = palette;
4620 q->update();
4622}
4623
4625{
4626}
4627
4675{
4676 Q_D(QWidget);
4677
4678#ifndef QT_NO_STYLE_STYLESHEET
4679 const QStyleSheetStyle* style;
4680 if (d->extra && (style = qt_styleSheet(d->extra->style)))
4681 style->saveWidgetFont(this, font);
4682#endif
4683
4685
4686 // Determine which font is inherited from this widget's ancestors and
4687 // QApplication::font, resolve this against \a font (attributes from the
4688 // inherited font are copied over). Then propagate this font to this
4689 // widget's children.
4690 QFont naturalFont = d->naturalWidgetFont(d->inheritedFontResolveMask);
4691 QFont resolvedFont = font.resolve(naturalFont);
4692 d->setFont_helper(resolvedFont);
4693}
4694
4695/*
4696 \internal
4697
4698 Returns the font that the widget \a w inherits from its ancestors and
4699 QApplication::font. \a inheritedMask is the combination of the widget's
4700 ancestors font request masks (i.e., which attributes from the parent
4701 widget's font are implicitly imposed on this widget by the user). Note
4702 that this font does not take into account the font set on \a w itself.
4703
4704 ### Stylesheet has a different font propagation mechanism. When a stylesheet
4705 is applied, fonts are not propagated anymore
4706*/
4708{
4709 Q_Q(const QWidget);
4710
4711 const bool useStyleSheetPropagationInWidgetStyles =
4713
4714 QFont naturalFont = QApplication::font(q);
4715 if ((!q->testAttribute(Qt::WA_StyleSheet) || useStyleSheetPropagationInWidgetStyles)
4716 && (!q->isWindow() || q->testAttribute(Qt::WA_WindowPropagation)
4717#if QT_CONFIG(graphicsview)
4718 || (extra && extra->proxyWidget)
4719#endif // QT_CONFIG(graphicsview)
4720 )) {
4721 if (QWidget *p = q->parentWidget()) {
4722 if (!p->testAttribute(Qt::WA_StyleSheet) || useStyleSheetPropagationInWidgetStyles) {
4723 if (!naturalFont.isCopyOf(QApplication::font())) {
4724 if (inheritedMask != 0) {
4725 QFont inheritedFont = p->font();
4726 inheritedFont.setResolveMask(inheritedMask);
4727 naturalFont = inheritedFont.resolve(naturalFont);
4728 } // else nothing to do (naturalFont = naturalFont)
4729 } else {
4730 naturalFont = p->font();
4731 }
4732 }
4733 }
4734#if QT_CONFIG(graphicsview)
4735 else if (extra && extra->proxyWidget) {
4736 if (inheritedMask != 0) {
4737 QFont inheritedFont = extra->proxyWidget->font();
4738 inheritedFont.setResolveMask(inheritedMask);
4739 naturalFont = inheritedFont.resolve(naturalFont);
4740 } // else nothing to do (naturalFont = naturalFont)
4741 }
4742#endif // QT_CONFIG(graphicsview)
4743 }
4744 naturalFont.setResolveMask(0);
4745 return naturalFont;
4746}
4747
4754{
4755 QFont localfont = data.fnt;
4757 return localfont;
4758}
4759
4769{
4771 QFont resolvedFont = localFont().resolve(naturalFont);
4772 setFont_helper(resolvedFont);
4773}
4774
4785{
4786 Q_Q(QWidget);
4787#ifndef QT_NO_STYLE_STYLESHEET
4788 const QStyleSheetStyle* cssStyle;
4789 cssStyle = extra ? qt_styleSheet(extra->style) : nullptr;
4790 const bool useStyleSheetPropagationInWidgetStyles =
4792#endif
4793
4794 data.fnt = QFont(font, q);
4795
4796 // Combine new mask with natural mask and propagate to children.
4797#if QT_CONFIG(graphicsview)
4798 if (!q->parentWidget() && extra && extra->proxyWidget) {
4799 QGraphicsProxyWidget *p = extra->proxyWidget;
4800 inheritedFontResolveMask = p->d_func()->inheritedFontResolveMask | p->font().resolveMask();
4801 } else
4802#endif // QT_CONFIG(graphicsview)
4803 if (q->isWindow() && !q->testAttribute(Qt::WA_WindowPropagation)) {
4805 }
4806 uint newMask = data.fnt.resolveMask() | inheritedFontResolveMask;
4807 // Set the font as also having resolved inherited traits, so the result of reading QWidget::font()
4808 // isn't all weak information, but save the original mask to be able to let new changes on the
4809 // parent widget font propagate correctly.
4810 directFontResolveMask = data.fnt.resolveMask();
4811 data.fnt.setResolveMask(newMask);
4812
4813 for (int i = 0; i < children.size(); ++i) {
4815 if (w) {
4816 if (0) {
4817#ifndef QT_NO_STYLE_STYLESHEET
4818 } else if (!useStyleSheetPropagationInWidgetStyles && w->testAttribute(Qt::WA_StyleSheet)) {
4819 // Style sheets follow a different font propagation scheme.
4820 if (cssStyle)
4821 cssStyle->updateStyleSheetFont(w);
4822#endif
4823 } else if ((!w->isWindow() || w->testAttribute(Qt::WA_WindowPropagation))) {
4824 // Propagate font changes.
4825 QWidgetPrivate *wd = w->d_func();
4826 wd->inheritedFontResolveMask = newMask;
4827 wd->resolveFont();
4828 }
4829 }
4830 }
4831
4832#ifndef QT_NO_STYLE_STYLESHEET
4833 if (!useStyleSheetPropagationInWidgetStyles && cssStyle) {
4834 cssStyle->updateStyleSheetFont(q);
4835 }
4836#endif
4837
4840}
4841
4843{
4844 Q_Q(QWidget);
4845
4846 if ( (direction == Qt::RightToLeft) == q->testAttribute(Qt::WA_RightToLeft))
4847 return;
4848 q->setAttribute(Qt::WA_RightToLeft, (direction == Qt::RightToLeft));
4849 if (!children.isEmpty()) {
4850 for (int i = 0; i < children.size(); ++i) {
4852 if (w && !w->isWindow() && !w->testAttribute(Qt::WA_SetLayoutDirection))
4853 w->d_func()->setLayoutDirection_helper(direction);
4854 }
4855 }
4858}
4859
4861{
4862 Q_Q(const QWidget);
4863 if (!q->testAttribute(Qt::WA_SetLayoutDirection))
4864 setLayoutDirection_helper(q->isWindow() ? QGuiApplication::layoutDirection() : q->parentWidget()->layoutDirection());
4865}
4866
4887{
4888 Q_D(QWidget);
4889
4892 return;
4893 }
4894
4896 d->setLayoutDirection_helper(direction);
4897}
4898
4900{
4902}
4903
4905{
4906 Q_D(QWidget);
4908 d->resolveLayoutDirection();
4909}
4910
4954#ifndef QT_NO_CURSOR
4956{
4957 Q_D(const QWidget);
4959 return (d->extra && d->extra->curs)
4960 ? *d->extra->curs
4962 if (isWindow() || !parentWidget())
4963 return QCursor(Qt::ArrowCursor);
4964 return parentWidget()->cursor();
4965}
4966
4968{
4969 Q_D(QWidget);
4971 || (d->extra && d->extra->curs))
4972 {
4973 d->createExtra();
4974 d->extra->curs = std::make_unique<QCursor>(cursor);
4975 }
4977 d->setCursor_sys(cursor);
4978
4981}
4982
4984{
4986 Q_Q(QWidget);
4987 qt_qpa_set_cursor(q, false);
4988}
4989
4991{
4992 Q_D(QWidget);
4993 if (d->extra)
4994 d->extra->curs.reset();
4995 if (!isWindow())
4997 d->unsetCursor_sys();
4998
5001}
5002
5004{
5005 Q_Q(QWidget);
5006 qt_qpa_set_cursor(q, false);
5007}
5008
5009static inline void applyCursor(QWidget *w, const QCursor &c)
5010{
5011 if (QWindow *window = w->windowHandle())
5012 window->setCursor(c);
5013}
5014
5015static inline void unsetCursor(QWidget *w)
5016{
5017 if (QWindow *window = w->windowHandle())
5018 window->unsetCursor();
5019}
5020
5021void qt_qpa_set_cursor(QWidget *w, bool force)
5022{
5023 if (!w->testAttribute(Qt::WA_WState_Created))
5024 return;
5025
5026 static QPointer<QWidget> lastUnderMouse = nullptr;
5027 if (force) {
5028 lastUnderMouse = w;
5029 } else if (lastUnderMouse) {
5030 const WId lastWinId = lastUnderMouse->effectiveWinId();
5031 const WId winId = w->effectiveWinId();
5032 if (lastWinId && lastWinId == winId)
5033 w = lastUnderMouse;
5034 } else if (!w->internalWinId()) {
5035 return; // The mouse is not under this widget, and it's not native, so don't change it.
5036 }
5037
5038 while (!w->internalWinId() && w->parentWidget() && !w->isWindow()
5039 && !w->testAttribute(Qt::WA_SetCursor))
5040 w = w->parentWidget();
5041
5042 QWidget *nativeParent = w;
5043 if (!w->internalWinId())
5044 nativeParent = w->nativeParentWidget();
5045 if (!nativeParent || !nativeParent->internalWinId())
5046 return;
5047
5048 if (w->isWindow() || w->testAttribute(Qt::WA_SetCursor)) {
5049 if (w->isEnabled())
5050 applyCursor(nativeParent, w->cursor());
5051 else
5052 // Enforce the windows behavior of clearing the cursor on
5053 // disabled widgets.
5054 unsetCursor(nativeParent);
5055 } else {
5056 unsetCursor(nativeParent);
5057 }
5058}
5059#endif
5060
5099void QWidget::render(QPaintDevice *target, const QPoint &targetOffset,
5100 const QRegion &sourceRegion, RenderFlags renderFlags)
5101{
5102 QPainter p(target);
5103 render(&p, targetOffset, sourceRegion, renderFlags);
5104}
5105
5119void QWidget::render(QPainter *painter, const QPoint &targetOffset,
5120 const QRegion &sourceRegion, RenderFlags renderFlags)
5121{
5122 if (Q_UNLIKELY(!painter)) {
5123 qWarning("QWidget::render: Null pointer to painter");
5124 return;
5125 }
5126
5127 if (Q_UNLIKELY(!painter->isActive())) {
5128 qWarning("QWidget::render: Cannot render with an inactive painter");
5129 return;
5130 }
5131
5132 const qreal opacity = painter->opacity();
5133 if (qFuzzyIsNull(opacity))
5134 return; // Fully transparent.
5135
5136 Q_D(QWidget);
5137 const bool inRenderWithPainter = d->extra && d->extra->inRenderWithPainter;
5138 const QRegion toBePainted = !inRenderWithPainter ? d->prepareToRender(sourceRegion, renderFlags)
5139 : sourceRegion;
5140 if (toBePainted.isEmpty())
5141 return;
5142
5143 if (!d->extra)
5144 d->createExtra();
5145 d->extra->inRenderWithPainter = true;
5146
5149 QPaintEnginePrivate *enginePriv = engine->d_func();
5150 Q_ASSERT(enginePriv);
5151 QPaintDevice *target = engine->paintDevice();
5153
5154 // Render via a pixmap when dealing with non-opaque painters or printers.
5155 if (!inRenderWithPainter && (opacity < 1.0 || (target->devType() == QInternal::Printer))) {
5156 d->render_helper(painter, targetOffset, toBePainted, renderFlags);
5157 d->extra->inRenderWithPainter = inRenderWithPainter;
5158 return;
5159 }
5160
5161 // Set new shared painter.
5162 QPainter *oldPainter = d->sharedPainter();
5163 d->setSharedPainter(painter);
5164
5165 // Save current system clip, viewport and transform,
5166 const QTransform oldTransform = enginePriv->systemTransform;
5167 const QRegion oldSystemClip = enginePriv->systemClip;
5168 const QRegion oldBaseClip = enginePriv->baseSystemClip;
5169 const QRegion oldSystemViewport = enginePriv->systemViewport;
5170
5171 // This ensures that all painting triggered by render() is clipped to the current engine clip.
5172 if (painter->hasClipping()) {
5173 const QRegion painterClip = painter->deviceTransform().map(painter->clipRegion());
5174 enginePriv->setSystemViewport(oldSystemClip.isEmpty() ? painterClip : oldSystemClip & painterClip);
5175 } else {
5176 enginePriv->setSystemViewport(oldSystemClip);
5177 }
5178
5179 d->render(target, targetOffset, toBePainted, renderFlags);
5180
5181 // Restore system clip, viewport and transform.
5182 enginePriv->baseSystemClip = oldBaseClip;
5183 enginePriv->setSystemTransformAndViewport(oldTransform, oldSystemViewport);
5184 enginePriv->systemStateChanged();
5185
5186 // Restore shared painter.
5187 d->setSharedPainter(oldPainter);
5188
5189 d->extra->inRenderWithPainter = inRenderWithPainter;
5190}
5191
5193{
5194 QResizeEvent e(target->size(), QSize());
5196
5197 const QObjectList children = target->children();
5198 for (int i = 0; i < children.size(); ++i) {
5199 if (!children.at(i)->isWidgetType())
5200 continue;
5201 QWidget *child = static_cast<QWidget*>(children.at(i));
5202 if (!child->isWindow() && child->testAttribute(Qt::WA_PendingResizeEvent))
5204 }
5205}
5206
5219QPixmap QWidget::grab(const QRect &rectangle)
5220{
5221 Q_D(QWidget);
5223 sendResizeEvents(this);
5224
5225 const QWidget::RenderFlags renderFlags = QWidget::DrawWindowBackground | QWidget::DrawChildren | QWidget::IgnoreMask;
5226
5227 const bool oldDirtyOpaqueChildren = d->dirtyOpaqueChildren;
5228 QRect r(rectangle);
5229 if (r.width() < 0 || r.height() < 0) {
5230 // For grabbing widgets that haven't been shown yet,
5231 // we trigger the layouting mechanism to determine the widget's size.
5232 r = d->prepareToRender(QRegion(), renderFlags).boundingRect();
5233 r.setTopLeft(rectangle.topLeft());
5234 }
5235
5236 if (!r.intersects(rect()))
5237 return QPixmap();
5238
5239 const qreal dpr = devicePixelRatio();
5240 QPixmap res((QSizeF(r.size()) * dpr).toSize());
5241 res.setDevicePixelRatio(dpr);
5242 if (!d->isOpaque)
5243 res.fill(Qt::transparent);
5244 d->render(&res, QPoint(), QRegion(r), renderFlags);
5245
5246 d->dirtyOpaqueChildren = oldDirtyOpaqueChildren;
5247 return res;
5248}
5249
5260#if QT_CONFIG(graphicseffect)
5261QGraphicsEffect *QWidget::graphicsEffect() const
5262{
5263 Q_D(const QWidget);
5264 return d->graphicsEffect;
5265}
5266#endif // QT_CONFIG(graphicseffect)
5267
5290#if QT_CONFIG(graphicseffect)
5291void QWidget::setGraphicsEffect(QGraphicsEffect *effect)
5292{
5293 Q_D(QWidget);
5294 if (d->graphicsEffect == effect)
5295 return;
5296
5297 if (d->graphicsEffect) {
5298 d->invalidateBackingStore(rect());
5299 delete d->graphicsEffect;
5300 d->graphicsEffect = nullptr;
5301 }
5302
5303 if (effect) {
5304 // Set new effect.
5307 d->graphicsEffect = effect;
5308 effect->d_func()->setGraphicsEffectSource(source);
5309 update();
5310 }
5311
5312 d->updateIsOpaque();
5313}
5314#endif // QT_CONFIG(graphicseffect)
5315
5317{
5318 if (data.in_show)
5319 return true;
5320
5321 Q_Q(const QWidget);
5322 if (q->isHidden())
5323 return false;
5324
5325 // The widget will be shown if any of its ancestors are about to show.
5326 QWidget *parent = q->parentWidget();
5327 return parent ? parent->d_func()->isAboutToShow() : false;
5328}
5329
5330QRegion QWidgetPrivate::prepareToRender(const QRegion &region, QWidget::RenderFlags renderFlags)
5331{
5332 Q_Q(QWidget);
5333 const bool isVisible = q->isVisible();
5334
5335 // Make sure the widget is laid out correctly.
5336 if (!isVisible && !isAboutToShow()) {
5337 QWidget *topLevel = q->window();
5338 (void)topLevel->d_func()->topData(); // Make sure we at least have top-data.
5339 topLevel->ensurePolished();
5340
5341 // Invalidate the layout of hidden ancestors (incl. myself) and pretend
5342 // they're not explicitly hidden.
5343 QWidget *widget = q;
5344 QWidgetList hiddenWidgets;
5345 while (widget) {
5346 if (widget->isHidden()) {
5348 hiddenWidgets.append(widget);
5349 if (!widget->isWindow() && widget->parentWidget()->d_func()->layout)
5350 widget->d_func()->updateGeometry_helper(true);
5351 }
5353 }
5354
5355 // Activate top-level layout.
5356 if (topLevel->d_func()->layout)
5357 topLevel->d_func()->layout->activate();
5358
5359 // Adjust size if necessary.
5360 QTLWExtra *topLevelExtra = topLevel->d_func()->maybeTopData();
5361 if (topLevelExtra && !topLevelExtra->sizeAdjusted
5362 && !topLevel->testAttribute(Qt::WA_Resized)) {
5363 topLevel->adjustSize();
5364 topLevel->setAttribute(Qt::WA_Resized, false);
5365 }
5366
5367 // Activate child layouts.
5368 topLevel->d_func()->activateChildLayoutsRecursively();
5369
5370 // We're not cheating with WA_WState_Hidden anymore.
5371 for (int i = 0; i < hiddenWidgets.size(); ++i) {
5372 QWidget *widget = hiddenWidgets.at(i);
5374 if (!widget->isWindow() && widget->parentWidget()->d_func()->layout)
5375 widget->parentWidget()->d_func()->layout->invalidate();
5376 }
5377 } else if (isVisible) {
5378 q->window()->d_func()->sendPendingMoveAndResizeEvents(true, true);
5379 }
5380
5381 // Calculate the region to be painted.
5382 QRegion toBePainted = !region.isEmpty() ? region : QRegion(q->rect());
5383 if (!(renderFlags & QWidget::IgnoreMask) && extra && extra->hasMask)
5384 toBePainted &= extra->mask;
5385 return toBePainted;
5386}
5387
5388void QWidgetPrivate::render_helper(QPainter *painter, const QPoint &targetOffset, const QRegion &toBePainted,
5389 QWidget::RenderFlags renderFlags)
5390{
5392 Q_ASSERT(!toBePainted.isEmpty());
5393
5394 Q_Q(QWidget);
5395 const QTransform originalTransform = painter->worldTransform();
5396 const bool useDeviceCoordinates = originalTransform.isScaling();
5397 if (!useDeviceCoordinates) {
5398 // Render via a pixmap.
5399 const QRect rect = toBePainted.boundingRect();
5400 const QSize size = rect.size();
5401 if (size.isNull())
5402 return;
5403
5404 const qreal pixmapDevicePixelRatio = painter->device()->devicePixelRatio();
5405 QPixmap pixmap(size * pixmapDevicePixelRatio);
5406 pixmap.setDevicePixelRatio(pixmapDevicePixelRatio);
5407
5408 if (!(renderFlags & QWidget::DrawWindowBackground) || !isOpaque)
5409 pixmap.fill(Qt::transparent);
5410 q->render(&pixmap, QPoint(), toBePainted, renderFlags);
5411
5412 const bool restore = !(painter->renderHints() & QPainter::SmoothPixmapTransform);
5414
5415 painter->drawPixmap(targetOffset, pixmap);
5416
5417 if (restore)
5419
5420 } else {
5421 // Render via a pixmap in device coordinates (to avoid pixmap scaling).
5422 QTransform transform = originalTransform;
5423 transform.translate(targetOffset.x(), targetOffset.y());
5424
5427
5428 // Calculate device rect.
5429 const QRectF rect(toBePainted.boundingRect());
5430 QRect deviceRect = transform.mapRect(QRectF(0, 0, rect.width(), rect.height())).toAlignedRect();
5431 deviceRect &= QRect(0, 0, device->width(), device->height());
5432
5434 pixmap.fill(Qt::transparent);
5435
5436 // Create a pixmap device coordinate painter.
5437 QPainter pixmapPainter(&pixmap);
5438 pixmapPainter.setRenderHints(painter->renderHints());
5440 pixmapPainter.setTransform(transform);
5441
5442 q->render(&pixmapPainter, QPoint(), toBePainted, renderFlags);
5443 pixmapPainter.end();
5444
5445 // And then draw the pixmap.
5448 painter->setTransform(originalTransform);
5449 }
5450}
5451
5452void QWidgetPrivate::drawWidget(QPaintDevice *pdev, const QRegion &rgn, const QPoint &offset, DrawWidgetFlags flags,
5453 QPainter *sharedPainter, QWidgetRepaintManager *repaintManager)
5454{
5455 if (rgn.isEmpty())
5456 return;
5457
5458 Q_Q(QWidget);
5459
5460 qCInfo(lcWidgetPainting) << "Drawing" << rgn << "of" << q << "at" << offset
5461 << "into paint device" << pdev << "with" << flags;
5462
5463 const bool asRoot = flags & DrawAsRoot;
5464 bool onScreen = shouldPaintOnScreen();
5465
5466#if QT_CONFIG(graphicseffect)
5469 QWidgetEffectSourcePrivate *sourced = static_cast<QWidgetEffectSourcePrivate *>
5470 (source->d_func());
5471 if (!sourced->context) {
5472 const QRegion effectRgn((flags & UseEffectRegionBounds) ? rgn.boundingRect() : rgn);
5473 QWidgetPaintContext context(pdev, effectRgn, offset, flags, sharedPainter, repaintManager);
5474 sourced->context = &context;
5475 if (!sharedPainter) {
5476 setSystemClip(pdev->paintEngine(), pdev->devicePixelRatio(), effectRgn.translated(offset));
5477 QPainter p(pdev);
5478 p.translate(offset);
5479 context.painter = &p;
5481 setSystemClip(pdev->paintEngine(), 1, QRegion());
5482 } else {
5483 context.painter = sharedPainter;
5484 if (sharedPainter->worldTransform() != sourced->lastEffectTransform) {
5485 sourced->invalidateCache();
5486 sourced->lastEffectTransform = sharedPainter->worldTransform();
5487 }
5494 }
5495 sourced->context = nullptr;
5496
5497 if (repaintManager)
5498 repaintManager->markNeedsFlush(q, effectRgn, offset);
5499
5500 return;
5501 }
5502 }
5503#endif // QT_CONFIG(graphicseffect)
5504 flags = flags & ~UseEffectRegionBounds;
5505
5506 const bool alsoOnScreen = flags & DrawPaintOnScreen;
5507 const bool recursive = flags & DrawRecursive;
5508 const bool alsoInvisible = flags & DrawInvisible;
5509
5511
5512 QRegion toBePainted(rgn);
5513 if (asRoot && !alsoInvisible)
5514 toBePainted &= clipRect(); //(rgn & visibleRegion());
5516 subtractOpaqueChildren(toBePainted, q->rect());
5517
5518 if (!toBePainted.isEmpty()) {
5519 if (!onScreen || alsoOnScreen) {
5520 //update the "in paint event" flag
5521 if (Q_UNLIKELY(q->testAttribute(Qt::WA_WState_InPaintEvent)))
5522 qWarning("QWidget::repaint: Recursive repaint detected");
5523 q->setAttribute(Qt::WA_WState_InPaintEvent);
5524
5525 //clip away the new area
5526 QPaintEngine *paintEngine = pdev->paintEngine();
5527 if (paintEngine) {
5528 setRedirected(pdev, -offset);
5529
5530 if (sharedPainter)
5531 setSystemClip(pdev->paintEngine(), pdev->devicePixelRatio(), toBePainted);
5532 else
5533 paintEngine->d_func()->systemRect = q->data->crect;
5534
5535 //paint the background
5536 if ((asRoot || q->autoFillBackground() || onScreen || q->testAttribute(Qt::WA_StyledBackground))
5537 && !q->testAttribute(Qt::WA_OpaquePaintEvent) && !q->testAttribute(Qt::WA_NoSystemBackground)) {
5539 QPainter p(q);
5540 p.setRenderHint(QPainter::SmoothPixmapTransform);
5541 paintBackground(&p, toBePainted, (asRoot || onScreen) ? (flags | DrawAsRoot) : DrawWidgetFlags());
5543 }
5544
5545 if (!sharedPainter)
5546 setSystemClip(pdev->paintEngine(), pdev->devicePixelRatio(), toBePainted.translated(offset));
5547
5548 if (!onScreen && !asRoot && !isOpaque && q->testAttribute(Qt::WA_TintedBackground)) {
5550 QPainter p(q);
5551 QColor tint = q->palette().window().color();
5552 tint.setAlphaF(.6f);
5553 p.fillRect(toBePainted.boundingRect(), tint);
5555 }
5556 }
5557
5558#if 0
5559 qDebug() << "painting" << q << "opaque ==" << isOpaque();
5560 qDebug() << "clipping to" << toBePainted << "location == " << offset
5561 << "geometry ==" << QRect(q->mapTo(q->window(), QPoint(0, 0)), q->size());
5562#endif
5563
5564 bool skipPaintEvent = false;
5565 if (renderToTexture) {
5566 // This widget renders into a texture which is composed later. We just need to
5567 // punch a hole in the backingstore, so the texture will be visible.
5569 if (!q->testAttribute(Qt::WA_AlwaysStackOnTop) && repaintManager) {
5570 QPainter p(q);
5571 p.setCompositionMode(QPainter::CompositionMode_Source);
5572 p.fillRect(q->rect(), Qt::transparent);
5573 } else if (!repaintManager) {
5574 // We are not drawing to a backingstore: fall back to QImage
5576 // grabFramebuffer() always sets the format to RGB32
5577 // regardless of whether it is transparent or not.
5578 if (img.format() == QImage::Format_RGB32)
5579 img.reinterpretAsFormat(QImage::Format_ARGB32_Premultiplied);
5580 QPainter p(q);
5581 p.drawImage(q->rect(), img);
5582 skipPaintEvent = true;
5583 }
5587 else
5588 skipPaintEvent = true;
5589 }
5590
5591 if (!skipPaintEvent) {
5592 //actually send the paint event
5593 sendPaintEvent(toBePainted);
5594 }
5595
5596 if (repaintManager)
5597 repaintManager->markNeedsFlush(q, toBePainted, offset);
5598
5599 //restore
5600 if (paintEngine) {
5602 if (!sharedPainter)
5603 paintEngine->d_func()->systemRect = QRect();
5604 else
5605 paintEngine->d_func()->currentClipDevice = nullptr;
5606
5607 setSystemClip(pdev->paintEngine(), 1, QRegion());
5608 }
5609 q->setAttribute(Qt::WA_WState_InPaintEvent, false);
5610 if (Q_UNLIKELY(q->paintingActive()))
5611 qWarning("QWidget::repaint: It is dangerous to leave painters active on a widget outside of the PaintEvent");
5612
5613 if (paintEngine && paintEngine->autoDestruct()) {
5614 delete paintEngine;
5615 }
5616 } else if (q->isWindow()) {
5617 QPaintEngine *engine = pdev->paintEngine();
5618 if (engine) {
5619 QPainter p(pdev);
5620 p.setClipRegion(toBePainted);
5621 const QBrush bg = q->palette().brush(QPalette::Window);
5622 if (bg.style() == Qt::TexturePattern)
5623 p.drawTiledPixmap(q->rect(), bg.texture());
5624 else
5625 p.fillRect(q->rect(), bg);
5626
5627 if (engine->autoDestruct())
5628 delete engine;
5629 }
5630 }
5631 }
5632
5633 if (recursive && !children.isEmpty()) {
5635 sharedPainter, repaintManager);
5636 }
5637}
5638
5640{
5641 Q_Q(QWidget);
5642 QPaintEvent e(toBePainted);
5643 QCoreApplication::sendSpontaneousEvent(q, &e);
5644
5645 if (renderToTexture)
5647}
5648
5650 const QRegion &sourceRegion, QWidget::RenderFlags renderFlags)
5651{
5652 if (Q_UNLIKELY(!target)) {
5653 qWarning("QWidget::render: null pointer to paint device");
5654 return;
5655 }
5656
5657 const bool inRenderWithPainter = extra && extra->inRenderWithPainter;
5658 QRegion paintRegion = !inRenderWithPainter
5659 ? prepareToRender(sourceRegion, renderFlags)
5660 : sourceRegion;
5661 if (paintRegion.isEmpty())
5662 return;
5663
5664 QPainter *oldSharedPainter = inRenderWithPainter ? sharedPainter() : nullptr;
5665
5666 // Use the target's shared painter if set (typically set when doing
5667 // "other->render(widget);" in the widget's paintEvent.
5668 if (target->devType() == QInternal::Widget) {
5669 QWidgetPrivate *targetPrivate = static_cast<QWidget *>(target)->d_func();
5670 if (targetPrivate->extra && targetPrivate->extra->inRenderWithPainter) {
5671 QPainter *targetPainter = targetPrivate->sharedPainter();
5672 if (targetPainter && targetPainter->isActive())
5673 setSharedPainter(targetPainter);
5674 }
5675 }
5676
5677 // Use the target's redirected device if set and adjust offset and paint
5678 // region accordingly. This is typically the case when people call render
5679 // from the paintEvent.
5680 QPoint offset = targetOffset;
5681 offset -= paintRegion.boundingRect().topLeft();
5682 QPoint redirectionOffset;
5683 QPaintDevice *redirected = nullptr;
5684
5685 if (target->devType() == QInternal::Widget)
5686 redirected = static_cast<QWidget *>(target)->d_func()->redirected(&redirectionOffset);
5687
5688 if (redirected) {
5690 offset -= redirectionOffset;
5691 }
5692
5693 if (!inRenderWithPainter) { // Clip handled by shared painter (in qpainter.cpp).
5694 if (QPaintEngine *targetEngine = target->paintEngine()) {
5695 const QRegion targetSystemClip = targetEngine->systemClip();
5696 if (!targetSystemClip.isEmpty())
5697 paintRegion &= targetSystemClip.translated(-offset);
5698 }
5699 }
5700
5701 // Set backingstore flags.
5702 DrawWidgetFlags flags = DrawPaintOnScreen | DrawInvisible;
5703 if (renderFlags & QWidget::DrawWindowBackground)
5704 flags |= DrawAsRoot;
5705
5706 if (renderFlags & QWidget::DrawChildren)
5708 else
5710
5712
5713 // Render via backingstore.
5714 drawWidget(target, paintRegion, offset, flags, sharedPainter());
5715
5716 // Restore shared painter.
5717 if (oldSharedPainter)
5718 setSharedPainter(oldSharedPainter);
5719}
5720
5722 const QPoint &offset, DrawWidgetFlags flags
5723 , QPainter *sharedPainter, QWidgetRepaintManager *repaintManager)
5724{
5725 QWidget *w = nullptr;
5727 bool dirtyBoundingRect = true;
5728 const bool exludeOpaqueChildren = (flags & DontDrawOpaqueChildren);
5729 const bool excludeNativeChildren = (flags & DontDrawNativeChildren);
5730
5731 do {
5732 QWidget *x = qobject_cast<QWidget*>(siblings.at(index));
5733 if (x && !(exludeOpaqueChildren && x->d_func()->isOpaque) && !x->isHidden() && !x->isWindow()
5734 && !(excludeNativeChildren && x->internalWinId())) {
5735 if (dirtyBoundingRect) {
5736 boundingRect = rgn.boundingRect();
5737 dirtyBoundingRect = false;
5738 }
5739
5740 if (qRectIntersects(boundingRect, x->d_func()->effectiveRectFor(x->data->crect))) {
5741 w = x;
5742 break;
5743 }
5744 }
5745 --index;
5746 } while (index >= 0);
5747
5748 if (!w)
5749 return;
5750
5751 QWidgetPrivate *wd = w->d_func();
5752 const QPoint widgetPos(w->data->crect.topLeft());
5753 const bool hasMask = wd->extra && wd->extra->hasMask && !wd->graphicsEffect;
5754 if (index > 0) {
5755 QRegion wr(rgn);
5756 if (wd->isOpaque)
5757 wr -= hasMask ? wd->extra->mask.translated(widgetPos) : w->data->crect;
5758 paintSiblingsRecursive(pdev, siblings, --index, wr, offset, flags,
5759 sharedPainter, repaintManager);
5760 }
5761
5762 if (w->updatesEnabled()
5763#if QT_CONFIG(graphicsview)
5764 && (!w->d_func()->extra || !w->d_func()->extra->proxyWidget)
5765#endif // QT_CONFIG(graphicsview)
5766 ) {
5767 QRegion wRegion(rgn);
5768 wRegion &= wd->effectiveRectFor(w->data->crect);
5769 wRegion.translate(-widgetPos);
5770 if (hasMask)
5771 wRegion &= wd->extra->mask;
5772 wd->drawWidget(pdev, wRegion, offset + widgetPos, flags, sharedPainter, repaintManager);
5773 }
5774}
5775
5776#if QT_CONFIG(graphicseffect)
5777QRectF QWidgetEffectSourcePrivate::boundingRect(Qt::CoordinateSystem system) const
5778{
5779 if (system != Qt::DeviceCoordinates)
5780 return m_widget->rect();
5781
5782 if (Q_UNLIKELY(!context)) {
5783 // Device coordinates without context not yet supported.
5784 qWarning("QGraphicsEffectSource::boundingRect: Not yet implemented, lacking device context");
5785 return QRectF();
5786 }
5787
5788 return context->painter->worldTransform().mapRect(m_widget->rect());
5789}
5790
5791void QWidgetEffectSourcePrivate::draw(QPainter *painter)
5792{
5793 if (!context || context->painter != painter) {
5794 m_widget->render(painter);
5795 return;
5796 }
5797
5798 // The region saved in the context is neither clipped to the rect
5799 // nor the mask, so we have to clip it here before calling drawWidget.
5800 QRegion toBePainted = context->rgn;
5801 toBePainted &= m_widget->rect();
5802 QWidgetPrivate *wd = qt_widget_private(m_widget);
5803 if (wd->extra && wd->extra->hasMask)
5804 toBePainted &= wd->extra->mask;
5805
5806 wd->drawWidget(context->pdev, toBePainted, context->offset, context->flags,
5807 context->sharedPainter, context->repaintManager);
5808}
5809
5810QPixmap QWidgetEffectSourcePrivate::pixmap(Qt::CoordinateSystem system, QPoint *offset,
5812{
5813 const bool deviceCoordinates = (system == Qt::DeviceCoordinates);
5814 if (Q_UNLIKELY(!context && deviceCoordinates)) {
5815 // Device coordinates without context not yet supported.
5816 qWarning("QGraphicsEffectSource::pixmap: Not yet implemented, lacking device context");
5817 return QPixmap();
5818 }
5819
5820 QPoint pixmapOffset;
5821 QRectF sourceRect = m_widget->rect();
5822
5823 if (deviceCoordinates) {
5824 const QTransform &painterTransform = context->painter->worldTransform();
5825 sourceRect = painterTransform.mapRect(sourceRect);
5826 pixmapOffset = painterTransform.map(pixmapOffset);
5827 }
5828
5829 QRect effectRect;
5830
5832 effectRect = m_widget->graphicsEffect()->boundingRectFor(sourceRect).toAlignedRect();
5834 effectRect = sourceRect.adjusted(-1, -1, 1, 1).toAlignedRect();
5835 else
5836 effectRect = sourceRect.toAlignedRect();
5837
5838 if (offset)
5839 *offset = effectRect.topLeft();
5840
5841 pixmapOffset -= effectRect.topLeft();
5842
5843 qreal dpr(1.0);
5844 if (const auto *paintDevice = context->painter->device())
5845 dpr = paintDevice->devicePixelRatio();
5846 else
5847 qWarning("QWidgetEffectSourcePrivate::pixmap: Painter not active");
5848 QPixmap pixmap(effectRect.size() * dpr);
5849 pixmap.setDevicePixelRatio(dpr);
5850
5851 pixmap.fill(Qt::transparent);
5852 m_widget->render(&pixmap, pixmapOffset, QRegion(), QWidget::DrawChildren);
5853 return pixmap;
5854}
5855#endif // QT_CONFIG(graphicseffect)
5856
5857#if QT_CONFIG(graphicsview)
5866QGraphicsProxyWidget *QWidgetPrivate::nearestGraphicsProxyWidget(const QWidget *origin)
5867{
5868 if (origin) {
5869 const auto &extra = origin->d_func()->extra;
5870 if (extra && extra->proxyWidget)
5871 return extra->proxyWidget;
5872 return nearestGraphicsProxyWidget(origin->parentWidget());
5873 }
5874 return nullptr;
5875}
5876#endif
5877
5894{
5895 Q_Q(QWidget);
5896 if (locale == loc && !forceUpdate)
5897 return;
5898
5899 locale = loc;
5900
5901 if (!children.isEmpty()) {
5902 for (int i = 0; i < children.size(); ++i) {
5904 if (!w)
5905 continue;
5906 if (w->testAttribute(Qt::WA_SetLocale))
5907 continue;
5908 if (w->isWindow() && !w->testAttribute(Qt::WA_WindowPropagation))
5909 continue;
5910 w->d_func()->setLocale_helper(loc, forceUpdate);
5911 }
5912 }
5915}
5916
5917void QWidget::setLocale(const QLocale &locale)
5918{
5919 Q_D(QWidget);
5920
5922 d->setLocale_helper(locale);
5923}
5924
5926{
5927 Q_D(const QWidget);
5928
5929 return d->locale;
5930}
5931
5933{
5934 Q_Q(const QWidget);
5935
5936 if (!q->testAttribute(Qt::WA_SetLocale)) {
5937 QWidget *parent = q->parentWidget();
5938 setLocale_helper(!parent || (q->isWindow() && !q->testAttribute(Qt::WA_WindowPropagation))
5939 ? QLocale() : parent->locale());
5940 }
5941}
5942
5944{
5945 Q_D(QWidget);
5947 d->resolveLocale();
5948}
5949
5974{
5975 Q_D(const QWidget);
5976 if (d->extra && d->extra->topextra) {
5977 if (!d->extra->topextra->caption.isEmpty())
5978 return d->extra->topextra->caption;
5979 if (!d->extra->topextra->filePath.isEmpty())
5980 return QFileInfo(d->extra->topextra->filePath).fileName() + "[*]"_L1;
5981 }
5982 return QString();
5983}
5984
5997{
5999
6000 QString cap = title;
6001 if (cap.isEmpty())
6002 return cap;
6003
6004 const auto placeHolder = "[*]"_L1;
6005 int index = cap.indexOf(placeHolder);
6006
6007 // here the magic begins
6008 while (index != -1) {
6009 index += placeHolder.size();
6010 int count = 1;
6011 while (cap.indexOf(placeHolder, index) == index) {
6012 ++count;
6013 index += placeHolder.size();
6014 }
6015
6016 if (count%2) { // odd number of [*] -> replace last one
6017 int lastIndex = cap.lastIndexOf(placeHolder, index - 1);
6020 cap.replace(lastIndex, 3, QWidget::tr("*"));
6021 else
6022 cap.remove(lastIndex, 3);
6023 }
6024
6025 index = cap.indexOf(placeHolder, index);
6026 }
6027
6028 cap.replace("[*][*]"_L1, placeHolder);
6029
6030 return cap;
6031}
6032
6034{
6035 Q_Q(QWidget);
6036 if (q->testAttribute(Qt::WA_WState_Created))
6038}
6039
6041{
6042 Q_Q(QWidget);
6043 if (!q->isWindow())
6044 return;
6045
6046 if (QWindow *window = q->windowHandle())
6047 window->setTitle(caption);
6048
6049}
6050
6052{
6053 Q_Q(QWidget);
6054 if (q->testAttribute(Qt::WA_WState_Created))
6056}
6057
6059{
6060#if QT_CONFIG(xcb)
6061 Q_Q(QWidget);
6062 // ### The QWidget property is deprecated, but the XCB window function is not.
6063 // It should remain available for the rare application that needs it.
6064 if (QWindow *window = q->windowHandle()) {
6065 if (auto *xcbWindow = dynamic_cast<QXcbWindow*>(window->handle()))
6066 xcbWindow->setWindowIconText(iconText);
6067 }
6068#else
6069 Q_UNUSED(iconText);
6070#endif
6071}
6072
6086{
6087 if (QWidget::windowIconText() == iconText)
6088 return;
6089
6090 Q_D(QWidget);
6091 d->topData()->iconText = iconText;
6092 d->setWindowIconText_helper(iconText);
6093
6096
6097 emit windowIconTextChanged(iconText);
6098}
6099
6110{
6111 if (QWidget::windowTitle() == title && !title.isEmpty() && !title.isNull())
6112 return;
6113
6114 Q_D(QWidget);
6115 d->topData()->caption = title;
6116 d->setWindowTitle_helper(title);
6117
6120
6122}
6123
6124
6140{
6141 const QWidget *w = this;
6142 while (w) {
6143 const QWidgetPrivate *d = w->d_func();
6144 if (d->extra && d->extra->topextra && d->extra->topextra->icon)
6145 return *d->extra->topextra->icon;
6146 w = w->parentWidget();
6147 }
6148 return QApplication::windowIcon();
6149}
6150
6152{
6153 Q_Q(QWidget);
6155
6156 // Do not send the event if the widget is a top level.
6157 // In that case, setWindowIcon_sys does it, and event propagation from
6158 // QWidgetWindow to the top level QWidget ensures that the event reaches
6159 // the top level anyhow
6160 if (!q->windowHandle())
6162 for (int i = 0; i < children.size(); ++i) {
6164 if (w && !w->isWindow())
6166 }
6167}
6168
6179{
6180 Q_D(QWidget);
6181
6183 d->createTLExtra();
6184
6185 if (!d->extra->topextra->icon)
6186 d->extra->topextra->icon = std::make_unique<QIcon>(icon);
6187 else
6188 *d->extra->topextra->icon = icon;
6189
6190 d->setWindowIcon_sys();
6191 d->setWindowIcon_helper();
6192
6194}
6195
6197{
6198 Q_Q(QWidget);
6199 if (QWindow *window = q->windowHandle())
6200 window->setIcon(q->windowIcon());
6201}
6202
6219{
6220 Q_D(const QWidget);
6221 return (d->extra && d->extra->topextra) ? d->extra->topextra->iconText : QString();
6222}
6223
6249{
6250 Q_D(const QWidget);
6251 return (d->extra && d->extra->topextra) ? d->extra->topextra->filePath : QString();
6252}
6253
6255{
6256 if (filePath == windowFilePath())
6257 return;
6258
6259 Q_D(QWidget);
6260
6261 d->createTLExtra();
6262 d->extra->topextra->filePath = filePath;
6263 d->setWindowFilePath_helper(filePath);
6264}
6265
6267{
6268 if (extra->topextra && extra->topextra->caption.isEmpty()) {
6269#ifdef Q_OS_MAC
6271#else
6272 Q_Q(QWidget);
6273 Q_UNUSED(filePath);
6274 setWindowTitle_helper(q->windowTitle());
6275#endif
6276 }
6277#ifdef Q_OS_MAC
6278 setWindowFilePath_sys(filePath);
6279#endif
6280}
6281
6283{
6284 Q_Q(QWidget);
6285 if (!q->isWindow())
6286 return;
6287
6288 if (QWindow *window = q->windowHandle())
6289 window->setFilePath(filePath);
6290}
6291
6299{
6300 Q_D(const QWidget);
6301 return (d->extra && d->extra->topextra) ? d->extra->topextra->role : QString();
6302}
6303
6309{
6310#if QT_CONFIG(xcb)
6311 Q_D(QWidget);
6312 d->createTLExtra();
6313 d->topData()->role = role;
6314 if (windowHandle()) {
6315 if (auto *xcbWindow = dynamic_cast<QXcbWindow*>(windowHandle()->handle()))
6316 xcbWindow->setWindowRole(role);
6317 }
6318#else
6319 Q_UNUSED(role);
6320#endif
6321}
6322
6373{
6374 Q_D(QWidget);
6375 if (!w && !d->extra)
6376 return;
6377
6378 for (QWidget* fp = w; fp; fp = fp->focusProxy()) {
6379 if (Q_UNLIKELY(fp == this)) {
6380 qWarning("QWidget: %s (%s) already in focus proxy chain", metaObject()->className(), objectName().toLocal8Bit().constData());
6381 return;
6382 }
6383 }
6384
6385 const bool moveFocusToProxy = (QApplicationPrivate::focus_widget == this);
6386
6387 d->createExtra();
6388 d->extra->focus_proxy = w;
6389
6390 if (w && isAncestorOf(w)) {
6391 // If the focus proxy is a child of this (so this is a compound widget), then
6392 // we need to make sure that this widget is immediately in front of its own children
6393 // in the focus chain. Otherwise focusNextPrev_helper might jump over unrelated
6394 // widgets that are positioned between this compound widget, and its proxy in
6395 // the focus chain.
6396 const QWidget *parentOfW = w->parentWidget();
6397 Q_ASSERT(parentOfW); // can't be nullptr since we are an ancestor of w
6398 QWidget *firstChild = nullptr;
6399 const auto childList = children();
6400 for (QObject *child : childList) {
6401 if ((firstChild = qobject_cast<QWidget *>(child)))
6402 break;
6403 }
6404 Q_ASSERT(firstChild); // can't be nullptr since w is a child
6405 QWidget *oldNext = d->focus_next;
6406 QWidget *oldPrev = d->focus_prev;
6407 oldNext->d_func()->focus_prev = oldPrev;
6408 oldPrev->d_func()->focus_next = oldNext;
6409
6410 oldPrev = firstChild->d_func()->focus_prev;
6411 d->focus_next = firstChild;
6412 d->focus_prev = oldPrev;
6413 oldPrev->d_func()->focus_next = this;
6414 firstChild->d_func()->focus_prev = this;
6415 } else if (w && w->isAncestorOf(this)) {
6416 // If the focus proxy is a parent, 'this' has to be inserted directly after its parent in the focus chain
6417 // remove it from the chain and insert this into the focus chain after its parent
6418
6419 // is this the case already?
6420 QWidget *parentsNext = w->d_func()->focus_next;
6421 if (parentsNext == this) {
6422 // nothing to do.
6423 Q_ASSERT(d->focus_prev == w);
6424 } else {
6425 // Remove 'this' from the focus chain by making prev and next point directly to each other
6426 QWidget *myOldNext = d->focus_next;
6427 QWidget *myOldPrev = d->focus_prev;
6428 if (myOldNext && myOldPrev) {
6429 myOldNext->d_func()->focus_prev = myOldPrev;
6430 myOldPrev->d_func()->focus_next = myOldNext;
6431 }
6432
6433 // Insert 'this' behind the parent
6434 w->d_func()->focus_next = this;
6435 d->focus_prev = w;
6436 d->focus_next = parentsNext;
6437 parentsNext->d_func()->focus_prev = this;
6438 }
6439 }
6440
6441 if (moveFocusToProxy)
6443}
6444
6445
6453{
6454 Q_D(const QWidget);
6455 return d->extra ? d->extra->focus_proxy.data() : nullptr;
6456}
6457
6458
6472{
6473 const QWidget* w = this;
6474 while (w->d_func()->extra && w->d_func()->extra->focus_proxy)
6475 w = w->d_func()->extra->focus_proxy;
6476#if QT_CONFIG(graphicsview)
6477 if (QWidget *window = w->window()) {
6478 const auto &e = window->d_func()->extra;
6479 if (e && e->proxyWidget && e->proxyWidget->hasFocus() && window->focusWidget() == w)
6480 return true;
6481 }
6482#endif // QT_CONFIG(graphicsview)
6483 return (QApplication::focusWidget() == w);
6484}
6485
6522{
6523 if (!isEnabled())
6524 return;
6525
6526 QWidget *f = d_func()->deepestFocusProxy();
6527 if (!f)
6528 f = this;
6529
6531 return;
6532
6533#if QT_CONFIG(graphicsview)
6534 QWidget *previousProxyFocus = nullptr;
6535 if (const auto &topData = window()->d_func()->extra) {
6536 if (topData->proxyWidget && topData->proxyWidget->hasFocus()) {
6537 previousProxyFocus = topData->proxyWidget->widget()->focusWidget();
6538 if (previousProxyFocus && previousProxyFocus->focusProxy())
6539 previousProxyFocus = previousProxyFocus->focusProxy();
6540 if (previousProxyFocus == f && !topData->proxyWidget->d_func()->proxyIsGivingFocus)
6541 return;
6542 }
6543 }
6544#endif
6545
6546#if QT_CONFIG(graphicsview)
6547 // Update proxy state
6548 if (const auto &topData = window()->d_func()->extra) {
6549 if (topData->proxyWidget && !topData->proxyWidget->hasFocus()) {
6550 f->d_func()->updateFocusChild();
6551 topData->proxyWidget->d_func()->focusFromWidgetToProxy = 1;
6552 topData->proxyWidget->setFocus(reason);
6553 topData->proxyWidget->d_func()->focusFromWidgetToProxy = 0;
6554 }
6555 }
6556#endif
6557
6558 if (f->isActiveWindow()) {
6560 if (prev) {
6561 if (reason != Qt::PopupFocusReason && reason != Qt::MenuBarFocusReason
6564 }
6565
6566 if (reason != Qt::NoFocusReason) {
6567 QFocusEvent focusAboutToChange(QEvent::FocusAboutToChange, reason);
6568 QCoreApplication::sendEvent(prev, &focusAboutToChange);
6569 }
6570 }
6571
6572 f->d_func()->updateFocusChild();
6573
6575#if QT_CONFIG(accessibility)
6576 // menus update the focus manually and this would create bogus events
6577 if (!(f->inherits("QMenuBar") || f->inherits("QMenu") || f->inherits("QMenuItem")))
6578 {
6579 QAccessibleEvent event(f, QAccessible::Focus);
6580 QAccessible::updateAccessibility(&event);
6581 }
6582#endif
6583#if QT_CONFIG(graphicsview)
6584 if (const auto &topData = window()->d_func()->extra) {
6585 if (topData->proxyWidget) {
6586 if (previousProxyFocus && previousProxyFocus != f) {
6587 // Send event to self
6589 QPointer<QWidget> that = previousProxyFocus;
6590 QCoreApplication::sendEvent(previousProxyFocus, &event);
6591 if (that)
6592 QCoreApplication::sendEvent(that->style(), &event);
6593 }
6594 if (!isHidden()) {
6595#if QT_CONFIG(graphicsview)
6596 // Update proxy state
6597 if (const auto &topData = window()->d_func()->extra)
6598 if (topData->proxyWidget && topData->proxyWidget->hasFocus())
6599 topData->proxyWidget->d_func()->updateProxyInputMethodAcceptanceFromWidget();
6600#endif
6601 // Send event to self
6603 QPointer<QWidget> that = f;
6605 if (that)
6606 QCoreApplication::sendEvent(that->style(), &event);
6607 }
6608 }
6609 }
6610#endif
6611 } else {
6612 f->d_func()->updateFocusChild();
6613 }
6614}
6615
6616
6624{
6625 Q_Q(const QWidget);
6626
6627 QWidget *focusProxy = q->focusProxy();
6628 if (!focusProxy)
6629 return nullptr;
6630
6631 while (QWidget *nextFocusProxy = focusProxy->focusProxy())
6632 focusProxy = nextFocusProxy;
6633
6634 return focusProxy;
6635}
6636
6637static inline bool isEmbedded(const QWindow *w)
6638{
6639 const auto platformWindow = w->handle();
6640 return platformWindow && platformWindow->isEmbedded();
6641}
6642
6644{
6645 Q_Q(QWidget);
6646 // Embedded native widget may have taken the focus; get it back to toplevel
6647 // if that is the case (QTBUG-25852)
6648 // Do not activate in case the popup menu opens another application (QTBUG-70810)
6649 // unless the application is embedded (QTBUG-71991).
6650 if (QWindow *nativeWindow = q->testAttribute(Qt::WA_WState_Created) ? q->window()->windowHandle() : nullptr) {
6654 || isEmbedded(nativeWindow))) {
6655 nativeWindow->requestActivate();
6656 }
6657 }
6658}
6659
6660// updates focus_child on parent widgets to point into this widget
6662{
6663 Q_Q(QWidget);
6664
6665 QWidget *w = q;
6666 if (q->isHidden()) {
6667 while (w && w->isHidden()) {
6668 w->d_func()->focus_child = q;
6669 w = w->isWindow() ? nullptr : w->parentWidget();
6670 }
6671 } else {
6672 while (w) {
6673 w->d_func()->focus_child = q;
6674 w = w->isWindow() ? nullptr : w->parentWidget();
6675 }
6676 }
6677
6678 if (QTLWExtra *extra = q->window()->d_func()->maybeTopData()) {
6679 if (extra->window)
6680 emit extra->window->focusObjectChanged(q);
6681 }
6682}
6683
6707{
6708 if (hasFocus()) {
6711
6712 QFocusEvent focusAboutToChange(QEvent::FocusAboutToChange);
6713 QCoreApplication::sendEvent(this, &focusAboutToChange);
6714 }
6715
6716 QTLWExtra *extra = window()->d_func()->maybeTopData();
6717 QObject *originalFocusObject = nullptr;
6718 if (extra && extra->window) {
6719 originalFocusObject = extra->window->focusObject();
6720 // the window's focus object might already be nullptr if we are in the destructor, but we still
6721 // need to update QGuiApplication and input context if we have a focus widget.
6722 if (!originalFocusObject)
6723 originalFocusObject = focusWidget();
6724 }
6725
6726 QWidget *w = this;
6727 while (w) {
6728 // Just like setFocus(), we update (clear) the focus_child of our parents
6729 if (w->d_func()->focus_child == this)
6730 w->d_func()->focus_child = nullptr;
6731 w = w->parentWidget();
6732 }
6733
6734 // We've potentially cleared the focus_child of our parents, so we need
6735 // to report this to the rest of Qt. Note that the focus_child is not the same
6736 // thing as the application's focusWidget, which is why this piece of code is
6737 // not inside a hasFocus() block.
6738 if (originalFocusObject && originalFocusObject != extra->window->focusObject())
6739 emit extra->window->focusObjectChanged(extra->window->focusObject());
6740
6741#if QT_CONFIG(graphicsview)
6742 const auto &topData = d_func()->extra;
6743 if (topData && topData->proxyWidget)
6744 topData->proxyWidget->clearFocus();
6745#endif
6746
6747 if (hasFocus()) {
6748 // Update proxy state
6750#if QT_CONFIG(accessibility)
6751 QAccessibleEvent event(this, QAccessible::Focus);
6752 QAccessible::updateAccessibility(&event);
6753#endif
6754 }
6755}
6756
6757
6801{
6802 QWidget* p = parentWidget();
6803 bool isSubWindow = (windowType() == Qt::SubWindow);
6804 if (!isWindow() && !isSubWindow && p)
6805 return p->focusNextPrevChild(next);
6806#if QT_CONFIG(graphicsview)
6807 Q_D(QWidget);
6808 if (d->extra && d->extra->proxyWidget)
6809 return d->extra->proxyWidget->focusNextPrevChild(next);
6810#endif
6811
6812 bool wrappingOccurred = false;
6814 &wrappingOccurred);
6815 if (!w) return false;
6816
6818
6819 /* If we are about to wrap the focus chain, give the platform
6820 * implementation a chance to alter the wrapping behavior. This is
6821 * especially needed when the window is embedded in a window created by
6822 * another process.
6823 */
6824 if (wrappingOccurred) {
6826 if (window != nullptr) {
6828
6829 if (winp->platformWindow != nullptr) {
6831 event.ignore();
6833 if (event.isAccepted()) return true;
6834 }
6835 }
6836 }
6837
6838 w->setFocus(reason);
6839 return true;
6840}
6841
6852{
6853 return const_cast<QWidget *>(d_func()->focus_child);
6854}
6855
6857{
6858 Q_Q(QWidget);
6860 return proxy ? proxy : q;
6861}
6862
6869{
6870 return const_cast<QWidget *>(d_func()->focus_next);
6871}
6872
6882{
6883 return const_cast<QWidget *>(d_func()->focus_prev);
6884}
6885
6902{
6903 QWidget *tlw = window();
6904 if (tlw == QApplication::activeWindow() || (isVisible() && (tlw->windowType() == Qt::Popup)))
6905 return true;
6906
6907#if QT_CONFIG(graphicsview)
6908 if (const auto &tlwExtra = tlw->d_func()->extra) {
6909 if (isVisible() && tlwExtra->proxyWidget)
6910 return tlwExtra->proxyWidget->isActiveWindow();
6911 }
6912#endif
6913
6914 if (style()->styleHint(QStyle::SH_Widget_ShareActivation, nullptr, this)) {
6915 if (tlw->windowType() == Qt::Tool &&
6916 !tlw->isModal() &&
6917 (!tlw->parentWidget() || tlw->parentWidget()->isActiveWindow()))
6918 return true;
6920 while(w && tlw->windowType() == Qt::Tool &&
6921 !w->isModal() && w->parentWidget()) {
6922 w = w->parentWidget()->window();
6923 if (w == tlw)
6924 return true;
6925 }
6926 }
6927
6928 // Check for an active window container
6930 while (ww) {
6931 QWidgetWindow *qww = qobject_cast<QWidgetWindow *>(ww);
6932 QWindowContainer *qwc = qww ? qobject_cast<QWindowContainer *>(qww->widget()) : 0;
6933 if (qwc && qwc->topLevelWidget() == tlw)
6934 return true;
6935 ww = ww->parent();
6936 }
6937 }
6938
6939 // Check if platform adaptation thinks the window is active. This is necessary for
6940 // example in case of ActiveQt servers that are embedded into another application.
6941 // Those are separate processes that are not part of the parent application Qt window/widget
6942 // hierarchy, so they need to rely on native methods to determine if they are part of the
6943 // active window.
6944 if (const QWindow *w = tlw->windowHandle()) {
6945 if (w->handle())
6946 return w->handle()->isActive();
6947 }
6948
6949 return false;
6950}
6951
7003{
7004 if (!first || !second || first == second
7006 || second->focusPolicy() == Qt::NoFocus)
7007 return;
7008
7009 if (Q_UNLIKELY(first->window() != second->window())) {
7010 qWarning("QWidget::setTabOrder: 'first' and 'second' must be in the same window");
7011 return;
7012 }
7013
7014 const auto determineLastFocusChild = [](QWidget *target, QWidget *noFurtherThan)
7015 {
7016 // Since we need to repeat the same logic for both 'first' and 'second', we add a function that
7017 // determines the last focus child for a widget, taking proxies and compound widgets into account.
7018 // If the target is not a compound widget (it doesn't have a focus proxy that points to a child),
7019 // 'lastFocusChild' will be set to the target itself.
7020 QWidget *lastFocusChild = target;
7021
7022 QWidget *focusProxy = target->d_func()->deepestFocusProxy();
7023 if (!focusProxy) {
7024 // QTBUG-81097: Another case is possible here. We can have a child
7025 // widget, that sets its focusProxy() to the parent (target).
7026 // An example of such widget is a QLineEdit, nested into
7027 // a QAbstractSpinBox. In this case such widget should be considered
7028 // the last focus child.
7029 for (auto *object : target->children()) {
7030 QWidget *w = qobject_cast<QWidget*>(object);
7031 if (w && w->focusProxy() == target) {
7032 lastFocusChild = w;
7033 break;
7034 }
7035 }
7036 } else if (target->isAncestorOf(focusProxy)) {
7037 lastFocusChild = focusProxy;
7038 for (QWidget *focusNext = lastFocusChild->d_func()->focus_next;
7039 focusNext != focusProxy && target->isAncestorOf(focusNext) && focusNext->window() == focusProxy->window();
7040 focusNext = focusNext->d_func()->focus_next) {
7041 if (focusNext == noFurtherThan)
7042 break;
7043 if (focusNext->focusPolicy() != Qt::NoFocus)
7044 lastFocusChild = focusNext;
7045 }
7046 }
7047 return lastFocusChild;
7048 };
7049 auto setPrev = [](QWidget *w, QWidget *prev) {
7050 w->d_func()->focus_prev = prev;
7051 };
7052 auto setNext = [](QWidget *w, QWidget *next) {
7053 w->d_func()->focus_next = next;
7054 };
7055
7056 // detect inflection in case we have compound widgets
7057 QWidget *lastFocusChildOfFirst = determineLastFocusChild(first, second);
7058 if (lastFocusChildOfFirst == second)
7059 lastFocusChildOfFirst = first;
7060 QWidget *lastFocusChildOfSecond = determineLastFocusChild(second, first);
7061 if (lastFocusChildOfSecond == first)
7062 lastFocusChildOfSecond = second;
7063
7064 // remove the second widget from the chain
7065 {
7066 QWidget *oldPrev = second->d_func()->focus_prev;
7067 QWidget *prevWithFocus = oldPrev;
7068 while (prevWithFocus->focusPolicy() == Qt::NoFocus)
7069 prevWithFocus = prevWithFocus->d_func()->focus_prev;
7070 // only widgets between first and second -> all is fine
7071 if (prevWithFocus == first)
7072 return;
7073 QWidget *oldNext = lastFocusChildOfSecond->d_func()->focus_next;
7074 setPrev(oldNext, oldPrev);
7075 setNext(oldPrev, oldNext);
7076 }
7077
7078 // insert the second widget into the chain
7079 {
7080 QWidget *oldNext = lastFocusChildOfFirst->d_func()->focus_next;
7081 setPrev(second, lastFocusChildOfFirst);
7082 setNext(lastFocusChildOfFirst, second);
7083 setPrev(oldNext, lastFocusChildOfSecond);
7084 setNext(lastFocusChildOfSecond, oldNext);
7085 }
7086}
7087
7101{
7102 Q_Q(QWidget);
7103 if (oldtlw == q->window())
7104 return; // nothing to do
7105
7106 if (focus_child)
7108
7109 // separate the focus chain into new (children of myself) and old (the rest)
7110 QWidget *firstOld = nullptr;
7111 //QWidget *firstNew = q; //invariant
7112 QWidget *o = nullptr; // last in the old list
7113 QWidget *n = q; // last in the new list
7114
7115 bool prevWasNew = true;
7116 QWidget *w = focus_next;
7117
7118 //Note: for efficiency, we do not maintain the list invariant inside the loop
7119 //we append items to the relevant list, and we optimize by not changing pointers
7120 //when subsequent items are going into the same list.
7121 while (w != q) {
7122 bool currentIsNew = q->isAncestorOf(w);
7123 if (currentIsNew) {
7124 if (!prevWasNew) {
7125 //prev was old -- append to new list
7126 n->d_func()->focus_next = w;
7127 w->d_func()->focus_prev = n;
7128 }
7129 n = w;
7130 } else {
7131 if (prevWasNew) {
7132 //prev was new -- append to old list, if there is one
7133 if (o) {
7134 o->d_func()->focus_next = w;
7135 w->d_func()->focus_prev = o;
7136 } else {
7137 // "create" the old list
7138 firstOld = w;
7139 }
7140 }
7141 o = w;
7142 }
7143 w = w->d_func()->focus_next;
7144 prevWasNew = currentIsNew;
7145 }
7146
7147 //repair the old list:
7148 if (firstOld) {
7149 o->d_func()->focus_next = firstOld;
7150 firstOld->d_func()->focus_prev = o;
7151 }
7152
7153 if (!q->isWindow()) {
7154 QWidget *topLevel = q->window();
7155 //insert new chain into toplevel's chain
7156
7157 QWidget *prev = topLevel->d_func()->focus_prev;
7158
7159 topLevel->d_func()->focus_prev = n;
7160 prev->d_func()->focus_next = q;
7161
7162 focus_prev = prev;
7163 n->d_func()->focus_next = topLevel;
7164 } else {
7165 //repair the new list
7166 n->d_func()->focus_next = q;
7167 focus_prev = n;
7168 }
7169
7170}
7171
7180{
7181 Q_D(const QWidget);
7182 if (isWindow() && !(windowType() == Qt::Popup)) {
7183 QRect fs = d->frameStrut();
7184 return QSize(data->crect.width() + fs.left() + fs.right(),
7185 data->crect.height() + fs.top() + fs.bottom());
7186 }
7187 return data->crect.size();
7188}
7189
7198{
7199 Q_D(QWidget);
7202 if (isWindow())
7203 d->topData()->posIncludesFrame = false;
7204 d->setGeometry_sys(p.x() + geometry().x() - QWidget::x(),
7205 p.y() + geometry().y() - QWidget::y(),
7206 width(), height(), true);
7207 d->setDirtyOpaqueRegion();
7208 } else {
7209 // no frame yet: see also QWidgetPrivate::fixPosIncludesFrame(), QWindowPrivate::PositionPolicy.
7210 if (isWindow())
7211 d->topData()->posIncludesFrame = true;
7212 data->crect.moveTopLeft(p); // no frame yet
7214 }
7215
7216 if (d->extra && d->extra->hasWindowContainer)
7218}
7219
7220// move() was invoked with Qt::WA_WState_Created not set (frame geometry
7221// unknown), that is, crect has a position including the frame.
7222// If we can determine the frame strut, fix that and clear the flag.
7223// FIXME: This does not play well with window states other than
7224// Qt::WindowNoState, as we depend on calling setGeometry() on the
7225// platform window after fixing up the position so that the new
7226// geometry is reflected in the platform window, but when the frame
7227// comes in after the window has been shown (e.g. maximized), we're
7228// not in a position to do that kind of fixup.
7230{
7231 Q_Q(QWidget);
7232 if (QTLWExtra *te = maybeTopData()) {
7233 if (te->posIncludesFrame) {
7234 // For Qt::WA_DontShowOnScreen, assume a frame of 0 (for
7235 // example, in QGraphicsProxyWidget).
7236 if (q->testAttribute(Qt::WA_DontShowOnScreen)) {
7237 te->posIncludesFrame = 0;
7238 } else {
7239 if (q->windowHandle() && q->windowHandle()->handle()) {
7241 if (!q->data->fstrut_dirty) {
7242 data.crect.translate(te->frameStrut.x(), te->frameStrut.y());
7243 te->posIncludesFrame = 0;
7244 }
7245 } // windowHandle()
7246 } // !WA_DontShowOnScreen
7247 } // posIncludesFrame
7248 } // QTLWExtra
7249}
7250
7258{
7259 Q_D(QWidget);
7262 d->fixPosIncludesFrame();
7263 d->setGeometry_sys(geometry().x(), geometry().y(), s.width(), s.height(), false);
7264 d->setDirtyOpaqueRegion();
7265 } else {
7266 const auto oldRect = data->crect;
7267 data->crect.setSize(s.boundedTo(maximumSize()).expandedTo(minimumSize()));
7268 if (oldRect != data->crect)
7270 }
7271}
7272
7274{
7275 Q_D(QWidget);
7278 if (isWindow())
7279 d->topData()->posIncludesFrame = 0;
7281 d->setGeometry_sys(r.x(), r.y(), r.width(), r.height(), true);
7282 d->setDirtyOpaqueRegion();
7283 } else {
7284 const auto oldRect = data->crect;
7285 data->crect.setTopLeft(r.topLeft());
7286 data->crect.setSize(r.size().boundedTo(maximumSize()).expandedTo(minimumSize()));
7287 if (oldRect != data->crect) {
7290 }
7291 }
7292
7293 if (d->extra && d->extra->hasWindowContainer)
7295}
7296
7297void QWidgetPrivate::setGeometry_sys(int x, int y, int w, int h, bool isMove)
7298{
7299 Q_Q(QWidget);
7300 if (extra) { // any size restrictions?
7301 w = qMin(w,extra->maxw);
7302 h = qMin(h,extra->maxh);
7303 w = qMax(w,extra->minw);
7304 h = qMax(h,extra->minh);
7305 }
7306
7307 if (q->isWindow() && q->windowHandle()) {
7310 x = 0;
7311 y = 0;
7312 w = q->windowHandle()->width();
7313 h = q->windowHandle()->height();
7314 }
7315 }
7316
7317 QPoint oldp = q->geometry().topLeft();
7318 QSize olds = q->size();
7319 QRect r(x, y, w, h);
7320
7321 bool isResize = olds != r.size();
7322 if (!isMove)
7323 isMove = oldp != r.topLeft();
7324
7325
7326 // We only care about stuff that changes the geometry, or may
7327 // cause the window manager to change its state
7328 if (r.size() == olds && oldp == r.topLeft())
7329 return;
7330
7331 if (!data.in_set_window_state) {
7332 q->data->window_state &= ~Qt::WindowMaximized;
7333 q->data->window_state &= ~Qt::WindowFullScreen;
7334 if (q->isWindow())
7335 topData()->normalGeometry = QRect(0, 0, -1, -1);
7336 }
7337
7338 QPoint oldPos = q->pos();
7339 data.crect = r;
7340
7341 bool needsShow = false;
7342
7343 if (q->isWindow() || q->windowHandle()) {
7344 if (!(data.window_state & Qt::WindowFullScreen) && (w == 0 || h == 0)) {
7345 q->setAttribute(Qt::WA_OutsideWSRange, true);
7346 if (q->isVisible())
7347 hide_sys();
7348 data.crect = QRect(x, y, w, h);
7349 } else if (q->testAttribute(Qt::WA_OutsideWSRange)) {
7350 q->setAttribute(Qt::WA_OutsideWSRange, false);
7351 needsShow = true;
7352 }
7353 }
7354
7355 if (q->isVisible()) {
7356 if (!q->testAttribute(Qt::WA_DontShowOnScreen) && !q->testAttribute(Qt::WA_OutsideWSRange)) {
7357 if (QWindow *win = q->windowHandle()) {
7358 if (q->isWindow()) {
7359 if (isResize && !isMove)
7360 win->resize(w, h);
7361 else if (isMove && !isResize)
7362 win->setPosition(x, y);
7363 else
7364 win->setGeometry(q->geometry());
7365 } else {
7366 QPoint posInNativeParent = q->mapTo(q->nativeParentWidget(),QPoint());
7367 win->setGeometry(QRect(posInNativeParent,r.size()));
7368 }
7369
7370 if (needsShow)
7371 show_sys();
7372 }
7373
7374 if (!q->isWindow()) {
7375 if (renderToTexture) {
7376 QRegion updateRegion(q->geometry());
7377 updateRegion += QRect(oldPos, olds);
7378 q->parentWidget()->d_func()->invalidateBackingStore(updateRegion);
7379 } else if (isMove && !isResize) {
7380 moveRect(QRect(oldPos, olds), x - oldPos.x(), y - oldPos.y());
7381 } else {
7383 }
7384 }
7385 }
7386
7387 if (isMove) {
7388 QMoveEvent e(q->pos(), oldPos);
7390 }
7391 if (isResize) {
7392 QResizeEvent e(r.size(), olds);
7394 if (q->windowHandle())
7395 q->update();
7396 }
7397 } else { // not visible
7398 if (isMove && q->pos() != oldPos)
7399 q->setAttribute(Qt::WA_PendingMoveEvent, true);
7400 if (isResize)
7401 q->setAttribute(Qt::WA_PendingResizeEvent, true);
7402 }
7403
7404}
7405
7424{
7427 stream.setVersion(QDataStream::Qt_4_0);
7428 const quint32 magicNumber = 0x1D9D0CB;
7429 // Version history:
7430 // - Qt 4.2 - 4.8.6, 5.0 - 5.3 : Version 1.0
7431 // - Qt 4.8.6 - today, 5.4 - today: Version 2.0, save screen width in addition to check for high DPI scaling.
7432 // - Qt 5.12 - today : Version 3.0, save QWidget::geometry()
7433 quint16 majorVersion = 3;
7434 quint16 minorVersion = 0;
7435 const int screenNumber = QGuiApplication::screens().indexOf(screen());
7436 stream << magicNumber
7437 << majorVersion
7438 << minorVersion
7439 << frameGeometry()
7440 << normalGeometry()
7441 << qint32(screenNumber)
7444 << qint32(screen()->geometry().width()) // added in 2.0
7445 << geometry(); // added in 3.0
7446 return array;
7447}
7448
7472void QWidgetPrivate::checkRestoredGeometry(const QRect &availableGeometry, QRect *restoredGeometry,
7473 int frameHeight)
7474{
7475 // compare with restored geometry's height increased by frameHeight
7476 const int height = restoredGeometry->height() + frameHeight;
7477
7478 // Step 1: Resize if necessary:
7479 // make height / width 2px smaller than screen, because an exact match would be fullscreen
7480 if (availableGeometry.height() <= height)
7481 restoredGeometry->setHeight(availableGeometry.height() - 2 - frameHeight);
7482 if (availableGeometry.width() <= restoredGeometry->width())
7483 restoredGeometry->setWidth(availableGeometry.width() - 2);
7484
7485 // Step 2: Move if necessary:
7486 // Construct a rectangle from restored Geometry adjusted by frameHeight
7487 const QRect restored = restoredGeometry->adjusted(0, -frameHeight, 0, 0);
7488
7489 // Return if restoredGeometry (including frame) fits into screen
7490 if (availableGeometry.contains(restored))
7491 return;
7492
7493 // (size is correct, but at least one edge is off screen)
7494
7495 // Top out of bounds => move down
7496 if (restored.top() <= availableGeometry.top()) {
7497 restoredGeometry->moveTop(availableGeometry.top() + 1 + frameHeight);
7498 } else if (restored.bottom() >= availableGeometry.bottom()) {
7499 // Bottom out of bounds => move up
7500 restoredGeometry->moveBottom(availableGeometry.bottom() - 1);
7501 }
7502
7503 // Left edge out of bounds => move right
7504 if (restored.left() <= availableGeometry.left()) {
7505 restoredGeometry->moveLeft(availableGeometry.left() + 1);
7506 } else if (restored.right() >= availableGeometry.right()) {
7507 // Right edge out of bounds => move left
7508 restoredGeometry->moveRight(availableGeometry.right() - 1);
7509 }
7510}
7511
7536{
7537 if (geometry.size() < 4)
7538 return false;
7540 stream.setVersion(QDataStream::Qt_4_0);
7541
7542 const quint32 magicNumber = 0x1D9D0CB;
7543 quint32 storedMagicNumber;
7544 stream >> storedMagicNumber;
7545 if (storedMagicNumber != magicNumber)
7546 return false;
7547
7548 const quint16 currentMajorVersion = 3;
7549 quint16 majorVersion = 0;
7550 quint16 minorVersion = 0;
7551
7552 stream >> majorVersion >> minorVersion;
7553
7554 if (majorVersion > currentMajorVersion)
7555 return false;
7556 // (Allow all minor versions.)
7557
7558 QRect restoredFrameGeometry;
7559 QRect restoredGeometry;
7560 QRect restoredNormalGeometry;
7561 qint32 restoredScreenNumber;
7564 qint32 restoredScreenWidth = 0;
7565
7566 stream >> restoredFrameGeometry // Only used for sanity checks in version 0
7567 >> restoredNormalGeometry
7568 >> restoredScreenNumber
7569 >> maximized
7570 >> fullScreen;
7571
7572 if (majorVersion > 1)
7573 stream >> restoredScreenWidth;
7574 if (majorVersion > 2)
7575 stream >> restoredGeometry;
7576
7577 // ### Qt 6 - Perhaps it makes sense to dumb down the restoreGeometry() logic, see QTBUG-69104
7578
7579 if (restoredScreenNumber >= qMax(QGuiApplication::screens().size(), 1))
7580 restoredScreenNumber = 0;
7581 const QScreen *restoredScreen = QGuiApplication::screens().value(restoredScreenNumber, nullptr);
7582 const qreal screenWidthF = restoredScreen ? qreal(restoredScreen->geometry().width()) : 0;
7583 // Sanity check bailing out when large variations of screen sizes occur due to
7584 // high DPI scaling or different levels of DPI awareness.
7585 if (restoredScreenWidth) {
7586 const qreal factor = qreal(restoredScreenWidth) / screenWidthF;
7587 if (factor < 0.8 || factor > 1.25)
7588 return false;
7589 } else {
7590 // Saved by Qt 5.3 and earlier, try to prevent too large windows
7591 // unless the size will be adapted by maximized or fullscreen.
7592 if (!maximized && !fullScreen && qreal(restoredFrameGeometry.width()) / screenWidthF > 1.5)
7593 return false;
7594 }
7595
7596 const int frameHeight = QApplication::style()
7598 : 20;
7599
7600 if (!restoredNormalGeometry.isValid())
7601 restoredNormalGeometry = QRect(QPoint(0, frameHeight), sizeHint());
7602 if (!restoredNormalGeometry.isValid()) {
7603 // use the widget's adjustedSize if the sizeHint() doesn't help
7604 restoredNormalGeometry.setSize(restoredNormalGeometry
7605 .size()
7606 .expandedTo(d_func()->adjustedSize()));
7607 }
7608
7609 const QRect availableGeometry = restoredScreen ? restoredScreen->availableGeometry()
7610 : QRect();
7611
7612 // Modify the restored geometry if we are about to restore to coordinates
7613 // that would make the window "lost". This happens if:
7614 // - The restored geometry is completely or partly oustside the available geometry
7615 // - The title bar is outside the available geometry.
7616
7617 QWidgetPrivate::checkRestoredGeometry(availableGeometry, &restoredGeometry, frameHeight);
7618 QWidgetPrivate::checkRestoredGeometry(availableGeometry, &restoredNormalGeometry, frameHeight);
7619
7620 if (maximized || fullScreen) {
7621 // set geometry before setting the window state to make
7622 // sure the window is maximized to the right screen.
7623 Qt::WindowStates ws = windowState();
7624#ifndef Q_OS_WIN
7625 setGeometry(restoredNormalGeometry);
7626#else
7627 if (ws & Qt::WindowFullScreen) {
7628 // Full screen is not a real window state on Windows.
7629 move(availableGeometry.topLeft());
7630 } else if (ws & Qt::WindowMaximized) {
7631 // Setting a geometry on an already maximized window causes this to be
7632 // restored into a broken, half-maximized state, non-resizable state (QTBUG-4397).
7633 // Move the window in normal state if needed.
7634 if (restoredScreen != screen()) {
7636 setGeometry(restoredNormalGeometry);
7637 }
7638 } else {
7639 setGeometry(restoredNormalGeometry);
7640 }
7641#endif // Q_OS_WIN
7642 if (maximized)
7643 ws |= Qt::WindowMaximized;
7644 if (fullScreen)
7646 setWindowState(ws);
7647 d_func()->topData()->normalGeometry = restoredNormalGeometry;
7648 } else {
7650
7651 // FIXME: Why fall back to restoredNormalGeometry if majorVersion <= 2?
7652 if (majorVersion > 2)
7653 setGeometry(restoredGeometry);
7654 else
7655 setGeometry(restoredNormalGeometry);
7656 }
7657 return true;
7658}
7659
7677{
7678 Q_D(QWidget);
7679 if (left == d->leftmargin && top == d->topmargin
7680 && right == d->rightmargin && bottom == d->bottommargin)
7681 return;
7682 d->leftmargin = left;
7683 d->topmargin = top;
7684 d->rightmargin = right;
7685 d->bottommargin = bottom;
7686
7687 d->updateContentsRect();
7688}
7689
7707{
7708 setContentsMargins(margins.left(), margins.top(),
7709 margins.right(), margins.bottom());
7710}
7711
7713{
7714 Q_Q(QWidget);
7715
7716 if (layout)
7717 layout->update(); //force activate; will do updateGeometry
7718 else
7719 q->updateGeometry();
7720
7721 if (q->isVisible()) {
7722 q->update();
7723 QResizeEvent e(q->data->crect.size(), q->data->crect.size());
7725 } else {
7726 q->setAttribute(Qt::WA_PendingResizeEvent, true);
7727 }
7728
7731}
7732
7741{
7742 Q_D(const QWidget);
7743 QMargins userMargins(d->leftmargin, d->topmargin, d->rightmargin, d->bottommargin);
7745 userMargins | d->safeAreaMargins() : userMargins;
7746}
7747
7754{
7755 return rect() - contentsMargins();
7756}
7757
7759{
7760 Q_Q(const QWidget);
7761 QWidget *nativeWidget = q->window();
7762 if (!nativeWidget->windowHandle())
7763 return QMargins();
7764
7765 QPlatformWindow *platformWindow = nativeWidget->windowHandle()->handle();
7766 if (!platformWindow)
7767 return QMargins();
7768
7769 QMargins safeAreaMargins = platformWindow->safeAreaMargins();
7770
7771 if (!q->isWindow()) {
7772 // In theory the native parent widget already has a contents rect reflecting
7773 // the safe area of that widget, but we can't be sure that the widget or child
7774 // widgets of that widget have respected the contents rect when setting their
7775 // geometry, so we need to manually compute the safe area.
7776
7777 // Unless the native widget doesn't have any margins, in which case there's
7778 // nothing for us to compute.
7779 if (safeAreaMargins.isNull())
7780 return QMargins();
7781
7782 // Or, if one of our ancestors are in a layout that does not have WA_LayoutOnEntireRect
7783 // set, then we know that the layout has already taken care of placing us inside the
7784 // safe area, by taking the contents rect of its parent widget into account.
7785 const QWidget *assumedSafeWidget = nullptr;
7786 for (const QWidget *w = q; w != nativeWidget; w = w->parentWidget()) {
7787 QWidget *parentWidget = w->parentWidget();
7788 if (parentWidget->testAttribute(Qt::WA_LayoutOnEntireRect))
7789 continue; // Layout not going to help us
7790
7791 QLayout *layout = parentWidget->layout();
7792 if (!layout)
7793 continue;
7794
7795 if (layout->geometry().isNull())
7796 continue; // Layout hasn't been activated yet
7797
7798 if (layout->indexOf(w) < 0)
7799 continue; // Widget is not in layout
7800
7801 assumedSafeWidget = w;
7802 break;
7803 }
7804
7805#if !defined(QT_DEBUG)
7806 if (assumedSafeWidget) {
7807 // We found a layout that we assume will take care of keeping us within the safe area
7808 // For debug builds we still map the safe area using the fallback logic, so that we
7809 // can detect any misbehaving layouts.
7810 return QMargins();
7811 }
7812#endif
7813
7814 // In all other cases we need to map the safe area of the native parent to the widget.
7815 // This depends on the widget being positioned and sized already, which means the initial
7816 // layout will be wrong, but the layout will then adjust itself.
7817 QPoint topLeftMargins = q->mapFrom(nativeWidget, QPoint(safeAreaMargins.left(), safeAreaMargins.top()));
7818 QRect widgetRect = q->isVisible() ? q->visibleRegion().boundingRect() : q->rect();
7819 QPoint bottomRightMargins = widgetRect.bottomRight() - q->mapFrom(nativeWidget,
7821
7822 // Margins should never be negative
7823 safeAreaMargins = QMargins(qMax(0, topLeftMargins.x()), qMax(0, topLeftMargins.y()),
7824 qMax(0, bottomRightMargins.x()), qMax(0, bottomRightMargins.y()));
7825
7826 if (!safeAreaMargins.isNull() && assumedSafeWidget) {
7827 QLayout *layout = assumedSafeWidget->parentWidget()->layout();
7828 qWarning() << layout << "is laying out" << assumedSafeWidget
7829 << "outside of the contents rect of" << layout->parentWidget();
7830 return QMargins(); // Return empty margin to visually highlight the error
7831 }
7832 }
7833
7834 return safeAreaMargins;
7835}
7836
7868{
7869 return (Qt::ContextMenuPolicy)data->context_menu_policy;
7870}
7871
7873{
7874 data->context_menu_policy = (uint) policy;
7875}
7876
7900{
7901 return (Qt::FocusPolicy)data->focus_policy;
7902}
7903
7905{
7906 data->focus_policy = (uint) policy;
7907 Q_D(QWidget);
7908 if (d->extra && d->extra->focus_proxy)
7909 d->extra->focus_proxy->setFocusPolicy(policy);
7910}
7911
7941{
7942 Q_D(QWidget);
7944 d->setUpdatesEnabled_helper(enable);
7945}
7946
7957{
7959 if (defaultState == Qt::WindowFullScreen)
7961 else if (defaultState == Qt::WindowMaximized)
7962 showMaximized();
7963 else
7964 setVisible(true); // Don't call showNormal() as not to clobber Qt::Window(Max/Min)imized
7965}
7966
7973{
7974 Q_Q(QWidget);
7975 // polish if necessary
7976
7977 if (!q->testAttribute(Qt::WA_WState_Created))
7979 q->ensurePolished();
7980
7981 if (!q->isWindow() && q->parentWidget()->d_func()->layout && !q->parentWidget()->data->in_show)
7982 q->parentWidget()->d_func()->layout->activate();
7983 // activate our layout before we and our children become visible
7984 if (layout)
7985 layout->activate();
7986
7987 show_helper();
7988}
7989
7990void QWidgetPrivate::sendPendingMoveAndResizeEvents(bool recursive, bool disableUpdates)
7991{
7992 Q_Q(QWidget);
7993
7994 disableUpdates = disableUpdates && q->updatesEnabled();
7995 if (disableUpdates)
7996 q->setAttribute(Qt::WA_UpdatesDisabled);
7997
7998 if (q->testAttribute(Qt::WA_PendingMoveEvent)) {
7999 QMoveEvent e(data.crect.topLeft(), data.crect.topLeft());
8001 q->setAttribute(Qt::WA_PendingMoveEvent, false);
8002 }
8003
8004 if (q->testAttribute(Qt::WA_PendingResizeEvent)) {
8005 QResizeEvent e(data.crect.size(), QSize());
8007 q->setAttribute(Qt::WA_PendingResizeEvent, false);
8008 }
8009
8010 if (disableUpdates)
8011 q->setAttribute(Qt::WA_UpdatesDisabled, false);
8012
8013 if (!recursive)
8014 return;
8015
8016 for (int i = 0; i < children.size(); ++i) {
8018 child->d_func()->sendPendingMoveAndResizeEvents(recursive, disableUpdates);
8019 }
8020}
8021
8023{
8024 sendPendingMoveAndResizeEvents(false, true);
8025
8026 for (int i = 0; i < children.size(); ++i) {
8028 if (!child || child->isHidden() || child->isWindow())
8029 continue;
8030
8031 child->ensurePolished();
8032
8033 // Activate child's layout
8034 QWidgetPrivate *childPrivate = child->d_func();
8035 if (childPrivate->layout)
8036 childPrivate->layout->activate();
8037
8038 // Pretend we're visible.
8039 const bool wasVisible = child->isVisible();
8040 if (!wasVisible)
8041 child->setAttribute(Qt::WA_WState_Visible);
8042
8043 // Do the same for all my children.
8044 childPrivate->activateChildLayoutsRecursively();
8045
8046 // We're not cheating anymore.
8047 if (!wasVisible)
8048 child->setAttribute(Qt::WA_WState_Visible, false);
8049 }
8050}
8051
8053{
8054 Q_Q(QWidget);
8055 data.in_show = true; // qws optimization
8056 // make sure we receive pending move and resize events
8058
8059 // become visible before showing all children
8060 q->setAttribute(Qt::WA_WState_Visible);
8061
8062 // finally show all children recursively
8063 showChildren(false);
8064
8065
8066
8067 const bool isWindow = q->isWindow();
8068#if QT_CONFIG(graphicsview)
8069 bool isEmbedded = isWindow && q->graphicsProxyWidget() != nullptr;
8070#else
8071 bool isEmbedded = false;
8072#endif
8073
8074 // popup handling: new popups and tools need to be raised, and
8075 // existing popups must be closed. Also propagate the current
8076 // windows's KeyboardFocusChange status.
8077 if (isWindow && !isEmbedded) {
8078 if ((q->windowType() == Qt::Tool) || (q->windowType() == Qt::Popup) || q->windowType() == Qt::ToolTip) {
8079 q->raise();
8080 if (q->parentWidget() && q->parentWidget()->window()->testAttribute(Qt::WA_KeyboardFocusChange))
8081 q->setAttribute(Qt::WA_KeyboardFocusChange);
8082 } else {
8085 break;
8086 }
8087 }
8088 }
8089
8090 // Automatic embedding of child windows of widgets already embedded into
8091 // QGraphicsProxyWidget when they are shown the first time.
8092#if QT_CONFIG(graphicsview)
8093 if (isWindow) {
8095 QGraphicsProxyWidget *ancestorProxy = nearestGraphicsProxyWidget(q->parentWidget());
8096 if (ancestorProxy) {
8097 isEmbedded = true;
8098 ancestorProxy->d_func()->embedSubWindow(q);
8099 }
8100 }
8101 }
8102#else
8104#endif
8105
8106 // send the show event before showing the window
8107 QShowEvent showEvent;
8108 QCoreApplication::sendEvent(q, &showEvent);
8109
8110 show_sys();
8111
8112 if (!isEmbedded && q->windowType() == Qt::Popup)
8113 qApp->d_func()->openPopup(q);
8114
8115#if QT_CONFIG(accessibility)
8116 if (q->windowType() != Qt::ToolTip) { // Tooltips are read aloud twice in MS narrator.
8117 QAccessibleEvent event(q, QAccessible::ObjectShow);
8118 QAccessible::updateAccessibility(&event);
8119 }
8120#endif
8121
8125 }
8126
8127 // Process events when showing a Qt::SplashScreen widget before the event loop
8128 // is spinnning; otherwise it might not show up on particular platforms.
8129 // This makes QSplashScreen behave the same on all platforms.
8130 if (!qApp->d_func()->in_exec && q->windowType() == Qt::SplashScreen)
8132
8133 data.in_show = false; // reset qws optimization
8134}
8135
8137{
8138 Q_Q(QWidget);
8139
8140 auto window = qobject_cast<QWidgetWindow *>(windowHandle());
8141
8142 if (q->testAttribute(Qt::WA_DontShowOnScreen)) {
8143 invalidateBackingStore(q->rect());
8144 q->setAttribute(Qt::WA_Mapped);
8145 // add our window the modal window list (native dialogs)
8146 if (window && q->isWindow()
8147#if QT_CONFIG(graphicsview)
8148 && (!extra || !extra->proxyWidget)
8149#endif
8150 && q->windowModality() != Qt::NonModal) {
8152 }
8153 return;
8154 }
8155
8156 if (renderToTexture && !q->isWindow())
8157 QCoreApplication::postEvent(q->parentWidget(), new QUpdateLaterEvent(q->geometry()));
8158 else
8160
8161 if ((!q->isWindow() && !q->testAttribute(Qt::WA_NativeWindow))
8162 || q->testAttribute(Qt::WA_OutsideWSRange)) {
8163 return;
8164 }
8165
8166 if (window) {
8167 if (q->isWindow())
8169 QRect geomRect = q->geometry();
8170 if (!q->isWindow()) {
8171 QPoint topLeftOfWindow = q->mapTo(q->nativeParentWidget(),QPoint());
8172 geomRect.moveTopLeft(topLeftOfWindow);
8173 }
8174 const QRect windowRect = window->geometry();
8175 if (windowRect != geomRect) {
8176 if (q->testAttribute(Qt::WA_Moved)
8178 window->setGeometry(geomRect);
8179 else
8180 window->resize(geomRect.size());
8181 }
8182
8183#ifndef QT_NO_CURSOR
8184 qt_qpa_set_cursor(q, false); // Needed in case cursor was set before show
8185#endif
8186 invalidateBackingStore(q->rect());
8187 window->setNativeWindowVisibility(true);
8188 // Was the window moved by the Window system or QPlatformWindow::initialGeometry() ?
8189 if (window->isTopLevel()) {
8190 const QPoint crectTopLeft = q->data->crect.topLeft();
8191 const QPoint windowTopLeft = window->geometry().topLeft();
8192 if (crectTopLeft == QPoint(0, 0) && windowTopLeft != crectTopLeft)
8193 q->data->crect.moveTopLeft(windowTopLeft);
8194 }
8195 }
8196}
8197
8210{
8211 setVisible(false);
8212}
8213
8217{
8218 Q_Q(QWidget);
8219
8220 bool isEmbedded = false;
8221#if QT_CONFIG(graphicsview)
8222 isEmbedded = q->isWindow() && !bypassGraphicsProxyWidget(q) && nearestGraphicsProxyWidget(q->parentWidget()) != nullptr;
8223#else
8225#endif
8226
8227 if (!isEmbedded && (q->windowType() == Qt::Popup))
8228 qApp->d_func()->closePopup(q);
8229
8230 q->setAttribute(Qt::WA_Mapped, false);
8231 hide_sys();
8232
8233 bool wasVisible = q->testAttribute(Qt::WA_WState_Visible);
8234
8235 if (wasVisible) {
8236 q->setAttribute(Qt::WA_WState_Visible, false);
8237
8238 }
8239
8240 QHideEvent hideEvent;
8241 QCoreApplication::sendEvent(q, &hideEvent);
8242 hideChildren(false);
8243
8244 // next bit tries to move the focus if the focus widget is now
8245 // hidden.
8246 if (wasVisible) {
8247 qApp->d_func()->sendSyntheticEnterLeave(q);
8249 while (fw && !fw->isWindow()) {
8250 if (fw == q) {
8251 q->focusNextPrevChild(true);
8252 break;
8253 }
8254 fw = fw->parentWidget();
8255 }
8256 }
8257
8258 if (QWidgetRepaintManager *repaintManager = maybeRepaintManager())
8259 repaintManager->removeDirtyWidget(q);
8260
8261#if QT_CONFIG(accessibility)
8262 if (wasVisible) {
8263 QAccessibleEvent event(q, QAccessible::ObjectHide);
8264 QAccessible::updateAccessibility(&event);
8265 }
8266#endif
8267}
8268
8270{
8271 Q_Q(QWidget);
8272
8273 auto window = qobject_cast<QWidgetWindow *>(windowHandle());
8274
8275 if (q->testAttribute(Qt::WA_DontShowOnScreen)) {
8276 q->setAttribute(Qt::WA_Mapped, false);
8277 // remove our window from the modal window list (native dialogs)
8278 if (window && q->isWindow()
8279#if QT_CONFIG(graphicsview)
8280 && (!extra || !extra->proxyWidget)
8281#endif
8282 && q->windowModality() != Qt::NonModal) {
8284 }
8285 // do not return here, if window non-zero, we must hide it
8286 }
8287
8289
8290 if (!q->isWindow()) {
8291 QWidget *p = q->parentWidget();
8292 if (p &&p->isVisible()) {
8293 if (renderToTexture)
8294 p->d_func()->invalidateBackingStore(q->geometry());
8295 else
8296 invalidateBackingStore(q->rect());
8297 }
8298 } else {
8299 invalidateBackingStore(q->rect());
8300 }
8301
8302 if (window)
8303 window->setNativeWindowVisibility(false);
8304}
8305
8329void QWidget::setVisible(bool visible)
8330{
8332 return;
8333
8334 // Remember that setVisible was called explicitly
8336
8337 Q_D(QWidget);
8338 d->setVisible(visible);
8339}
8340
8341// This method is called from QWidgetWindow in response to QWindow::setVisible,
8342// and should match the semantics of QWindow::setVisible. QWidget::setVisible on
8343// the other hand keeps track of WA_WState_ExplicitShowHide in addition.
8345{
8346 Q_Q(QWidget);
8347 if (visible) { // show
8348 // Designer uses a trick to make grabWidget work without showing
8349 if (!q->isWindow() && q->parentWidget() && q->parentWidget()->isVisible()
8350 && !q->parentWidget()->testAttribute(Qt::WA_WState_Created))
8351 q->parentWidget()->window()->d_func()->createRecursively();
8352
8353 //create toplevels but not children of non-visible parents
8354 QWidget *pw = q->parentWidget();
8355 if (!q->testAttribute(Qt::WA_WState_Created)
8356 && (q->isWindow() || pw->testAttribute(Qt::WA_WState_Created))) {
8357 q->create();
8358 }
8359
8360 bool wasResized = q->testAttribute(Qt::WA_Resized);
8361 Qt::WindowStates initialWindowState = q->windowState();
8362
8363 // polish if necessary
8364 q->ensurePolished();
8365
8366 // whether we need to inform the parent widget immediately
8367 bool needUpdateGeometry = !q->isWindow() && q->testAttribute(Qt::WA_WState_Hidden);
8368 // we are no longer hidden
8369 q->setAttribute(Qt::WA_WState_Hidden, false);
8370
8371 if (needUpdateGeometry)
8373
8374 // activate our layout before we and our children become visible
8375 if (layout)
8376 layout->activate();
8377
8378 if (!q->isWindow()) {
8379 QWidget *parent = q->parentWidget();
8380 while (parent && parent->isVisible() && parent->d_func()->layout && !parent->data->in_show) {
8381 parent->d_func()->layout->activate();
8382 if (parent->isWindow())
8383 break;
8384 parent = parent->parentWidget();
8385 }
8386 if (parent)
8387 parent->d_func()->setDirtyOpaqueRegion();
8388 }
8389
8390 // adjust size if necessary
8391 if (!wasResized
8392 && (q->isWindow() || !q->parentWidget()->d_func()->layout)) {
8393 if (q->isWindow()) {
8394 q->adjustSize();
8395 if (q->windowState() != initialWindowState)
8396 q->setWindowState(initialWindowState);
8397 } else {
8398 q->adjustSize();
8399 }
8400 q->setAttribute(Qt::WA_Resized, false);
8401 }
8402
8403 q->setAttribute(Qt::WA_KeyboardFocusChange, false);
8404
8405 if (q->isWindow() || q->parentWidget()->isVisible()) {
8406 show_helper();
8407
8408 qApp->d_func()->sendSyntheticEnterLeave(q);
8409 }
8410
8411 QEvent showToParentEvent(QEvent::ShowToParent);
8412 QCoreApplication::sendEvent(q, &showToParentEvent);
8413 } else { // hide
8416
8417 // hw: The test on getOpaqueRegion() needs to be more intelligent
8418 // currently it doesn't work if the widget is hidden (the region will
8419 // be clipped). The real check should be testing the cached region
8420 // (and dirty flag) directly.
8421 if (!q->isWindow() && q->parentWidget()) // && !d->getOpaqueRegion().isEmpty())
8422 q->parentWidget()->d_func()->setDirtyOpaqueRegion();
8423
8424 if (!q->testAttribute(Qt::WA_WState_Hidden)) {
8426 if (q->testAttribute(Qt::WA_WState_Created))
8427 hide_helper();
8428 }
8429
8430 // invalidate layout similar to updateGeometry()
8431 if (!q->isWindow() && q->parentWidget()) {
8432 if (q->parentWidget()->d_func()->layout)
8433 q->parentWidget()->d_func()->layout->invalidate();
8434 else if (q->parentWidget()->isVisible())
8436 }
8437
8438 QEvent hideToParentEvent(QEvent::HideToParent);
8439 QCoreApplication::sendEvent(q, &hideToParentEvent);
8440 }
8441}
8442
8446void QWidget::setHidden(bool hidden)
8447{
8448 setVisible(!hidden);
8449}
8450
8452{
8453 Q_Q(QWidget);
8454 if ( !(q->isHidden() && q->testAttribute(Qt::WA_WState_ExplicitShowHide)) )
8455 q->setVisible(true);
8456}
8457
8458void QWidgetPrivate::showChildren(bool spontaneous)
8459{
8460 QList<QObject*> childList = children;
8461 for (int i = 0; i < childList.size(); ++i) {
8462 QWidget *widget = qobject_cast<QWidget*>(childList.at(i));
8465 if (!widget
8466 || widget->isWindow()
8468 continue;
8469 if (spontaneous) {
8471 widget->d_func()->showChildren(true);
8472 QShowEvent e;
8473 QApplication::sendSpontaneousEvent(widget, &e);
8474 } else {
8476 widget->d_func()->show_recursive();
8477 else
8478 widget->show();
8479 }
8480 }
8481}
8482
8483void QWidgetPrivate::hideChildren(bool spontaneous)
8484{
8485 Q_Q(QWidget);
8486 QList<QObject*> childList = children;
8487 for (int i = 0; i < childList.size(); ++i) {
8488 QWidget *widget = qobject_cast<QWidget*>(childList.at(i));
8490 continue;
8491
8492 if (spontaneous)
8494 else
8496 widget->d_func()->hideChildren(spontaneous);
8497 QHideEvent e;
8498 if (spontaneous) {
8499 QApplication::sendSpontaneousEvent(widget, &e);
8500 } else {
8502 if (widget->internalWinId()
8504 // hide_sys() on an ancestor won't have any affect on this
8505 // widget, so it needs an explicit hide_sys() of its own
8506 widget->d_func()->hide_sys();
8507 }
8508 }
8509 qApp->d_func()->sendSyntheticEnterLeave(widget);
8510#if QT_CONFIG(accessibility)
8511 if (!spontaneous) {
8512 QAccessibleEvent event(widget, QAccessible::ObjectHide);
8513 QAccessible::updateAccessibility(&event);
8514 }
8515#endif
8516 }
8517
8518 // If the window of this widget is not closed, then the leave event
8519 // will eventually handle the widget under mouse use case.
8520 // Otherwise, we need to explicitly handle it here.
8521 if (QWidget* widgetWindow = q->window();
8522 widgetWindow && widgetWindow->data->is_closing) {
8523 q->setAttribute(Qt::WA_UnderMouse, false);
8524 }
8525}
8526
8546{
8547 if (data.is_closing)
8548 return true;
8549
8550 // We might not have initiated the close, so update the state now that we know
8551 data.is_closing = true;
8552
8553 Q_Q(QWidget);
8554 QPointer<QWidget> that = q;
8555
8556 if (data.in_destructor)
8558
8559 if (mode != CloseNoEvent) {
8560 QCloseEvent e;
8562 QApplication::sendSpontaneousEvent(q, &e);
8563 else
8565 if (!that.isNull() && !e.isAccepted()) {
8566 data.is_closing = false;
8567 return false;
8568 }
8569 }
8570
8571 // even for windows, make sure we deliver a hide event and that all children get hidden
8572 if (!that.isNull() && !q->isHidden())
8573 q->hide();
8574
8575 if (!that.isNull()) {
8576 data.is_closing = false;
8577 if (q->testAttribute(Qt::WA_DeleteOnClose)) {
8578 q->setAttribute(Qt::WA_DeleteOnClose, false);
8579 q->deleteLater();
8580 }
8581 }
8582 return true;
8583}
8584
8585
8609{
8610 return d_func()->close();
8611}
8612
8614{
8615 // FIXME: We're not setting is_closing here, even though that would
8616 // make sense, as the code below will not end up in handleClose to
8617 // reset is_closing when there's a QWindow, but no QPlatformWindow,
8618 // and we can't assume close is synchronous so we can't reset it here.
8619
8620 // Close native widgets via QWindow::close() in order to run QWindow
8621 // close code. The QWidget-specific close code in handleClose() will
8622 // in this case be called from the Close event handler in QWidgetWindow.
8623 if (QWindow *widgetWindow = windowHandle()) {
8624 if (widgetWindow->isTopLevel())
8625 return widgetWindow->close();
8626 }
8627
8629}
8630
8689bool QWidget::isVisibleTo(const QWidget *ancestor) const
8690{
8691 if (!ancestor)
8692 return isVisible();
8693 const QWidget * w = this;
8694 while (!w->isHidden()
8695 && !w->isWindow()
8696 && w->parentWidget()
8697 && w->parentWidget() != ancestor)
8698 w = w->parentWidget();
8699 return !w->isHidden();
8700}
8701
8702
8714{
8715 Q_D(const QWidget);
8716
8717 QRect clipRect = d->clipRect();
8718 if (clipRect.isEmpty())
8719 return QRegion();
8720 QRegion r(clipRect);
8721 d->subtractOpaqueChildren(r, clipRect);
8722 d->subtractOpaqueSiblings(r);
8723 return r;
8724}
8725
8726
8728{
8729 Q_Q(const QWidget);
8730
8731 QSize s = q->sizeHint();
8732
8733 if (q->isWindow()) {
8734 Qt::Orientations exp;
8735 if (layout) {
8738 exp = layout->expandingDirections();
8739 } else
8740 {
8741 if (q->sizePolicy().hasHeightForWidth())
8742 s.setHeight(q->heightForWidth(s.width()));
8743 exp = q->sizePolicy().expandingDirections();
8744 }
8745 if (exp & Qt::Horizontal)
8746 s.setWidth(qMax(s.width(), 200));
8747 if (exp & Qt::Vertical)
8748 s.setHeight(qMax(s.height(), 100));
8749
8750 QRect screen;
8751 if (const QScreen *screenAtPoint = QGuiApplication::screenAt(q->pos()))
8752 screen = screenAtPoint->geometry();
8753 else
8755
8756 s.setWidth(qMin(s.width(), screen.width()*2/3));
8757 s.setHeight(qMin(s.height(), screen.height()*2/3));
8758
8759 if (QTLWExtra *extra = maybeTopData())
8760 extra->sizeAdjusted = true;
8761 }
8762
8763 if (!s.isValid()) {
8764 QRect r = q->childrenRect(); // get children rectangle
8765 if (r.isNull())
8766 return s;
8767 s = r.size() + QSize(2 * r.x(), 2 * r.y());
8768 }
8769
8770 return s;
8771}
8772
8790{
8791 Q_D(QWidget);
8793 QSize s = d->adjustedSize();
8794
8795 if (d->layout)
8796 d->layout->activate();
8797
8798 if (s.isValid())
8799 resize(s);
8800}
8801
8802
8819{
8820 Q_D(const QWidget);
8821 if (d->layout)
8822 return d->layout->totalSizeHint();
8823 return QSize(-1, -1);
8824}
8825
8846{
8847 Q_D(const QWidget);
8848 if (d->layout)
8849 return d->layout->totalMinimumSize();
8850 return QSize(-1, -1);
8851}
8852
8853
8869{
8870 while (child) {
8871 if (child == this)
8872 return true;
8873 if (child->isWindow())
8874 return false;
8875 child = child->parentWidget();
8876 }
8877 return false;
8878}
8879
8880/*****************************************************************************
8881 QWidget event handling
8882 *****************************************************************************/
8883
8913{
8914 Q_D(QWidget);
8915
8916 // ignore mouse and key events when disabled
8917 if (!isEnabled()) {
8918 switch(event->type()) {
8921 case QEvent::TabletMove:
8925 case QEvent::MouseMove:
8926 case QEvent::TouchBegin:
8928 case QEvent::TouchEnd:
8931 case QEvent::KeyPress:
8932 case QEvent::KeyRelease:
8933#if QT_CONFIG(wheelevent)
8934 case QEvent::Wheel:
8935#endif
8936 return false;
8937 default:
8938 break;
8939 }
8940 }
8941 switch (event->type()) {
8943 // Sync up QWidget's view of whether or not the widget has been created
8944 switch (static_cast<QPlatformSurfaceEvent*>(event)->surfaceEventType()) {
8947 create();
8948 break;
8951 // Child windows have already been destroyed by QWindow,
8952 // so we skip them here.
8953 destroy(false, false);
8954 }
8955 break;
8956 }
8957 break;
8958 }
8959 case QEvent::MouseMove:
8961 break;
8962
8965 break;
8966
8969 break;
8970
8973 break;
8974#if QT_CONFIG(wheelevent)
8975 case QEvent::Wheel:
8976 wheelEvent((QWheelEvent*)event);
8977 break;
8978#endif
8979#if QT_CONFIG(tabletevent)
8980 case QEvent::TabletMove:
8981 if (static_cast<QTabletEvent *>(event)->buttons() == Qt::NoButton && !testAttribute(Qt::WA_TabletTracking))
8982 break;
8983 Q_FALLTHROUGH();
8986 tabletEvent((QTabletEvent*)event);
8987 break;
8988#endif
8989 case QEvent::KeyPress: {
8990 QKeyEvent *k = static_cast<QKeyEvent *>(event);
8991 bool res = false;
8992 if (!(k->modifiers() & (Qt::ControlModifier | Qt::AltModifier))) { //### Add MetaModifier?
8993 if (k->key() == Qt::Key_Backtab
8994 || (k->key() == Qt::Key_Tab && (k->modifiers() & Qt::ShiftModifier)))
8995 res = focusNextPrevChild(false);
8996 else if (k->key() == Qt::Key_Tab)
8997 res = focusNextPrevChild(true);
8998 if (res)
8999 break;
9000 }
9001 keyPressEvent(k);
9002#ifdef QT_KEYPAD_NAVIGATION
9003 if (!k->isAccepted() && QApplication::keypadNavigationEnabled()
9005 if (QApplication::navigationMode() == Qt::NavigationModeKeypadTabOrder) {
9006 if (k->key() == Qt::Key_Up)
9007 res = focusNextPrevChild(false);
9008 else if (k->key() == Qt::Key_Down)
9009 res = focusNextPrevChild(true);
9010 } else if (QApplication::navigationMode() == Qt::NavigationModeKeypadDirectional) {
9011 if (k->key() == Qt::Key_Up)
9012 res = QWidgetPrivate::navigateToDirection(QWidgetPrivate::DirectionNorth);
9013 else if (k->key() == Qt::Key_Right)
9014 res = QWidgetPrivate::navigateToDirection(QWidgetPrivate::DirectionEast);
9015 else if (k->key() == Qt::Key_Down)
9016 res = QWidgetPrivate::navigateToDirection(QWidgetPrivate::DirectionSouth);
9017 else if (k->key() == Qt::Key_Left)
9018 res = QWidgetPrivate::navigateToDirection(QWidgetPrivate::DirectionWest);
9019 }
9020 if (res) {
9021 k->accept();
9022 break;
9023 }
9024 }
9025#endif
9026#if QT_CONFIG(whatsthis)
9027 if (!k->isAccepted()
9028 && k->modifiers() & Qt::ShiftModifier && k->key() == Qt::Key_F1
9029 && d->whatsThis.size()) {
9030 QWhatsThis::showText(mapToGlobal(inputMethodQuery(Qt::ImCursorRectangle).toRect().center()), d->whatsThis, this);
9031 k->accept();
9032 }
9033#endif
9034 }
9035 break;
9036
9037 case QEvent::KeyRelease:
9039 Q_FALLTHROUGH();
9041 break;
9042
9045 break;
9046
9049 Qt::InputMethodQueries queries = query->queries();
9050 for (uint i = 0; i < 32; ++i) {
9051 Qt::InputMethodQuery q = (Qt::InputMethodQuery)(int)(queries & (1<<i));
9052 if (q) {
9054 if (q == Qt::ImEnabled && !v.isValid() && isEnabled()) {
9055 // Qt:ImEnabled was added in Qt 5.3. So not all widgets support it, even
9056 // if they implement IM otherwise (by overriding inputMethodQuery()). Instead
9057 // they set the widget attribute Qt::WA_InputMethodEnabled. But this attribute
9058 // will only be set if the widget supports IM _and_ is not read-only. So for
9059 // read-only widgets, not all IM features will be supported when ImEnabled is
9060 // not implemented explicitly (e.g selection handles for read-only widgets on iOS).
9062 }
9063 query->setValue(q, v);
9064 }
9065 }
9066 query->accept();
9067 }
9068 break;
9069
9072 break;
9073
9074 case QEvent::Polish: {
9075 style()->polish(this);
9077 if (!QApplication::font(this).isCopyOf(QApplication::font()))
9078 d->resolveFont();
9079 if (!QApplication::palette(this).isCopyOf(QGuiApplication::palette()))
9080 d->resolvePalette();
9081 }
9082 break;
9083
9086 d->setWindowIcon_sys();
9087 d->setWindowIcon_helper();
9088 }
9089 break;
9090 case QEvent::FocusIn:
9092 d->updateWidgetTransform(event);
9093 break;
9094
9095 case QEvent::FocusOut:
9097 break;
9098
9099 case QEvent::Enter:
9100#if QT_CONFIG(statustip)
9101 if (d->statusTip.size()) {
9102 QStatusTipEvent tip(d->statusTip);
9103 QCoreApplication::sendEvent(const_cast<QWidget *>(this), &tip);
9104 }
9105#endif
9106 enterEvent(static_cast<QEnterEvent*>(event));
9107 break;
9108
9109 case QEvent::Leave:
9110#if QT_CONFIG(statustip)
9111 if (d->statusTip.size()) {
9112 QString empty;
9113 QStatusTipEvent tip(empty);
9114 QCoreApplication::sendEvent(const_cast<QWidget *>(this), &tip);
9115 }
9116#endif
9118 break;
9119
9120 case QEvent::HoverEnter:
9121 case QEvent::HoverLeave:
9122 update();
9123 break;
9124
9125 case QEvent::Paint:
9126 // At this point the event has to be delivered, regardless
9127 // whether the widget isVisible() or not because it
9128 // already went through the filters
9130 break;
9131
9132 case QEvent::Move:
9134 d->updateWidgetTransform(event);
9135 break;
9136
9137 case QEvent::Resize:
9139 d->updateWidgetTransform(event);
9140 break;
9141
9142 case QEvent::Close:
9144 break;
9145
9146#ifndef QT_NO_CONTEXTMENU
9148 switch (data->context_menu_policy) {
9150 break;
9152 contextMenuEvent(static_cast<QContextMenuEvent *>(event));
9153 break;
9156 break;
9157#if QT_CONFIG(menu)
9159 if (d->actions.size()) {
9160 QMenu::exec(d->actions, static_cast<QContextMenuEvent *>(event)->globalPos(),
9161 nullptr, this);
9162 break;
9163 }
9164 Q_FALLTHROUGH();
9165#endif
9166 default:
9167 event->ignore();
9168 break;
9169 }
9170 break;
9171#endif // QT_NO_CONTEXTMENU
9172
9173#if QT_CONFIG(draganddrop)
9174 case QEvent::Drop:
9175 dropEvent((QDropEvent*) event);
9176 break;
9177
9178 case QEvent::DragEnter:
9179 dragEnterEvent((QDragEnterEvent*) event);
9180 break;
9181
9182 case QEvent::DragMove:
9183 dragMoveEvent((QDragMoveEvent*) event);
9184 break;
9185
9186 case QEvent::DragLeave:
9187 dragLeaveEvent((QDragLeaveEvent*) event);
9188 break;
9189#endif
9190
9191 case QEvent::Show:
9193 break;
9194
9195 case QEvent::Hide:
9197 break;
9198
9200 if (!isHidden())
9201 d->show_sys();
9202 break;
9203
9205 d->resolveFont();
9206 break;
9208 if (!(windowType() == Qt::Desktop))
9209 d->resolvePalette();
9210 break;
9211
9215 case QEvent::FontChange:
9230 break;
9231
9233 const bool wasMinimized = static_cast<const QWindowStateChangeEvent *>(event)->oldState() & Qt::WindowMinimized;
9234 if (wasMinimized != isMinimized()) {
9235 QWidget *widget = const_cast<QWidget *>(this);
9236 if (wasMinimized) {
9237 // Always send the spontaneous events here, otherwise it can break the application!
9238 if (!d->childrenShownByExpose) {
9239 // Show widgets only when they are not yet shown by the expose event
9240 d->showChildren(true);
9242 QCoreApplication::sendSpontaneousEvent(widget, &showEvent);
9243 }
9244 d->childrenHiddenByWState = false; // Set it always to "false" when window is restored
9245 } else {
9247 QCoreApplication::sendSpontaneousEvent(widget, &hideEvent);
9248 d->hideChildren(true);
9249 d->childrenHiddenByWState = true;
9250 }
9251 d->childrenShownByExpose = false; // Set it always to "false" when window state changes
9252 }
9254 }
9255 break;
9256
9260 update();
9261 QList<QObject*> childList = d->children;
9262 for (int i = 0; i < childList.size(); ++i) {
9263 QWidget *w = qobject_cast<QWidget *>(childList.at(i));
9264 if (w && w->isVisible() && !w->isWindow())
9266 }
9267 break; }
9268
9271 {
9272 QList<QObject*> childList = d->children;
9273 for (int i = 0; i < childList.size(); ++i) {
9274 QObject *o = childList.at(i);
9275 if (o)
9277 }
9278 }
9279 update();
9280 break;
9281
9283 d->resolveLayoutDirection();
9284 break;
9285
9287 if (d->layout)
9288 d->layout->invalidate();
9289 update();
9291 break;
9293 d->syncBackingStore();
9294 break;
9296 update(static_cast<QUpdateLaterEvent*>(event)->region());
9297 break;
9299 if (isVisible() && !window()->isMinimized()) {
9300 event->accept();
9301 update();
9302 }
9303 break;
9304
9307 if (!d->children.isEmpty()) {
9309 for (int i = 0; i < d->children.size(); ++i) {
9310 QObject *o = d->children.at(i);
9311 if (o && o != modalWidget && o->isWidgetType()) {
9312 QWidget *w = static_cast<QWidget *>(o);
9313 // do not forward the event to child windows; QApplication does this for us
9314 if (!w->isWindow())
9316 }
9317 }
9318 }
9319 break;
9320#if QT_CONFIG(tooltip)
9321 case QEvent::ToolTip:
9322 if (!d->toolTip.isEmpty())
9323 QToolTip::showText(static_cast<QHelpEvent*>(event)->globalPos(), d->toolTip, this, QRect(), d->toolTipDuration);
9324 else
9325 event->ignore();
9326 break;
9327#endif
9328#if QT_CONFIG(whatsthis)
9329 case QEvent::WhatsThis:
9330 if (d->whatsThis.size())
9331 QWhatsThis::showText(static_cast<QHelpEvent *>(event)->globalPos(), d->whatsThis, this);
9332 else
9333 event->ignore();
9334 break;
9336 if (d->whatsThis.isEmpty())
9337 event->ignore();
9338 break;
9339#endif
9341 d->topData()->frameStrut.setCoords(0 ,0, 0, 0);
9342 data->fstrut_dirty = false;
9343 break;
9344#ifndef QT_NO_ACTION
9349 break;
9350#endif
9351
9353 {
9355
9356 // inform children of the change
9357 QList<QObject*> childList = d->children;
9358 for (int i = 0; i < childList.size(); ++i) {
9359 QWidget *w = qobject_cast<QWidget *>(childList.at(i));
9360 if (w && w->isVisible() && !w->isWindow())
9362 }
9363 break;
9364 }
9365 case QEvent::TouchBegin:
9367 case QEvent::TouchEnd:
9369 {
9370 event->ignore();
9371 break;
9372 }
9373#ifndef QT_NO_GESTURES
9374 case QEvent::Gesture:
9375 event->ignore();
9376 break;
9377#endif
9379 if (const QTLWExtra *te = d->maybeTopData()) {
9380 const QWindow *win = te->window;
9381 d->setWinId((win && win->handle()) ? win->handle()->winId() : 0);
9382 }
9383 break;
9385 if (d->data.fnt.d->dpi != logicalDpiY())
9386 d->updateFont(d->data.fnt);
9387 d->renderToTextureReallyDirty = 1;
9388 break;
9390 const QByteArray &propName = static_cast<QDynamicPropertyChangeEvent *>(event)->propertyName();
9391 if (propName.size() == 13 && !qstrncmp(propName, "_q_customDpi", 12)) {
9392 uint value = property(propName.constData()).toUInt();
9393 if (!d->extra)
9394 d->createExtra();
9395 const char axis = propName.at(12);
9396 if (axis == 'X')
9397 d->extra->customDpiX = value;
9398 else if (axis == 'Y')
9399 d->extra->customDpiY = value;
9400 d->updateFont(d->data.fnt);
9401 }
9402 if (windowHandle() && !qstrncmp(propName, "_q_platform_", 12))
9403 windowHandle()->setProperty(propName, property(propName));
9404 Q_FALLTHROUGH();
9405 }
9406 default:
9407 return QObject::event(event);
9408 }
9409 return true;
9410}
9411
9429{
9430 switch(event->type()) {
9431 case QEvent::EnabledChange: {
9432 update();
9433#if QT_CONFIG(accessibility)
9435 s.disabled = true;
9436 QAccessibleStateChangeEvent event(this, s);
9437 QAccessible::updateAccessibility(&event);
9438#endif
9439 break;
9440 }
9441
9442 case QEvent::FontChange:
9443 case QEvent::StyleChange: {
9444 Q_D(QWidget);
9445 update();
9447 if (d->layout)
9448 d->layout->invalidate();
9449 break;
9450 }
9451
9453 update();
9454 break;
9455
9462 QApplication::style()->polish(this);
9463 QEvent styleChangedEvent(QEvent::StyleChange);
9464 QCoreApplication::sendEvent(this, &styleChangedEvent);
9465 if (isVisible())
9466 update();
9467 }
9468 break;
9469
9470#ifdef Q_OS_MAC
9473 break;
9474#endif
9475
9476 default:
9477 break;
9478 }
9479}
9480
9508{
9509 event->ignore();
9510}
9511
9530{
9531 event->ignore();
9532 if ((windowType() == Qt::Popup)) {
9533 event->accept();
9534 QWidget* w;
9535 while ((w = QApplication::activePopupWidget()) && w != this){
9536 w->close();
9537 if (QApplication::activePopupWidget() == w) // widget does not want to disappear
9538 w->hide(); // hide at least
9539 }
9540 if (!rect().contains(event->position().toPoint())){
9541 close();
9542 }
9543 }
9544}
9545
9555{
9556 event->ignore();
9557}
9558
9577{
9579}
9580
9581#if QT_CONFIG(wheelevent)
9596void QWidget::wheelEvent(QWheelEvent *event)
9597{
9598 event->ignore();
9599}
9600#endif // QT_CONFIG(wheelevent)
9601
9602#if QT_CONFIG(tabletevent)
9623void QWidget::tabletEvent(QTabletEvent *event)
9624{
9625 event->ignore();
9626}
9627#endif // QT_CONFIG(tabletevent)
9628
9653{
9654#ifndef QT_NO_SHORTCUT
9655 if ((windowType() == Qt::Popup) && event->matches(QKeySequence::Cancel)) {
9656 event->accept();
9657 close();
9658 } else
9659#endif
9660 {
9661 event->ignore();
9662 }
9663}
9664
9688{
9689 event->ignore();
9690}
9691
9712{
9713 if (focusPolicy() != Qt::NoFocus || !isWindow()) {
9714 update();
9715 }
9716}
9717
9738{
9739 if (focusPolicy() != Qt::NoFocus || !isWindow())
9740 update();
9741
9742#if !defined(QT_PLATFORM_UIKIT)
9743 // FIXME: revisit autoSIP logic, QTBUG-42906
9744 if (qApp->autoSipEnabled() && testAttribute(Qt::WA_InputMethodEnabled))
9746#endif
9747}
9748
9762{
9763}
9764
9778{
9779}
9780
9830{
9831}
9832
9833
9848{
9849}
9850
9851
9869{
9870}
9871
9872#ifndef QT_NO_ACTION
9882{
9883
9884}
9885#endif
9886
9903{
9904 event->accept();
9905}
9906
9907#ifndef QT_NO_CONTEXTMENU
9922{
9923 event->ignore();
9924}
9925#endif // QT_NO_CONTEXTMENU
9926
9927
9945{
9946 event->ignore();
9947}
9948
9960{
9961 switch(query) {
9963 return QRect(width()/2, 0, 1, height());
9964 case Qt::ImFont:
9965 return font();
9967 // Fallback.
9969 case Qt::ImHints:
9970 return (int)inputMethodHints();
9972 return d_func()->clipRect();
9973 default:
9974 return QVariant();
9975 }
9976}
9977
10003Qt::InputMethodHints QWidget::inputMethodHints() const
10004{
10005#if QT_CONFIG(im)
10006 const QWidgetPrivate *priv = d_func();
10007 while (priv->inheritsInputMethodHints) {
10008 priv = priv->q_func()->parentWidget()->d_func();
10009 Q_ASSERT(priv);
10010 }
10011 return priv->imHints;
10012#else
10013 return Qt::ImhNone;
10014#endif
10015}
10016
10017void QWidget::setInputMethodHints(Qt::InputMethodHints hints)
10018{
10019#ifndef QT_NO_IM
10020 Q_D(QWidget);
10021 if (d->imHints == hints)
10022 return;
10023 d->imHints = hints;
10024 if (this == QGuiApplication::focusObject())
10026#else
10027 Q_UNUSED(hints);
10028#endif //QT_NO_IM
10029}
10030
10031
10032#if QT_CONFIG(draganddrop)
10033
10048void QWidget::dragEnterEvent(QDragEnterEvent *)
10049{
10050}
10051
10066void QWidget::dragMoveEvent(QDragMoveEvent *)
10067{
10068}
10069
10082void QWidget::dragLeaveEvent(QDragLeaveEvent *)
10083{
10084}
10085
10097void QWidget::dropEvent(QDropEvent *)
10098{
10099}
10100
10101#endif // QT_CONFIG(draganddrop)
10102
10123{
10124}
10125
10145{
10146}
10147
10176{
10177 Q_UNUSED(eventType);
10180 return false;
10181}
10182
10207{
10208 Q_D(const QWidget);
10209
10210 const QMetaObject *m = metaObject();
10211 if (m == d->polished)
10212 return;
10213 d->polished = m;
10214
10216 QCoreApplication::sendEvent(const_cast<QWidget *>(this), &e);
10217
10218 // polish children after 'this'
10219 QList<QObject*> children = d->children;
10220 for (int i = 0; i < children.size(); ++i) {
10221 QObject *o = children.at(i);
10222 if (!o->isWidgetType())
10223 continue;
10225 w->ensurePolished();
10226 }
10227
10228 if (d->parent && d->sendChildEvents) {
10229 QChildEvent e(QEvent::ChildPolished, const_cast<QWidget *>(this));
10230 QCoreApplication::sendEvent(d->parent, &e);
10231 }
10232}
10233
10241{
10242 Q_D(const QWidget);
10243 return d->extra ? d->extra->mask : QRegion();
10244}
10245
10256{
10257 return d_func()->layout;
10258}
10259
10260
10287{
10288 if (Q_UNLIKELY(!l)) {
10289 qWarning("QWidget::setLayout: Cannot set layout to 0");
10290 return;
10291 }
10292 if (layout()) {
10293 if (Q_UNLIKELY(layout() != l))
10294 qWarning("QWidget::setLayout: Attempting to set QLayout \"%s\" on %s \"%s\", which already has a"
10295 " layout", l->objectName().toLocal8Bit().data(), metaObject()->className(),
10297 return;
10298 }
10299
10300 QObject *oldParent = l->parent();
10301 if (oldParent && oldParent != this) {
10302 if (oldParent->isWidgetType()) {
10303 // Steal the layout off a widget parent. Takes effect when
10304 // morphing laid-out container widgets in Designer.
10305 QWidget *oldParentWidget = static_cast<QWidget *>(oldParent);
10306 oldParentWidget->takeLayout();
10307 } else {
10308 qWarning("QWidget::setLayout: Attempting to set QLayout \"%s\" on %s \"%s\", when the QLayout already has a parent",
10311 return;
10312 }
10313 }
10314
10315 Q_D(QWidget);
10316 l->d_func()->topLevel = true;
10317 d->layout = l;
10318 if (oldParent != this) {
10319 l->setParent(this);
10320 l->d_func()->reparentChildWidgets(this);
10321 l->invalidate();
10322 }
10323
10324 if (isWindow() && d->maybeTopData())
10325 d->topData()->sizeAdjusted = false;
10326}
10327
10335QLayout *QWidget::takeLayout()
10336{
10337 Q_D(QWidget);
10338 QLayout *l = layout();
10339 if (!l)
10340 return nullptr;
10341 d->layout = nullptr;
10342 l->setParent(nullptr);
10343 return l;
10344}
10345
10372{
10373 Q_D(const QWidget);
10374 return d->size_policy;
10375}
10376
10378{
10379 Q_D(QWidget);
10381 if (policy == d->size_policy)
10382 return;
10383
10384 if (d->size_policy.retainSizeWhenHidden() != policy.retainSizeWhenHidden())
10385 d->retainSizeWhenHiddenChanged = 1;
10386
10387 d->size_policy = policy;
10388
10389#if QT_CONFIG(graphicsview)
10390 if (const auto &extra = d->extra) {
10391 if (extra->proxyWidget)
10392 extra->proxyWidget->setSizePolicy(policy);
10393 }
10394#endif
10395
10397 d->retainSizeWhenHiddenChanged = 0;
10398
10399 if (isWindow() && d->maybeTopData())
10400 d->topData()->sizeAdjusted = false;
10401}
10402
10423{
10424 if (layout() && layout()->hasHeightForWidth())
10425 return layout()->totalHeightForWidth(w);
10426 return -1;
10427}
10428
10429
10436{
10437 Q_D(const QWidget);
10438 return d->layout ? d->layout->hasHeightForWidth() : d->size_policy.hasHeightForWidth();
10439}
10440
10457{
10458 return d_func()->childAt_helper(p, false);
10459}
10460
10461QWidget *QWidgetPrivate::childAt_helper(const QPoint &p, bool ignoreChildrenInDestructor) const
10462{
10463 if (children.isEmpty())
10464 return nullptr;
10465
10467 return nullptr;
10468 return childAtRecursiveHelper(p, ignoreChildrenInDestructor);
10469}
10470
10471QWidget *QWidgetPrivate::childAtRecursiveHelper(const QPoint &p, bool ignoreChildrenInDestructor) const
10472{
10473 for (int i = children.size() - 1; i >= 0; --i) {
10475 if (!child || child->isWindow() || child->isHidden() || child->testAttribute(Qt::WA_TransparentForMouseEvents)
10476 || (ignoreChildrenInDestructor && child->data->in_destructor)) {
10477 continue;
10478 }
10479
10480 // Map the point 'p' from parent coordinates to child coordinates.
10481 QPoint childPoint = p;
10482 childPoint -= child->data->crect.topLeft();
10483
10484 // Check if the point hits the child.
10485 if (!child->d_func()->pointInsideRectAndMask(childPoint))
10486 continue;
10487
10488 // Do the same for the child's descendants.
10489 if (QWidget *w = child->d_func()->childAtRecursiveHelper(childPoint, ignoreChildrenInDestructor))
10490 return w;
10491
10492 // We have found our target; namely the child at position 'p'.
10493 return child;
10494 }
10495 return nullptr;
10496}
10497
10499{
10500 Q_Q(QWidget);
10501 if (widgetItem)
10502 widgetItem->invalidateSizeCache();
10503 QWidget *parent;
10504 if (forceUpdate || !extra || extra->minw != extra->maxw || extra->minh != extra->maxh) {
10505 const int isHidden = q->isHidden() && !size_policy.retainSizeWhenHidden() && !retainSizeWhenHiddenChanged;
10506
10507 if (!q->isWindow() && !isHidden && (parent = q->parentWidget())) {
10508 if (parent->d_func()->layout)
10509 parent->d_func()->layout->invalidate();
10510 else if (parent->isVisible())
10512 }
10513 }
10514}
10515
10527{
10528 Q_D(QWidget);
10529 d->updateGeometry_helper(false);
10530}
10531
10550void QWidget::setWindowFlags(Qt::WindowFlags flags)
10551{
10552 Q_D(QWidget);
10553 d->setWindowFlags(flags);
10554}
10555
10565{
10566 Q_D(QWidget);
10567 if (on)
10568 d->setWindowFlags(data->window_flags | flag);
10569 else
10570 d->setWindowFlags(data->window_flags & ~flag);
10571}
10572
10578{
10579 Q_Q(QWidget);
10580 if (q->data->window_flags == flags)
10581 return;
10582
10583 if ((q->data->window_flags | flags) & Qt::Window) {
10584 // the old type was a window and/or the new type is a window
10585 QPoint oldPos = q->pos();
10586 bool visible = q->isVisible();
10587 const bool windowFlagChanged = (q->data->window_flags ^ flags) & Qt::Window;
10588 q->setParent(q->parentWidget(), flags);
10589
10590 // if both types are windows or neither of them are, we restore
10591 // the old position
10592 if (!windowFlagChanged && (visible || q->testAttribute(Qt::WA_Moved)))
10593 q->move(oldPos);
10594 // for backward-compatibility we change Qt::WA_QuitOnClose attribute value only when the window was recreated.
10596 } else {
10597 q->data->window_flags = flags;
10598 }
10599}
10600
10611{
10612 data->window_flags = flags;
10613}
10614
10653{
10654 if (parent == parentWidget())
10655 return;
10657}
10658
10660{
10662 if (d->renderToTexture) {
10663 QEvent e(eventType);
10665 }
10666
10667 for (int i = 0; i < d->children.size(); ++i) {
10668 QWidget *w = qobject_cast<QWidget *>(d->children.at(i));
10669 if (w && !w->isWindow() && QWidgetPrivate::get(w)->textureChildSeen)
10671 }
10672}
10673
10680void QWidget::setParent(QWidget *parent, Qt::WindowFlags f)
10681{
10682 Q_D(QWidget);
10683 Q_ASSERT_X(this != parent, Q_FUNC_INFO, "Cannot parent a QWidget to itself");
10684#ifdef QT_DEBUG
10685 const auto checkForParentChildLoops = qScopeGuard([&](){
10686 int depth = 0;
10687 auto p = parentWidget();
10688 while (p) {
10689 if (++depth == QObjectPrivate::CheckForParentChildLoopsWarnDepth) {
10690 qWarning("QWidget %p (class: '%s', object name: '%s') may have a loop in its parent-child chain; "
10691 "this is undefined behavior",
10692 this, metaObject()->className(), qPrintable(objectName()));
10693 }
10694 p = p->parentWidget();
10695 }
10696 });
10697#endif
10698
10699 const bool resized = testAttribute(Qt::WA_Resized);
10700 const bool wasCreated = testAttribute(Qt::WA_WState_Created);
10701 QWidget *oldtlw = window();
10702
10703 if (f & Qt::Window) // Frame geometry likely changes, refresh.
10704 d->data.fstrut_dirty = true;
10705
10706 QWidget *desktopWidget = nullptr;
10707 if (parent && parent->windowType() == Qt::Desktop)
10708 desktopWidget = parent;
10709 bool newParent = (parent != parentWidget()) || desktopWidget;
10710
10711 if (newParent && parent && !desktopWidget) {
10713 parent->d_func()->enforceNativeChildren();
10714 else if (parent->d_func()->nativeChildrenForced() || parent->testAttribute(Qt::WA_PaintOnScreen))
10716 }
10717
10718 if (wasCreated) {
10720 hide();
10722 }
10723 if (newParent) {
10726 }
10727 }
10728
10729 // texture-based widgets need a pre-notification when their associated top-level window changes
10730 // This is not under the wasCreated/newParent conditions above in order to also play nice with QDockWidget.
10731 if (d->textureChildSeen && ((!parent && parentWidget()) || (parent && parent->window() != oldtlw)))
10733
10734 // If we get parented into another window, children will be folded
10735 // into the new parent's focus chain, so clear focus now.
10736 if (newParent && isAncestorOf(focusWidget()) && !(f & Qt::Window))
10738
10739 d->setParent_sys(parent, f);
10740
10741 if (desktopWidget)
10742 parent = nullptr;
10743
10744 if (d->textureChildSeen && parent) {
10745 // set the textureChildSeen flag up the whole parent chain
10747 }
10748
10749 if (QWidgetRepaintManager *oldPaintManager = oldtlw->d_func()->maybeRepaintManager()) {
10750 if (newParent)
10751 oldPaintManager->removeDirtyWidget(this);
10752 // Move the widget and all its static children from
10753 // the old backing store to the new one.
10754 oldPaintManager->moveStaticWidgets(this);
10755 }
10756
10757 d->reparentFocusWidgets(oldtlw);
10758 setAttribute(Qt::WA_Resized, resized);
10759
10760 const bool useStyleSheetPropagationInWidgetStyles =
10762
10763 if (!useStyleSheetPropagationInWidgetStyles && !testAttribute(Qt::WA_StyleSheet)
10764 && (!parent || !parent->testAttribute(Qt::WA_StyleSheet))) {
10765 // if the parent has a font set or inherited, then propagate the mask to the new child
10766 if (parent) {
10767 const auto pd = parent->d_func();
10768 d->inheritedFontResolveMask = pd->directFontResolveMask | pd->inheritedFontResolveMask;
10769 d->inheritedPaletteResolveMask = pd->directPaletteResolveMask | pd->inheritedPaletteResolveMask;
10770 }
10771 d->resolveFont();
10772 d->resolvePalette();
10773 }
10774 d->resolveLayoutDirection();
10775 d->resolveLocale();
10776
10777 // Note: GL widgets under WGL or EGL will always need a ParentChange
10778 // event to handle recreation/rebinding of the GL context, hence the
10779 // (f & Qt::MSWindowsOwnDC) clause (which is set on QGLWidgets on all
10780 // platforms).
10781 if (newParent || !wasCreated
10782#if QT_CONFIG(opengles2)
10783 || (f & Qt::MSWindowsOwnDC)
10784#endif
10785 ) {
10786 // propagate enabled updates enabled state to non-windows
10787 if (!isWindow()) {
10789 d->setEnabled_helper(parent ? parent->isEnabled() : true);
10791 d->setUpdatesEnabled_helper(parent ? parent->updatesEnabled() : true);
10792 }
10793 d->inheritStyle();
10794
10795 // send and post remaining QObject events
10796 if (parent && d->sendChildEvents) {
10799 }
10800
10801 if (parent && d->sendChildEvents && d->polished) {
10804 }
10805
10808 }
10809
10810 // texture-based widgets need another event when their top-level window
10811 // changes (more precisely, has already changed at this point)
10812 if (d->textureChildSeen && oldtlw != window())
10814
10815 if (!wasCreated) {
10816 if (isWindow() || parentWidget()->isVisible())
10820 }
10821
10822 d->updateIsOpaque();
10823
10824#if QT_CONFIG(graphicsview)
10825 // Embed the widget into a proxy if the parent is embedded.
10826 // ### Doesn't handle reparenting out of an embedded widget.
10827 if (oldtlw->graphicsProxyWidget()) {
10828 if (QGraphicsProxyWidget *ancestorProxy = d->nearestGraphicsProxyWidget(oldtlw))
10829 ancestorProxy->d_func()->unembedSubWindow(this);
10830 }
10831 if (isWindow() && parent && !graphicsProxyWidget() && !bypassGraphicsProxyWidget(this)) {
10832 if (QGraphicsProxyWidget *ancestorProxy = d->nearestGraphicsProxyWidget(parent))
10833 ancestorProxy->d_func()->embedSubWindow(this);
10834 }
10835#endif
10836
10837 if (d->extra && d->extra->hasWindowContainer)
10839
10840 QWidget *newtlw = window();
10841 if (oldtlw != newtlw) {
10843 // Only evaluate the reparented subtree. While it might be tempting to
10844 // do it on newtlw instead, the performance implications of that are
10845 // problematic when it comes to large widget trees.
10846 if (q_evaluateRhiConfig(this, nullptr, &surfaceType)) {
10847 newtlw->d_func()->usesRhiFlush = true;
10848 if (QWindow *w = newtlw->windowHandle()) {
10849 if (w->surfaceType() != surfaceType) {
10850 newtlw->destroy();
10851 newtlw->create();
10852 }
10853 }
10854 }
10855 }
10856}
10857
10858void QWidgetPrivate::setParent_sys(QWidget *newparent, Qt::WindowFlags f)
10859{
10860 Q_Q(QWidget);
10861
10862 Qt::WindowFlags oldFlags = data.window_flags;
10863 bool wasCreated = q->testAttribute(Qt::WA_WState_Created);
10864
10865 QScreen *targetScreen = nullptr;
10866 // Handle a request to move the widget to a particular screen
10867 if (newparent && newparent->windowType() == Qt::Desktop) {
10868 // make sure the widget is created on the same screen as the
10869 // programmer specified desktop widget
10870 targetScreen = newparent->screen();
10871 newparent = nullptr;
10872 }
10873
10874 setWinId(0);
10875
10876 if (parent != newparent) {
10877 QObjectPrivate::setParent_helper(newparent); //### why does this have to be done in the _sys function???
10878 if (q->windowHandle()) {
10879 q->windowHandle()->setFlags(f);
10880 QWidget *parentWithWindow =
10881 newparent ? (newparent->windowHandle() ? newparent : newparent->nativeParentWidget()) : nullptr;
10882 if (parentWithWindow) {
10883 QWidget *topLevel = parentWithWindow->window();
10884 if ((f & Qt::Window) && topLevel && topLevel->windowHandle()) {
10885 q->windowHandle()->setTransientParent(topLevel->windowHandle());
10886 q->windowHandle()->setParent(nullptr);
10887 } else {
10888 q->windowHandle()->setTransientParent(nullptr);
10889 q->windowHandle()->setParent(parentWithWindow->windowHandle());
10890 }
10891 } else {
10892 q->windowHandle()->setTransientParent(nullptr);
10893 q->windowHandle()->setParent(nullptr);
10894 }
10895 }
10896 }
10897
10898 if (!newparent) {
10899 f |= Qt::Window;
10900 if (parent)
10901 targetScreen = q->parentWidget()->window()->screen();
10902 }
10903
10904 bool explicitlyHidden = q->testAttribute(Qt::WA_WState_Hidden) && q->testAttribute(Qt::WA_WState_ExplicitShowHide);
10905
10906 // Reparenting toplevel to child
10907 if (wasCreated && !(f & Qt::Window) && (oldFlags & Qt::Window) && !q->testAttribute(Qt::WA_NativeWindow)) {
10908 if (extra && extra->hasWindowContainer)
10910
10911 QWindow *newParentWindow = newparent->windowHandle();
10912 if (!newParentWindow)
10913 if (QWidget *npw = newparent->nativeParentWidget())
10914 newParentWindow = npw->windowHandle();
10915
10916 for (QObject *child : q->windowHandle()->children()) {
10917 QWindow *childWindow = qobject_cast<QWindow *>(child);
10918 if (!childWindow)
10919 continue;
10920
10921 QWidgetWindow *childWW = qobject_cast<QWidgetWindow *>(childWindow);
10922 QWidget *childWidget = childWW ? childWW->widget() : nullptr;
10923 if (!childWW || (childWidget && childWidget->testAttribute(Qt::WA_NativeWindow)))
10924 childWindow->setParent(newParentWindow);
10925 }
10926 q->destroy();
10927 }
10928
10929 adjustFlags(f, q);
10930 data.window_flags = f;
10931 q->setAttribute(Qt::WA_WState_Created, false);
10932 q->setAttribute(Qt::WA_WState_Visible, false);
10933 q->setAttribute(Qt::WA_WState_Hidden, false);
10934
10935 if (newparent && wasCreated && (q->testAttribute(Qt::WA_NativeWindow) || (f & Qt::Window)))
10936 q->createWinId();
10937
10938 if (q->isWindow() || (!newparent || newparent->isVisible()) || explicitlyHidden)
10939 q->setAttribute(Qt::WA_WState_Hidden);
10940 q->setAttribute(Qt::WA_WState_ExplicitShowHide, explicitlyHidden);
10941
10942 // move the window to the selected screen
10943 if (!newparent && targetScreen) {
10944 // only if it is already created
10945 if (q->testAttribute(Qt::WA_WState_Created))
10946 q->windowHandle()->setScreen(targetScreen);
10947 else
10948 topData()->initialScreen = targetScreen;
10949 }
10950}
10951
10973void QWidget::scroll(int dx, int dy)
10974{
10975 if ((!updatesEnabled() && children().size() == 0) || !isVisible())
10976 return;
10977 if (dx == 0 && dy == 0)
10978 return;
10979 Q_D(QWidget);
10980#if QT_CONFIG(graphicsview)
10981 if (QGraphicsProxyWidget *proxy = QWidgetPrivate::nearestGraphicsProxyWidget(this)) {
10982 // Graphics View maintains its own dirty region as a list of rects;
10983 // until we can connect item updates directly to the view, we must
10984 // separately add a translated dirty region.
10985 for (const QRect &rect : d->dirty)
10986 proxy->update(rect.translated(dx, dy));
10987 proxy->scroll(dx, dy, proxy->subWidgetRect(this));
10988 return;
10989 }
10990#endif
10991 d->setDirtyOpaqueRegion();
10992 d->scroll_sys(dx, dy);
10993}
10994
10995void QWidgetPrivate::scroll_sys(int dx, int dy)
10996{
10997 Q_Q(QWidget);
10998 scrollChildren(dx, dy);
10999 scrollRect(q->rect(), dx, dy);
11000}
11001
11012void QWidget::scroll(int dx, int dy, const QRect &r)
11013{
11014
11015 if ((!updatesEnabled() && children().size() == 0) || !isVisible())
11016 return;
11017 if (dx == 0 && dy == 0)
11018 return;
11019 Q_D(QWidget);
11020#if QT_CONFIG(graphicsview)
11021 if (QGraphicsProxyWidget *proxy = QWidgetPrivate::nearestGraphicsProxyWidget(this)) {
11022 // Graphics View maintains its own dirty region as a list of rects;
11023 // until we can connect item updates directly to the view, we must
11024 // separately add a translated dirty region.
11025 if (!d->dirty.isEmpty()) {
11026 for (const QRect &rect : d->dirty.translated(dx, dy) & r)
11027 proxy->update(rect);
11028 }
11029 proxy->scroll(dx, dy, r.translated(proxy->subWidgetRect(this).topLeft().toPoint()));
11030 return;
11031 }
11032#endif
11033 d->scroll_sys(dx, dy, r);
11034}
11035
11036void QWidgetPrivate::scroll_sys(int dx, int dy, const QRect &r)
11037{
11038 scrollRect(r, dx, dy);
11039}
11040
11058{
11059 repaint(rect());
11060}
11061
11070void QWidget::repaint(int x, int y, int w, int h)
11071{
11072 if (x > data->crect.width() || y > data->crect.height())
11073 return;
11074
11075 if (w < 0)
11076 w = data->crect.width() - x;
11077 if (h < 0)
11078 h = data->crect.height() - y;
11079
11080 repaint(QRect(x, y, w, h));
11081}
11082
11088{
11089 Q_D(QWidget);
11090 d->repaint(rect);
11091}
11092
11099{
11100 Q_D(QWidget);
11101 d->repaint(rgn);
11102}
11103
11104template <typename T>
11106{
11107 Q_Q(QWidget);
11108
11109 if (!q->isVisible() || !q->updatesEnabled() || r.isEmpty())
11110 return;
11111
11112 QTLWExtra *tlwExtra = q->window()->d_func()->maybeTopData();
11113 if (tlwExtra && tlwExtra->backingStore && tlwExtra->repaintManager)
11114 tlwExtra->repaintManager->markDirty(r, q, QWidgetRepaintManager::UpdateNow);
11115}
11116
11136{
11137 update(rect());
11138}
11139
11153{
11154 Q_D(QWidget);
11155 d->update(rect);
11156}
11157
11163void QWidget::update(const QRegion &rgn)
11164{
11165 Q_D(QWidget);
11166 d->update(rgn);
11167}
11168
11169template <typename T>
11171{
11172 Q_Q(QWidget);
11173
11174 if (renderToTexture && !q->isVisible()) {
11176 return;
11177 }
11178
11179 if (!q->isVisible() || !q->updatesEnabled())
11180 return;
11181
11182 T clipped = r & q->rect();
11183
11184 if (clipped.isEmpty())
11185 return;
11186
11187 if (q->testAttribute(Qt::WA_WState_InPaintEvent)) {
11189 return;
11190 }
11191
11192 QTLWExtra *tlwExtra = q->window()->d_func()->maybeTopData();
11193 if (tlwExtra && tlwExtra->backingStore && tlwExtra->repaintManager)
11194 tlwExtra->repaintManager->markDirty(clipped, q);
11195}
11196
11204{
11205 if (attribute < int(8*sizeof(uint))) {
11206 if (on)
11207 data->widget_attributes |= (1<<attribute);
11208 else
11209 data->widget_attributes &= ~(1<<attribute);
11210 } else {
11211 const int x = attribute - 8*sizeof(uint);
11212 const int int_off = x / (8*sizeof(uint));
11213 if (on)
11214 d->high_attributes[int_off] |= (1<<(x-(int_off*8*sizeof(uint))));
11215 else
11216 d->high_attributes[int_off] &= ~(1<<(x-(int_off*8*sizeof(uint))));
11217 }
11218}
11219
11220#ifdef Q_OS_MAC
11221void QWidgetPrivate::macUpdateSizeAttribute()
11222{
11223 Q_Q(QWidget);
11226 for (int i = 0; i < children.size(); ++i) {
11228 if (w && (!w->isWindow() || w->testAttribute(Qt::WA_WindowPropagation))
11229 && !w->testAttribute(Qt::WA_MacMiniSize) // no attribute set? inherit from parent
11230 && !w->testAttribute(Qt::WA_MacSmallSize)
11231 && !w->testAttribute(Qt::WA_MacNormalSize))
11232 w->d_func()->macUpdateSizeAttribute();
11233 }
11234 resolveFont();
11235}
11236#endif
11237
11245{
11246 if (testAttribute(attribute) == on)
11247 return;
11248
11249 Q_D(QWidget);
11250 static_assert(sizeof(d->high_attributes)*8 >= (Qt::WA_AttributeCount - sizeof(uint)*8),
11251 "QWidget::setAttribute(WidgetAttribute, bool): "
11252 "QWidgetPrivate::high_attributes[] too small to contain all attributes in WidgetAttribute");
11253#ifdef Q_OS_WIN
11254 // ### Don't use PaintOnScreen+paintEngine() to do native painting in some future release
11255 if (attribute == Qt::WA_PaintOnScreen && on && windowType() != Qt::Desktop && !inherits("QGLWidget")) {
11256 // see ::paintEngine for details
11257 paintEngine();
11258 if (d->noPaintOnScreen)
11259 return;
11260 }
11261#endif
11262
11263 // Don't set WA_NativeWindow on platforms that don't support it -- except for QGLWidget, which depends on it
11264 if (attribute == Qt::WA_NativeWindow && !d->mustHaveWindowHandle) {
11266 if (!platformIntegration->hasCapability(QPlatformIntegration::NativeWidgets))
11267 return;
11268 }
11269
11271
11272 switch (attribute) {
11273
11274#if QT_CONFIG(draganddrop)
11275 case Qt::WA_AcceptDrops: {
11282 break;
11283 }
11285 for (int i = 0; i < d->children.size(); ++i) {
11286 QWidget *w = qobject_cast<QWidget *>(d->children.at(i));
11287 if (w && !w->isWindow() && !w->testAttribute(Qt::WA_AcceptDrops) && w->testAttribute(Qt::WA_DropSiteRegistered) != on)
11288 w->setAttribute(Qt::WA_DropSiteRegistered, on);
11289 }
11290 break;
11291 }
11292#endif
11293
11295 d->sendChildEvents = !on;
11296 break;
11298 d->receiveChildEvents = !on;
11299 break;
11302 case Qt::WA_MacMiniSize:
11303#ifdef Q_OS_MAC
11304 {
11305 // We can only have one of these set at a time
11308 for (int i = 0; i < 3; ++i) {
11309 if (MacSizes[i] != attribute)
11310 setAttribute_internal(MacSizes[i], false, data, d);
11311 }
11312 d->macUpdateSizeAttribute();
11313 }
11314#endif
11315 break;
11316 case Qt::WA_ShowModal:
11317 if (!on) {
11318 // reset modality type to NonModal when clearing WA_ShowModal
11319 data->window_modality = Qt::NonModal;
11320 } else if (data->window_modality == Qt::NonModal) {
11321 // If modality hasn't been set prior to setting WA_ShowModal, use
11322 // ApplicationModal.
11323 data->window_modality = Qt::ApplicationModal;
11324 // Some window managers do not allow us to enter modality after the
11325 // window is visible.The window must be hidden before changing the
11326 // windowModality property and then reshown.
11327 }
11329 // don't call setModal_sys() before create()
11330 d->setModal_sys();
11331 }
11332 break;
11333 case Qt::WA_MouseTracking: {
11336 break; }
11337 case Qt::WA_TabletTracking: {
11340 break; }
11341 case Qt::WA_NativeWindow: {
11342 d->createTLExtra();
11343 if (on)
11344 d->createTLSysExtra();
11345#ifndef QT_NO_IM
11346 QWidget *focusWidget = d->effectiveFocusWidget();
11347 if (on && !internalWinId() && this == QGuiApplication::focusObject()
11351 }
11353 parentWidget()->d_func()->enforceNativeChildren();
11355 d->createWinId();
11359 }
11360#endif //QT_NO_IM
11361 break;
11362 }
11364 d->updateIsOpaque();
11365 Q_FALLTHROUGH();
11367 d->updateIsOpaque();
11368 break;
11370 d->updateIsOpaque();
11371 Q_FALLTHROUGH();
11373 d->updateSystemBackground();
11374 break;
11376 break;
11378#ifndef QT_NO_IM
11379 if (QGuiApplication::focusObject() == this) {
11380 if (!on)
11383 }
11384#endif //QT_NO_IM
11385 break;
11386 }
11388 d->resolvePalette();
11389 d->resolveFont();
11390 d->resolveLocale();
11391 break;
11393 if (on && isVisible()) {
11394 // Make sure we keep the current state and only hide the widget
11395 // from the desktop. show_sys will only update platform specific
11396 // attributes at this point.
11397 d->hide_sys();
11398 d->show_sys();
11399 }
11400 break;
11401 }
11402
11416 d->setNetWmWindowTypes();
11417 break;
11418
11420 if (QWidgetRepaintManager *repaintManager = d->maybeRepaintManager()) {
11421 if (on)
11422 repaintManager->addStaticWidget(this);
11423 else
11424 repaintManager->removeStaticWidget(this);
11425 }
11426 break;
11428 if (on)
11430 d->updateIsTranslucent();
11431
11432 break;
11434 break;
11435 default:
11436 break;
11437 }
11438}
11439
11447bool QWidget::testAttribute_helper(Qt::WidgetAttribute attribute) const
11448{
11449 Q_D(const QWidget);
11450 const int x = attribute - 8*sizeof(uint);
11451 const int int_off = x / (8*sizeof(uint));
11452 return (d->high_attributes[int_off] & (1<<(x-(int_off*8*sizeof(uint)))));
11453}
11454
11481{
11482 Q_D(const QWidget);
11483 return (isWindow() && d->maybeTopData()) ? d->maybeTopData()->opacity / 255. : 1.0;
11484}
11485
11487{
11488 Q_D(QWidget);
11489 if (!isWindow())
11490 return;
11491
11492 opacity = qBound(qreal(0.0), opacity, qreal(1.0));
11493 QTLWExtra *extra = d->topData();
11494 extra->opacity = uint(opacity * 255);
11496 d->setWindowOpacity_sys(opacity);
11497
11499 return;
11500
11501#if QT_CONFIG(graphicsview)
11502 if (QGraphicsProxyWidget *proxy = graphicsProxyWidget()) {
11503 // Avoid invalidating the cache if set.
11504 if (proxy->cacheMode() == QGraphicsItem::NoCache)
11505 proxy->update();
11506 else if (QGraphicsScene *scene = proxy->scene())
11507 scene->update(proxy->sceneBoundingRect());
11508 return;
11509 }
11510#endif
11511}
11512
11514{
11515 Q_Q(QWidget);
11516 if (q->windowHandle())
11517 q->windowHandle()->setOpacity(level);
11518}
11519
11545{
11547}
11548
11550{
11551 Q_D(QWidget);
11553
11554 d->setWindowModified_helper();
11555
11558}
11559
11561{
11562 Q_Q(QWidget);
11563 QWindow *window = q->windowHandle();
11564 if (!window)
11565 return;
11566 QPlatformWindow *platformWindow = window->handle();
11567 if (!platformWindow)
11568 return;
11569 bool on = q->testAttribute(Qt::WA_WindowModified);
11570 if (!platformWindow->setWindowModified(on)) {
11571 if (Q_UNLIKELY(on && !q->windowTitle().contains("[*]"_L1)))
11572 qWarning("QWidget::setWindowModified: The window title does not contain a '[*]' placeholder");
11573 setWindowTitle_helper(q->windowTitle());
11574 setWindowIconText_helper(q->windowIconText());
11575 }
11576}
11577
11578#if QT_CONFIG(tooltip)
11597void QWidget::setToolTip(const QString &s)
11598{
11599 Q_D(QWidget);
11600 d->toolTip = s;
11601
11604}
11605
11606QString QWidget::toolTip() const
11607{
11608 Q_D(const QWidget);
11609 return d->toolTip;
11610}
11611
11623void QWidget::setToolTipDuration(int msec)
11624{
11625 Q_D(QWidget);
11626 d->toolTipDuration = msec;
11627}
11628
11629int QWidget::toolTipDuration() const
11630{
11631 Q_D(const QWidget);
11632 return d->toolTipDuration;
11633}
11634
11635#endif // QT_CONFIG(tooltip)
11636
11637
11638#if QT_CONFIG(statustip)
11647void QWidget::setStatusTip(const QString &s)
11648{
11649 Q_D(QWidget);
11650 d->statusTip = s;
11651}
11652
11653QString QWidget::statusTip() const
11654{
11655 Q_D(const QWidget);
11656 return d->statusTip;
11657}
11658#endif // QT_CONFIG(statustip)
11659
11660#if QT_CONFIG(whatsthis)
11670void QWidget::setWhatsThis(const QString &s)
11671{
11672 Q_D(QWidget);
11673 d->whatsThis = s;
11674}
11675
11676QString QWidget::whatsThis() const
11677{
11678 Q_D(const QWidget);
11679 return d->whatsThis;
11680}
11681#endif // QT_CONFIG(whatsthis)
11682
11683#if QT_CONFIG(accessibility)
11705void QWidget::setAccessibleName(const QString &name)
11706{
11707 Q_D(QWidget);
11708 d->accessibleName = name;
11709 QAccessibleEvent event(this, QAccessible::NameChanged);
11710 QAccessible::updateAccessibility(&event);
11711}
11712
11713QString QWidget::accessibleName() const
11714{
11715 Q_D(const QWidget);
11716 return d->accessibleName;
11717}
11718
11735void QWidget::setAccessibleDescription(const QString &description)
11736{
11737 Q_D(QWidget);
11738 d->accessibleDescription = description;
11739 QAccessibleEvent event(this, QAccessible::DescriptionChanged);
11740 QAccessible::updateAccessibility(&event);
11741}
11742
11743QString QWidget::accessibleDescription() const
11744{
11745 Q_D(const QWidget);
11746 return d->accessibleDescription;
11747}
11748#endif // QT_CONFIG(accessibility)
11749
11750#ifndef QT_NO_SHORTCUT
11775{
11776 Q_ASSERT(qApp);
11777 if (key.isEmpty())
11778 return 0;
11780 return QGuiApplicationPrivate::instance()->shortcutMap.addShortcut(this, key, context, qWidgetShortcutContextMatcher);
11781}
11782
11799{
11800 Q_ASSERT(qApp);
11801 if (id)
11802 QGuiApplicationPrivate::instance()->shortcutMap.removeShortcut(id, this, 0);
11803}
11804
11818{
11819 Q_ASSERT(qApp);
11820 if (id)
11821 QGuiApplicationPrivate::instance()->shortcutMap.setShortcutEnabled(enable, id, this, 0);
11822}
11823
11833{
11834 Q_ASSERT(qApp);
11835 if (id)
11836 QGuiApplicationPrivate::instance()->shortcutMap.setShortcutAutoRepeat(enable, id, this, 0);
11837}
11838#endif // QT_NO_SHORTCUT
11839
11845{
11846 if (this == QGuiApplication::focusObject())
11848}
11849
11863{
11864 Q_D(QWidget);
11865 if (!isWindow()) {
11866 QWidget *p = parentWidget();
11867 const int parentChildCount = p->d_func()->children.size();
11868 if (parentChildCount < 2)
11869 return;
11870 const int from = p->d_func()->children.indexOf(this);
11871 Q_ASSERT(from >= 0);
11872 // Do nothing if the widget is already in correct stacking order _and_ created.
11873 if (from != parentChildCount -1)
11874 p->d_func()->children.move(from, parentChildCount - 1);
11876 create();
11877 else if (from == parentChildCount - 1)
11878 return;
11879
11880 QRegion region(rect());
11881 d->subtractOpaqueSiblings(region);
11882 d->invalidateBackingStore(region);
11883 }
11885 d->raise_sys();
11886
11887 if (d->extra && d->extra->hasWindowContainer)
11889
11892}
11893
11895{
11896 Q_Q(QWidget);
11897 if (q->isWindow() || q->testAttribute(Qt::WA_NativeWindow)) {
11898 q->windowHandle()->raise();
11899 } else if (renderToTexture) {
11900 if (QWidget *p = q->parentWidget()) {
11902 p->d_func()->invalidateBackingStore(effectiveRectFor(q->geometry()));
11903 }
11904 }
11905}
11906
11917{
11918 Q_D(QWidget);
11919 if (!isWindow()) {
11920 QWidget *p = parentWidget();
11921 const int parentChildCount = p->d_func()->children.size();
11922 if (parentChildCount < 2)
11923 return;
11924 const int from = p->d_func()->children.indexOf(this);
11925 Q_ASSERT(from >= 0);
11926 // Do nothing if the widget is already in correct stacking order _and_ created.
11927 if (from != 0)
11928 p->d_func()->children.move(from, 0);
11930 create();
11931 else if (from == 0)
11932 return;
11933 }
11935 d->lower_sys();
11936
11937 if (d->extra && d->extra->hasWindowContainer)
11939
11942}
11943
11945{
11946 Q_Q(QWidget);
11947 if (q->isWindow() || q->testAttribute(Qt::WA_NativeWindow)) {
11948 Q_ASSERT(q->testAttribute(Qt::WA_WState_Created));
11949 q->windowHandle()->lower();
11950 } else if (QWidget *p = q->parentWidget()) {
11952 p->d_func()->invalidateBackingStore(effectiveRectFor(q->geometry()));
11953 }
11954}
11955
11964{
11965 Q_D(QWidget);
11966 QWidget *p = parentWidget();
11967 if (!w || isWindow() || p != w->parentWidget() || this == w)
11968 return;
11969 if (p) {
11970 int from = p->d_func()->children.indexOf(this);
11971 int to = p->d_func()->children.indexOf(w);
11972 Q_ASSERT(from >= 0);
11973 Q_ASSERT(to >= 0);
11974 if (from < to)
11975 --to;
11976 // Do nothing if the widget is already in correct stacking order _and_ created.
11977 if (from != to)
11978 p->d_func()->children.move(from, to);
11980 create();
11981 else if (from == to)
11982 return;
11983 }
11985 d->stackUnder_sys(w);
11986
11989}
11990
11992{
11993 Q_Q(QWidget);
11994 if (QWidget *p = q->parentWidget()) {
11996 p->d_func()->invalidateBackingStore(effectiveRectFor(q->geometry()));
11997 }
11998}
11999
12041{
12042 Q_Q(const QWidget);
12043 if (!q->isWindow() || (q->windowType() == Qt::Desktop) || q->testAttribute(Qt::WA_DontShowOnScreen)) {
12044 // x2 = x1 + w - 1, so w/h = 1
12045 return QRect(0, 0, 1, 1);
12046 }
12047
12048 if (data.fstrut_dirty
12049 // ### Fix properly for 4.3
12050 && q->isVisible()
12051 && q->testAttribute(Qt::WA_WState_Created))
12052 const_cast<QWidgetPrivate *>(this)->updateFrameStrut();
12053
12054 return maybeTopData() ? maybeTopData()->frameStrut : QRect();
12055}
12056
12058{
12059 Q_Q(QWidget);
12060 if (q->data->fstrut_dirty) {
12061 if (QTLWExtra *te = maybeTopData()) {
12062 if (te->window && te->window->handle()) {
12063 const QMargins margins = te->window->frameMargins();
12064 if (!margins.isNull()) {
12065 te->frameStrut.setCoords(margins.left(), margins.top(), margins.right(), margins.bottom());
12066 q->data->fstrut_dirty = false;
12067 }
12068 }
12069 }
12070 }
12071}
12072
12073#ifdef QT_KEYPAD_NAVIGATION
12082bool QWidgetPrivate::navigateToDirection(Direction direction)
12083{
12084 QWidget *targetWidget = widgetInNavigationDirection(direction);
12085 if (targetWidget)
12086 targetWidget->setFocus();
12087 return (targetWidget != 0);
12088}
12089
12099QWidget *QWidgetPrivate::widgetInNavigationDirection(Direction direction)
12100{
12101 const QWidget *sourceWidget = QApplication::focusWidget();
12102 if (!sourceWidget)
12103 return nullptr;
12104 const QRect sourceRect = sourceWidget->rect().translated(sourceWidget->mapToGlobal(QPoint()));
12105 const int sourceX =
12107 (sourceRect.left() + (sourceRect.right() - sourceRect.left()) / 2)
12108 :(direction == DirectionEast ? sourceRect.right() : sourceRect.left());
12109 const int sourceY =
12111 (sourceRect.top() + (sourceRect.bottom() - sourceRect.top()) / 2)
12112 :(direction == DirectionSouth ? sourceRect.bottom() : sourceRect.top());
12113 const QPoint sourcePoint(sourceX, sourceY);
12114 const QPoint sourceCenter = sourceRect.center();
12115 const QWidget *sourceWindow = sourceWidget->window();
12116
12117 QWidget *targetWidget = nullptr;
12118 int shortestDistance = INT_MAX;
12119
12120 const auto targetCandidates = QApplication::allWidgets();
12121 for (QWidget *targetCandidate : targetCandidates) {
12122
12123 const QRect targetCandidateRect = targetCandidate->rect().translated(targetCandidate->mapToGlobal(QPoint()));
12124
12125 // For focus proxies, the child widget handling the focus can have keypad navigation focus,
12126 // but the owner of the proxy cannot.
12127 // Additionally, empty widgets should be ignored.
12128 if (targetCandidate->focusProxy() || targetCandidateRect.isEmpty())
12129 continue;
12130
12131 // Only navigate to a target widget that...
12132 if ( targetCandidate != sourceWidget
12133 // ...takes the focus,
12134 && targetCandidate->focusPolicy() & Qt::TabFocus
12135 // ...is above if DirectionNorth,
12136 && !(direction == DirectionNorth && targetCandidateRect.bottom() > sourceRect.top())
12137 // ...is on the right if DirectionEast,
12138 && !(direction == DirectionEast && targetCandidateRect.left() < sourceRect.right())
12139 // ...is below if DirectionSouth,
12140 && !(direction == DirectionSouth && targetCandidateRect.top() < sourceRect.bottom())
12141 // ...is on the left if DirectionWest,
12142 && !(direction == DirectionWest && targetCandidateRect.right() > sourceRect.left())
12143 // ...is enabled,
12144 && targetCandidate->isEnabled()
12145 // ...is visible,
12146 && targetCandidate->isVisible()
12147 // ...is in the same window,
12148 && targetCandidate->window() == sourceWindow) {
12149 const int targetCandidateDistance = [](const QPoint &sourcePoint,
12150 const QRect &targetCandidateRect) {
12151 int dx = 0;
12152 int dy = 0;
12153 if (p.x() < r.left())
12154 dx = r.left() - p.x();
12155 else if (p.x() > r.right())
12156 dx = p.x() - r.right();
12157 if (p.y() < r.top())
12158 dy = r.top() - p.y();
12159 else if (p.y() > r.bottom())
12160 dy = p.y() - r.bottom();
12161 return dx + dy;
12162 }();
12163 if (targetCandidateDistance < shortestDistance) {
12164 shortestDistance = targetCandidateDistance;
12165 targetWidget = targetCandidate;
12166 }
12167 }
12168 }
12169 return targetWidget;
12170}
12171
12183bool QWidgetPrivate::canKeypadNavigate(Qt::Orientation orientation)
12184{
12185 return orientation == Qt::Horizontal?
12186 (QWidgetPrivate::widgetInNavigationDirection(QWidgetPrivate::DirectionEast)
12187 || QWidgetPrivate::widgetInNavigationDirection(QWidgetPrivate::DirectionWest))
12188 :(QWidgetPrivate::widgetInNavigationDirection(QWidgetPrivate::DirectionNorth)
12189 || QWidgetPrivate::widgetInNavigationDirection(QWidgetPrivate::DirectionSouth));
12190}
12203bool QWidgetPrivate::inTabWidget(QWidget *widget)
12204{
12205 for (QWidget *tabWidget = widget; tabWidget; tabWidget = tabWidget->parentWidget())
12206 if (qobject_cast<const QTabWidget*>(tabWidget))
12207 return true;
12208 return false;
12209}
12210#endif
12211
12219void QWidget::setBackingStore(QBackingStore *store)
12220{
12221 // ### createWinId() ??
12222
12223 if (!isWindow())
12224 return;
12225
12226 Q_D(QWidget);
12227
12228 QTLWExtra *topData = d->topData();
12229 if (topData->backingStore == store)
12230 return;
12231
12232 QBackingStore *oldStore = topData->backingStore;
12234 topData->backingStore = store;
12235
12236 QWidgetRepaintManager *repaintManager = d->maybeRepaintManager();
12237 if (!repaintManager)
12238 return;
12239
12240 if (isWindow()) {
12241 if (repaintManager->backingStore() != oldStore && repaintManager->backingStore() != store)
12242 delete repaintManager->backingStore();
12243 repaintManager->setBackingStore(store);
12244 }
12245}
12246
12253{
12254 Q_D(const QWidget);
12255 QTLWExtra *extra = d->maybeTopData();
12256 if (extra && extra->backingStore)
12257 return extra->backingStore;
12258
12259 QWidgetRepaintManager *repaintManager = d->maybeRepaintManager();
12260 return repaintManager ? repaintManager->backingStore() : nullptr;
12261}
12262
12264{
12265 if (left)
12266 *left = (int)leftLayoutItemMargin;
12267 if (top)
12268 *top = (int)topLayoutItemMargin;
12269 if (right)
12271 if (bottom)
12273}
12274
12276{
12281 return;
12282
12283 Q_Q(QWidget);
12284 leftLayoutItemMargin = (signed char)left;
12285 topLayoutItemMargin = (signed char)top;
12286 rightLayoutItemMargin = (signed char)right;
12287 bottomLayoutItemMargin = (signed char)bottom;
12288 q->updateGeometry();
12289}
12290
12292{
12293 Q_Q(QWidget);
12294 QStyleOption myOpt;
12295 if (!opt) {
12296 myOpt.initFrom(q);
12297 myOpt.rect.setRect(0, 0, 32768, 32768); // arbitrary
12298 opt = &myOpt;
12299 }
12300
12301 QRect liRect = q->style()->subElementRect(element, opt, q);
12302 if (liRect.isValid()) {
12303 leftLayoutItemMargin = (signed char)(opt->rect.left() - liRect.left());
12304 topLayoutItemMargin = (signed char)(opt->rect.top() - liRect.top());
12305 rightLayoutItemMargin = (signed char)(liRect.right() - opt->rect.right());
12306 bottomLayoutItemMargin = (signed char)(liRect.bottom() - opt->rect.bottom());
12307 } else {
12312 }
12313}
12314// resets the Qt::WA_QuitOnClose attribute to the default value for transient widgets.
12316{
12317 Q_Q(QWidget);
12318
12319 if (!q->parentWidget()) {
12320 Qt::WindowType type = q->windowType();
12321 if (type == Qt::Widget || type == Qt::SubWindow)
12322 type = Qt::Window;
12323 if (type != Qt::Widget && type != Qt::Window && type != Qt::Dialog)
12324 q->setAttribute(Qt::WA_QuitOnClose, false);
12325 }
12326}
12327
12329{
12331 if (!wd->textureChildSeen)
12332 return;
12333 if (end)
12334 wd->endCompose();
12335 else
12336 wd->beginCompose();
12337 for (int i = 0; i < wd->children.size(); ++i) {
12339 if (w && !w->isWindow() && !w->isHidden() && QWidgetPrivate::get(w)->textureChildSeen)
12341 }
12342}
12343
12345{
12346 return widget->data;
12347}
12348
12350{
12351 return widget->d_func();
12352}
12353
12354
12355#if QT_CONFIG(graphicsview)
12365QGraphicsProxyWidget *QWidget::graphicsProxyWidget() const
12366{
12367 Q_D(const QWidget);
12368 if (d->extra) {
12369 return d->extra->proxyWidget;
12370 }
12371 return nullptr;
12372}
12373#endif
12374
12375#ifndef QT_NO_GESTURES
12382void QWidget::grabGesture(Qt::GestureType gesture, Qt::GestureFlags flags)
12383{
12384 Q_D(QWidget);
12385 d->gestureContext.insert(gesture, flags);
12386 (void)QGestureManager::instance(); // create a gesture manager
12387}
12388
12396{
12397 // if you modify this function, check the inlined version in ~QWidget, too
12398 Q_D(QWidget);
12399 if (d->gestureContext.remove(gesture)) {
12401 manager->cleanupCachedGestures(this, gesture);
12402 }
12403}
12404#endif // QT_NO_GESTURES
12405
12419void QWidget::destroy(bool destroyWindow, bool destroySubWindows)
12420{
12421 Q_D(QWidget);
12422
12423 d->aboutToDestroy();
12424 if (!isWindow() && parentWidget())
12425 parentWidget()->d_func()->invalidateBackingStore(d->effectiveRectFor(geometry()));
12426 d->deactivateWidgetCleanup();
12427
12428 if ((windowType() == Qt::Popup) && qApp)
12429 qApp->d_func()->closePopup(this);
12430
12433 if (QWidget::mouseGrabber() == this)
12434 releaseMouse();
12435 if (QWidget::keyboardGrabber() == this)
12437
12439
12440 if (windowType() != Qt::Desktop) {
12441 if (destroySubWindows) {
12442 QObjectList childList(children());
12443 for (int i = 0; i < childList.size(); i++) {
12444 QWidget *widget = qobject_cast<QWidget *>(childList.at(i));
12446 if (widget->windowHandle()) {
12447 widget->destroy();
12448 }
12449 }
12450 }
12451 }
12452 if (destroyWindow) {
12453 d->deleteTLSysExtra();
12454 } else {
12456 d->hide_sys();
12457 }
12458 }
12459
12460 d->setWinId(0);
12461 }
12462}
12463
12475{
12476 qWarning("QWidget::paintEngine: Should no longer be called");
12477
12478#ifdef Q_OS_WIN
12479 // We set this bit which is checked in setAttribute for
12480 // Qt::WA_PaintOnScreen. We do this to allow these two scenarios:
12481 //
12482 // 1. Users accidentally set Qt::WA_PaintOnScreen on X and port to
12483 // Windows which would mean suddenly their widgets stop working.
12484 //
12485 // 2. Users set paint on screen and subclass paintEngine() to
12486 // return 0, in which case we have a "hole" in the backingstore
12487 // allowing use of GDI or DirectX directly.
12488 //
12489 // 1 is WRONG, but to minimize silent failures, we have set this
12490 // bit to ignore the setAttribute call. 2. needs to be
12491 // supported because its our only means of embedding native
12492 // graphics stuff.
12493 const_cast<QWidgetPrivate *>(d_func())->noPaintOnScreen = 1;
12494#endif
12495
12496 return nullptr; //##### @@@
12497}
12498
12499// Do not call QWindow::mapToGlobal() until QPlatformWindow is properly showing.
12500static inline bool canMapPosition(QWindow *window)
12501{
12502 return window->handle() && !qt_window_private(window)->resizeEventPending;
12503}
12504
12505#if QT_CONFIG(graphicsview)
12506static inline QGraphicsProxyWidget *graphicsProxyWidget(const QWidget *w)
12507{
12508 QGraphicsProxyWidget *result = nullptr;
12509 const QWidgetPrivate *d = qt_widget_private(const_cast<QWidget *>(w));
12510 if (d->extra)
12511 result = d->extra->proxyWidget;
12512 return result;
12513}
12514#endif // QT_CONFIG(graphicsview)
12515
12519};
12520
12522{
12524 result.window = nullptr;
12525 for ( ; w ; w = w->parentWidget()) {
12526#if QT_CONFIG(graphicsview)
12527 if (QGraphicsProxyWidget *qgpw = graphicsProxyWidget(w)) {
12528 if (const QGraphicsScene *scene = qgpw->scene()) {
12529 const QList <QGraphicsView *> views = scene->views();
12530 if (!views.isEmpty()) {
12531 result.transform *= qgpw->sceneTransform();
12532 result.transform *= views.first()->viewportTransform();
12533 w = views.first()->viewport();
12534 }
12535 }
12536 }
12537#endif // QT_CONFIG(graphicsview)
12538 QWindow *window = w->windowHandle();
12539 if (window && canMapPosition(window)) {
12540 result.window = window;
12541 break;
12542 }
12543
12544 const QPoint topLeft = w->geometry().topLeft();
12545 result.transform.translate(topLeft.x(), topLeft.y());
12546 if (w->isWindow())
12547 break;
12548 }
12549 return result;
12550}
12551
12563{
12565 const QPointF g = t.transform.map(pos);
12566 return t.window ? t.window->mapToGlobal(g) : g;
12567}
12568
12573{
12574 return mapToGlobal(QPointF(pos)).toPoint();
12575}
12576
12587{
12589 const QPointF windowLocal = t.window ? t.window->mapFromGlobal(pos) : pos;
12590 return t.transform.inverted().map(windowLocal);
12591}
12592
12597{
12598 return mapFromGlobal(QPointF(pos)).toPoint();
12599}
12600
12603static bool mouseGrabWithCursor = false;
12604static QWidget *keyboardGrb = nullptr;
12605
12606static inline QWindow *grabberWindow(const QWidget *w)
12607{
12608 QWindow *window = w->windowHandle();
12609 if (!window)
12610 if (const QWidget *nativeParent = w->nativeParentWidget())
12611 window = nativeParent->windowHandle();
12612 return window;
12613}
12614
12615#ifndef QT_NO_CURSOR
12616static void grabMouseForWidget(QWidget *widget, const QCursor *cursor = nullptr)
12617#else
12618static void grabMouseForWidget(QWidget *widget)
12619#endif
12620{
12621 if (qt_mouseGrb)
12623
12624 mouseGrabWithCursor = false;
12626#ifndef QT_NO_CURSOR
12627 if (cursor) {
12628 mouseGrabWithCursor = true;
12630 }
12631#endif // !QT_NO_CURSOR
12632 window->setMouseGrabEnabled(true);
12633 }
12634
12636 qt_pressGrab = nullptr;
12637}
12638
12640{
12641 if (qt_mouseGrb == widget) {
12643#ifndef QT_NO_CURSOR
12644 if (mouseGrabWithCursor) {
12646 mouseGrabWithCursor = false;
12647 }
12648#endif // !QT_NO_CURSOR
12649 window->setMouseGrabEnabled(false);
12650 }
12651 }
12652 qt_mouseGrb = nullptr;
12653}
12654
12684{
12685 grabMouseForWidget(this);
12686}
12687
12704#ifndef QT_NO_CURSOR
12706{
12707 grabMouseForWidget(this, &cursor);
12708}
12709#endif
12710
12712{
12713 // This is like a combination of grab/releaseMouse() but with error checking
12714 // and it has no effect on the result of mouseGrabber().
12715 Q_Q(QWidget);
12717 return window ? window->setMouseGrabEnabled(grab) : false;
12718}
12719
12728{
12730}
12731
12752{
12753 if (keyboardGrb)
12755 if (QWindow *window = grabberWindow(this))
12756 window->setKeyboardGrabEnabled(true);
12757 keyboardGrb = this;
12758}
12759
12761{
12762 // This is like a combination of grab/releaseKeyboard() but with error
12763 // checking and it has no effect on the result of keyboardGrabber().
12764 Q_Q(QWidget);
12766 return window ? window->setKeyboardGrabEnabled(grab) : false;
12767}
12768
12777{
12778 if (keyboardGrb == this) {
12779 if (QWindow *window = grabberWindow(this))
12780 window->setKeyboardGrabEnabled(false);
12781 keyboardGrb = nullptr;
12782 }
12783}
12784
12796{
12797 if (qt_mouseGrb)
12798 return qt_mouseGrb;
12799 return qt_pressGrab;
12800}
12801
12813{
12814 return keyboardGrb;
12815}
12816
12842{
12843 QWindow *const wnd = window()->windowHandle();
12844
12845 if (wnd)
12846 wnd->requestActivate();
12847}
12848
12857{
12858 QScreen *screen = this->screen();
12859
12860 if (!screen) {
12861 if (m == PdmDpiX || m == PdmDpiY)
12862 return 72;
12863 return QPaintDevice::metric(m);
12864 }
12865
12866 auto resolveDevicePixelRatio = [this, screen]() -> qreal {
12867
12868 // Note: keep in sync with QBackingStorePrivate::backingStoreDevicePixelRatio()!
12869 static bool downscale = qEnvironmentVariableIntValue("QT_WIDGETS_HIGHDPI_DOWNSCALE") > 0;
12870 QWindow *window = this->window()->windowHandle();
12871 if (window)
12872 return downscale ? std::ceil(window->devicePixelRatio()) : window->devicePixelRatio();
12873 return screen->devicePixelRatio();
12874 };
12875
12876 switch (m) {
12877 case PdmWidth:
12878 return data->crect.width();
12879 case PdmWidthMM:
12880 return data->crect.width() * screen->physicalSize().width() / screen->geometry().width();
12881 case PdmHeight:
12882 return data->crect.height();
12883 case PdmHeightMM:
12884 return data->crect.height() * screen->physicalSize().height() / screen->geometry().height();
12885 case PdmDepth:
12886 return screen->depth();
12887 case PdmDpiX:
12888 for (const QWidget *p = this; p; p = p->parentWidget()) {
12889 if (p->d_func()->extra && p->d_func()->extra->customDpiX)
12890 return p->d_func()->extra->customDpiX;
12891 }
12893 case PdmDpiY:
12894 for (const QWidget *p = this; p; p = p->parentWidget()) {
12895 if (p->d_func()->extra && p->d_func()->extra->customDpiY)
12896 return p->d_func()->extra->customDpiY;
12897 }
12899 case PdmPhysicalDpiX:
12901 case PdmPhysicalDpiY:
12904 return resolveDevicePixelRatio();
12906 return QPaintDevice::devicePixelRatioFScale() * resolveDevicePixelRatio();
12907 default:
12908 break;
12909 }
12910 return QPaintDevice::metric(m);
12911}
12912
12919{
12920 const QPalette &pal = palette();
12921 painter->d_func()->state->pen = QPen(pal.brush(foregroundRole()), 1);
12922 painter->d_func()->state->bgBrush = pal.brush(backgroundRole());
12923 QFont f(font(), const_cast<QWidget *>(this));
12924 painter->d_func()->state->deviceFont = f;
12925 painter->d_func()->state->font = f;
12926}
12927
12934{
12935 return d_func()->redirected(offset);
12936}
12937
12944{
12945 // Someone sent a paint event directly to the widget
12946 if (!d_func()->redirectDev)
12947 return nullptr;
12948
12949 QPainter *sp = d_func()->sharedPainter();
12950 if (!sp || !sp->isActive())
12951 return nullptr;
12952
12953 if (sp->paintEngine()->paintDevice() != d_func()->redirectDev)
12954 return nullptr;
12955
12956 return sp;
12957}
12958
12981void QWidget::setMask(const QRegion &newMask)
12982{
12983 Q_D(QWidget);
12984
12985 d->createExtra();
12986 if (newMask == d->extra->mask)
12987 return;
12988
12989#ifndef QT_NO_BACKINGSTORE
12990 const QRegion oldMask(d->extra->mask);
12991#endif
12992
12993 d->extra->mask = newMask;
12994 d->extra->hasMask = !newMask.isEmpty();
12995
12997 return;
12998
12999 d->setMask_sys(newMask);
13000
13001#ifndef QT_NO_BACKINGSTORE
13002 if (!isVisible())
13003 return;
13004
13005 if (!d->extra->hasMask) {
13006 // Mask was cleared; update newly exposed area.
13007 QRegion expose(rect());
13008 expose -= oldMask;
13009 if (!expose.isEmpty()) {
13010 d->setDirtyOpaqueRegion();
13011 update(expose);
13012 }
13013 return;
13014 }
13015
13016 if (!isWindow()) {
13017 // Update newly exposed area on the parent widget.
13018 QRegion parentExpose(rect());
13019 parentExpose -= newMask;
13020 if (!parentExpose.isEmpty()) {
13021 d->setDirtyOpaqueRegion();
13022 parentExpose.translate(data->crect.topLeft());
13023 parentWidget()->update(parentExpose);
13024 }
13025
13026 // Update newly exposed area on this widget
13027 if (!oldMask.isEmpty())
13028 update(newMask - oldMask);
13029 }
13030#endif
13031}
13032
13034{
13035 Q_Q(QWidget);
13036 if (QWindow *window = q->windowHandle())
13037 window->setMask(region);
13038}
13039
13066{
13068}
13069
13078{
13079 Q_D(QWidget);
13080 if (!d->extra || !d->extra->hasMask)
13081 return;
13082 setMask(QRegion());
13083}
13084
13086{
13087 Q_ASSERT(widgetAsObject->isWidgetType());
13088 Q_ASSERT(!newParent || newParent->isWidgetType());
13089 QWidget *widget = static_cast<QWidget*>(widgetAsObject);
13090 widget->setParent(static_cast<QWidget*>(newParent));
13091}
13092
13094{
13095 Q_Q(const QWidget);
13096 std::string flags = QObjectPrivate::flagsForDumping();
13098 flags += 'F';
13099 if (q->isVisible()) {
13100 std::stringstream s;
13101 s << '<'
13102 << q->width() << 'x' << q->height()
13103 << std::showpos << q->x() << q->y()
13104 << '>';
13105 flags += s.str();
13106 } else {
13107 flags += 'I';
13108 }
13109 return flags;
13110}
13111
13113{
13114#if QT_CONFIG(xcb)
13115 Q_Q(QWidget);
13116
13117 if (!q->windowHandle())
13118 return;
13119
13120 QXcbWindow::WindowTypes wmWindowType = QXcbWindow::None;
13121 if (q->testAttribute(Qt::WA_X11NetWmWindowTypeDesktop))
13122 wmWindowType |= QXcbWindow::Desktop;
13123 if (q->testAttribute(Qt::WA_X11NetWmWindowTypeDock))
13124 wmWindowType |= QXcbWindow::Dock;
13125 if (q->testAttribute(Qt::WA_X11NetWmWindowTypeToolBar))
13126 wmWindowType |= QXcbWindow::Toolbar;
13127 if (q->testAttribute(Qt::WA_X11NetWmWindowTypeMenu))
13128 wmWindowType |= QXcbWindow::Menu;
13129 if (q->testAttribute(Qt::WA_X11NetWmWindowTypeUtility))
13130 wmWindowType |= QXcbWindow::Utility;
13131 if (q->testAttribute(Qt::WA_X11NetWmWindowTypeSplash))
13132 wmWindowType |= QXcbWindow::Splash;
13133 if (q->testAttribute(Qt::WA_X11NetWmWindowTypeDialog))
13134 wmWindowType |= QXcbWindow::Dialog;
13135 if (q->testAttribute(Qt::WA_X11NetWmWindowTypeDropDownMenu))
13136 wmWindowType |= QXcbWindow::DropDownMenu;
13137 if (q->testAttribute(Qt::WA_X11NetWmWindowTypePopupMenu))
13138 wmWindowType |= QXcbWindow::PopupMenu;
13139 if (q->testAttribute(Qt::WA_X11NetWmWindowTypeToolTip))
13140 wmWindowType |= QXcbWindow::Tooltip;
13141 if (q->testAttribute(Qt::WA_X11NetWmWindowTypeNotification))
13142 wmWindowType |= QXcbWindow::Notification;
13143 if (q->testAttribute(Qt::WA_X11NetWmWindowTypeCombo))
13144 wmWindowType |= QXcbWindow::Combo;
13145 if (q->testAttribute(Qt::WA_X11NetWmWindowTypeDND))
13146 wmWindowType |= QXcbWindow::Dnd;
13147
13148 if (wmWindowType == QXcbWindow::None && skipIfMissing)
13149 return;
13150
13151 if (auto *xcbWindow = dynamic_cast<QXcbWindow*>(q->windowHandle()->handle()))
13152 xcbWindow->setWindowType(wmWindowType);
13153#else
13154 Q_UNUSED(skipIfMissing);
13155#endif
13156}
13157
13158#ifndef QT_NO_DEBUG_STREAM
13159
13161{
13162 const QMetaObject *qtMo = qt_getEnumMetaObject(Qt::WA_AttributeCount);
13163 const QMetaEnum me = qtMo->enumerator(qtMo->indexOfEnumerator("WidgetAttribute"));
13164 debug << ", attributes=[";
13165 int count = 0;
13166 for (int a = 0; a < Qt::WA_AttributeCount; ++a) {
13167 if (widget->testAttribute(static_cast<Qt::WidgetAttribute>(a))) {
13168 if (count++)
13169 debug << ',';
13170 debug << me.valueToKey(a);
13171 }
13172 }
13173 debug << ']';
13174}
13175
13177{
13178 const QDebugStateSaver saver(debug);
13179 debug.nospace();
13180 if (widget) {
13181 debug << widget->metaObject()->className() << '(' << (const void *)widget;
13182 if (!widget->objectName().isEmpty())
13183 debug << ", name=" << widget->objectName();
13184 if (debug.verbosity() > 2) {
13185 const QRect geometry = widget->geometry();
13187 if (widget->isVisible())
13188 debug << ", visible";
13189 if (!widget->isEnabled())
13190 debug << ", disabled";
13191 debug << ", states=" << widget->windowState()
13192 << ", type=" << widget->windowType() << ", flags=" << widget->windowFlags();
13194 if (widget->isWindow())
13195 debug << ", window";
13196 debug << ", " << geometry.width() << 'x' << geometry.height()
13197 << Qt::forcesign << geometry.x() << geometry.y() << Qt::noforcesign;
13198 if (frameGeometry != geometry) {
13199 const QMargins margins(geometry.x() - frameGeometry.x(),
13200 geometry.y() - frameGeometry.y(),
13201 frameGeometry.right() - geometry.right(),
13202 frameGeometry.bottom() - geometry.bottom());
13203 debug << ", margins=" << margins;
13204 }
13205 debug << ", devicePixelRatio=" << widget->devicePixelRatio();
13206 if (const WId wid = widget->internalWinId())
13207 debug << ", winId=0x" << Qt::hex << wid << Qt::dec;
13208 }
13209 debug << ')';
13210 } else {
13211 debug << "QWidget(0x0)";
13212 }
13213 return debug;
13214}
13215#endif // !QT_NO_DEBUG_STREAM
13216
13218
13219#include "moc_qwidget.cpp"
13220#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:65
The QAction class provides an abstraction for user commands that can be added to different user inter...
Definition qaction.h:30
static QWidget * focus_widget
static QWidget * hidden_focus_widget
static QWidget * active_window
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:534
qsizetype size() const noexcept
Returns the number of bytes in this byte array.
Definition qbytearray.h:474
const char * constData() const noexcept
Returns a pointer to the const data stored in the byte array.
Definition qbytearray.h:122
char at(qsizetype i) const
Returns the byte at index position i in the byte array.
Definition qbytearray.h:523
\inmodule QtCore
Definition qcoreevent.h:372
The QCloseEvent class contains parameters that describe a close event.
Definition qevent.h:561
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:593
const QPoint & globalPos() const
Returns the global position of the mouse pointer at the time of the event.
Definition qevent.h:611
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:499
\inmodule QtCore\reentrant
Definition qdatastream.h:30
\inmodule QtCore
\inmodule QtCore
\inmodule QtGui
Definition qevent.h:164
\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:303
void accept()
Sets the accept flag of the event object, the equivalent of calling setAccepted(true).
Definition qcoreevent.h:305
\inmodule QtCore \reentrant
Definition qfileinfo.h:22
QString fileName() const
Returns the name of the file, excluding the path.
The QFocusEvent class contains event parameters for widget focus events.
Definition qevent.h:469
\reentrant
Definition qfont.h:20
bool isCopyOf(const QFont &) const
Returns true if this font and f are copies of each other, i.e.
Definition qfont.cpp:1845
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:1854
void setResolveMask(uint mask)
Definition qfont.h:252
uint resolveMask() const
Definition qfont.h:251
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...
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:787
const QPoint & globalPos() const
Returns the mouse cursor position when the event was generated in global coordinates.
Definition qevent.h:798
The QHideEvent class provides an event which is sent after a widget is hidden.
Definition qevent.h:585
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:973
\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:624
The QInputMethodQueryEvent class provides an event sent by the input context to input objects.
Definition qevent.h:678
Qt::InputMethodQueries queries() const
Returns the properties queried by the event.
Definition qevent.h:683
void setInputItemTransform(const QTransform &transform)
Sets the transformation from input item coordinates to window coordinates to be transform.
void update(Qt::InputMethodQueries queries)
Called by the input item to inform the platform input methods when there has been state changes in ed...
void hide()
Requests virtual keyboard to close.
void commit()
Commits the word user is currently composing to the editor.
void setInputItemRectangle(const QRectF &rect)
The QKeyEvent class describes a key event.
Definition qevent.h:423
Qt::KeyboardModifiers modifiers() const
Returns the keyboard modifier flags that existed immediately after the event occurred.
Definition qevent.cpp:1465
int key() const
Returns the code of the key that was pressed or released.
Definition qevent.h:433
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.
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:598
void update()
Updates the layout for parentWidget().
Definition qlayout.cpp:970
bool activate()
Redoes the layout for parentWidget() if necessary.
Definition qlayout.cpp:994
Qt::Orientations expandingDirections() const override
Returns whether this layout can make use of more space than sizeHint().
Definition qlayout.cpp:943
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:1176
qsizetype size() const noexcept
Definition qlist.h:386
bool isEmpty() const noexcept
Definition qlist.h:390
T & first()
Definition qlist.h:628
const_reference at(qsizetype i) const noexcept
Definition qlist.h:429
T value(qsizetype i) const
Definition qlist.h:661
qsizetype removeAll(const AT &t)
Definition qlist.h:575
void append(parameter_type t)
Definition qlist.h:441
\inmodule QtCore
Definition qmargins.h:23
constexpr int bottom() const noexcept
Returns the bottom margin.
Definition qmargins.h:119
constexpr bool isNull() const noexcept
Returns true if all margins are is 0; otherwise returns false.
Definition qmargins.h:107
constexpr int left() const noexcept
Returns the left margin.
Definition qmargins.h:110
constexpr int right() const noexcept
Returns the right margin.
Definition qmargins.h:116
constexpr int top() const noexcept
Returns the top margin.
Definition qmargins.h:113
QAction * exec()
Executes this menu synchronously.
Definition qmenu.cpp:2586
\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:195
The QMoveEvent class contains event parameters for move events.
Definition qevent.h:501
uint isWindow
Definition qobject.h:70
uint isWidget
Definition qobject.h:64
QObjectList children
Definition qobject.h:62
uint wasWidget
Definition qobject.h:74
uint willBeWidget
Definition qobject.h:73
QObject * parent
Definition qobject.h:61
void setParent_helper(QObject *)
Definition qobject.cpp:2166
virtual std::string flagsForDumping() const
Definition qobject.cpp:4228
\inmodule QtCore
Definition qobject.h:90
const QObjectList & children() const
Returns a list of child objects.
Definition qobject.h:171
QObject * parent() const
Returns a pointer to the parent object.
Definition qobject.h:311
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2823
QString objectName
the name of this object
Definition qobject.h:94
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:1363
void setParent(QObject *parent)
Makes the object a child of parent.
Definition qobject.cpp:2142
friend class QWidget
Definition qobject.h:347
QList< QByteArray > dynamicPropertyNames() const
Definition qobject.cpp:4216
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:313
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:118
bool paintingActive() const
qreal devicePixelRatio() const
@ PdmDevicePixelRatioScaled
int logicalDpiY() const
virtual QPaintDevice * redirected(QPoint *offset) const
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:485
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.
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:698
const QFont & font() const
Returns the currently set font used for drawing text.
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
bool end()
Ends painting.
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:794
quint64 ResolveMask
Definition qpalette.h:112
void setCurrentColorGroup(ColorGroup cg)
Set the palette's current color group to cg.
Definition qpalette.h:64
void setResolveMask(ResolveMask mask)
ResolveMask resolveMask() const
@ Inactive
Definition qpalette.h:48
@ Disabled
Definition qpalette.h:48
QPalette resolve(const QPalette &other) const
Returns a new QPalette that is a union of this instance and other.
bool isCopyOf(const QPalette &p) const
Returns true if this palette and p are copies of each other, i.e.
@ HighlightedText
Definition qpalette.h:52
@ ToolTipBase
Definition qpalette.h:56
@ ButtonText
Definition qpalette.h:51
@ WindowText
Definition qpalette.h:50
@ Highlight
Definition qpalette.h:52
@ ToolTipText
Definition qpalette.h:56
\inmodule QtGui
Definition qpen.h:25
Returns a copy of the pixmap that is transformed using the given transformation transform and transfo...
Definition qpixmap.h:27
void setRhiConfig(const QPlatformBackingStoreRhiConfig &config)
The QPlatformIntegration class is the entry for WindowSystem specific functionality.
virtual Qt::WindowState defaultWindowState(Qt::WindowFlags) const
virtual bool hasCapability(Capability cap) const
The QPlatformSurfaceEvent class is used to notify about native platform surface events....
Definition qevent.h:530
The QPlatformWindow class provides an abstraction for top-level windows.
QWindow * window() const
Returns the window which belongs to the QPlatformWindow.
virtual bool windowEvent(QEvent *event)
Reimplement this method to be able to do any platform specific event handling.
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,...
virtual void propagateSizeHints()
Reimplement to propagate the size hints of the QWindow.
\inmodule QtCore\reentrant
Definition qpoint.h:214
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:394
\inmodule QtCore\reentrant
Definition qpoint.h:23
constexpr int x() const noexcept
Returns the x coordinate of this point.
Definition qpoint.h:127
constexpr int y() const noexcept
Returns the y coordinate of this point.
Definition qpoint.h:132
\inmodule QtCore
Definition qpointer.h:18
bool isNull() const
Returns true if the referenced object has been destroyed or if there is no referenced object; otherwi...
Definition qpointer.h:67
\inmodule QtCore\reentrant
Definition qrect.h:483
QRect toAlignedRect() const noexcept
Definition qrect.cpp:2330
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:799
\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:166
constexpr void moveTopLeft(const QPoint &p) noexcept
Moves the rectangle, leaving the top-left corner at the given position.
Definition qrect.h:303
constexpr void moveBottom(int pos) noexcept
Moves the rectangle vertically, leaving the rectangle's bottom edge at the given y coordinate.
Definition qrect.h:297
constexpr void moveRight(int pos) noexcept
Moves the rectangle horizontally, leaving the rectangle's right edge at the given x coordinate.
Definition qrect.h:291
constexpr int height() const noexcept
Returns the height of the rectangle.
Definition qrect.h:238
constexpr bool isValid() const noexcept
Returns true if the rectangle is valid, otherwise returns false.
Definition qrect.h:169
constexpr bool isNull() const noexcept
Returns true if the rectangle is a null rectangle, otherwise returns false.
Definition qrect.h:163
constexpr int bottom() const noexcept
Returns the y-coordinate of the rectangle's bottom edge.
Definition qrect.h:181
constexpr QPoint topLeft() const noexcept
Returns the position of the rectangle's top-left corner.
Definition qrect.h:220
constexpr void setSize(const QSize &s) noexcept
Sets the size of the rectangle to the given size.
Definition qrect.h:386
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:369
constexpr int top() const noexcept
Returns the y-coordinate of the rectangle's top edge.
Definition qrect.h:175
constexpr void moveLeft(int pos) noexcept
Moves the rectangle horizontally, leaving the rectangle's left edge at the given x coordinate.
Definition qrect.h:285
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:851
constexpr int left() const noexcept
Returns the x-coordinate of the rectangle's left edge.
Definition qrect.h:172
constexpr void setRect(int x, int y, int w, int h) noexcept
Sets the coordinates of the rectangle's top-left corner to ({x}, {y}), and its size to the given widt...
Definition qrect.h:345
constexpr int x() const noexcept
Returns the x-coordinate of the rectangle's left edge.
Definition qrect.h:184
constexpr void setWidth(int w) noexcept
Sets the width of the rectangle to the given width.
Definition qrect.h:380
constexpr QSize size() const noexcept
Returns the size of the rectangle.
Definition qrect.h:241
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:244
constexpr QPoint bottomRight() const noexcept
Returns the position of the rectangle's bottom-right corner.
Definition qrect.h:223
constexpr int width() const noexcept
Returns the width of the rectangle.
Definition qrect.h:235
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:260
constexpr int y() const noexcept
Returns the y-coordinate of the rectangle's top edge.
Definition qrect.h:187
constexpr void setHeight(int h) noexcept
Sets the height of the rectangle to the given height.
Definition qrect.h:383
constexpr void moveTop(int pos) noexcept
Moves the rectangle vertically, leaving the rectangle's top edge at the given y coordinate.
Definition qrect.h:288
constexpr QPoint center() const noexcept
Returns the center point of the rectangle.
Definition qrect.h:232
constexpr int right() const noexcept
Returns the x-coordinate of the rectangle's right edge.
Definition qrect.h:178
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:547
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
QRect availableGeometry
the screen's available geometry in pixels
Definition qscreen.h:46
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
bool remove(const T &value)
Definition qset.h:63
iterator insert(const T &value)
Definition qset.h:155
The QShowEvent class provides an event that is sent when a widget is shown.
Definition qevent.h:577
\inmodule QtCore
Definition qsize.h:207
constexpr qreal width() const noexcept
Returns the width.
Definition qsize.h:321
constexpr qreal height() const noexcept
Returns the height.
Definition qsize.h:324
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:138
The QStatusTipEvent class provides an event that is used to show messages in a status bar.
Definition qevent.h:807
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
bool isNull() const
Returns true if this string is null; otherwise returns false.
Definition qstring.h:898
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition qstring.h:1083
QByteArray toLocal8Bit() const &
Definition qstring.h:567
The QStyleOption class stores the parameters used by QStyle functions.
void initFrom(const QWidget *w)
void updateStyleSheetFont(QWidget *w) const
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:606
@ SH_TitleBar_ModifyNotification
Definition qstyle.h:631
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
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option=nullptr, const QWidget *widget=nullptr) const =0
Returns the value of the given pixel metric.
virtual void unpolish(QWidget *widget)
Uninitialize the given {widget}'s appearance.
Definition qstyle.cpp:455
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:427
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...
QRect mapRect(const QRect &) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
\inmodule QtCore
Definition qvariant.h:64
bool isValid() const
Returns true if the storage type of this variant is not QMetaType::UnknownType; otherwise returns fal...
Definition qvariant.h:707
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
uint mustHaveWindowHandle
Definition qwidget_p.h:718
void deleteExtra()
Definition qwidget.cpp:1653
void setEnabled_helper(bool)
Definition qwidget.cpp:3372
uint dirtyOpaqueChildren
Definition qwidget_p.h:711
const QMetaObject * polished
Definition qwidget_p.h:648
void hideChildren(bool spontaneous)
Definition qwidget.cpp:8483
QSize adjustedSize() const
Definition qwidget.cpp:8727
QMargins safeAreaMargins() const
Definition qwidget.cpp:7758
QWindow * _q_closestWindowHandle() const
Definition qwidget.cpp:1058
void setWindowFilePath_sys(const QString &filePath)
Definition qwidget.cpp:6282
QTLWExtra * maybeTopData() const
Definition qwidget_p.h:824
static int instanceCounter
Definition qwidget_p.h:693
void setModal_sys()
Definition qwidget.cpp:2814
uint inheritedFontResolveMask
Definition qwidget_p.h:682
void setLayoutItemMargins(int left, int top, int right, int bottom)
QWidget * focus_next
Definition qwidget_p.h:640
QWidgetData data
Definition qwidget_p.h:696
static void adjustFlags(Qt::WindowFlags &flags, QWidget *w=nullptr)
Definition qwidget.cpp:888
void deactivateWidgetCleanup()
Definition qwidget.cpp:2313
virtual void setWindowFlags(Qt::WindowFlags windowFlags)
void repaint(T t)
bool setScreen(QScreen *screen)
Definition qwidget.cpp:2427
QRegion clipRegion() const
Definition qwidget.cpp:1896
void createSysExtra()
Definition qwidget.cpp:1644
void createTLExtra()
Definition qwidget.cpp:1582
void getLayoutItemMargins(int *left, int *top, int *right, int *bottom) const
void subtractOpaqueChildren(QRegion &rgn, const QRect &clipRect) const
Definition qwidget.cpp:2014
void setWindowTitle_helper(const QString &cap)
Definition qwidget.cpp:6033
void setMask_sys(const QRegion &)
QScreen * associatedScreen() const
Definition qwidget.cpp:1063
QWidget * childAtRecursiveHelper(const QPoint &p, bool) const
uint usesDoubleBufferedGLContext
Definition qwidget_p.h:717
void updateFont(const QFont &)
Definition qwidget.cpp:4784
void setParent_sys(QWidget *parent, Qt::WindowFlags)
QFont localFont() const
Definition qwidget.cpp:4753
signed char leftLayoutItemMargin
Definition qwidget_p.h:689
virtual void beginBackingStorePainting()
Definition qwidget_p.h:600
void setUpdatesEnabled_helper(bool)
Definition qwidget.cpp:1807
void scrollRect(const QRect &, int dx, int dy)
void hide_helper()
Definition qwidget.cpp:8216
uint high_attributes[4]
Definition qwidget_p.h:708
bool updateBrushOrigin(QPainter *, const QBrush &brush) const
Definition qwidget.cpp:2251
void updateFrameStrut()
QPalette::ResolveMask inheritedPaletteResolveMask
Definition qwidget_p.h:684
virtual QImage grabFramebuffer()
Definition qwidget_p.h:599
uint renderToTextureReallyDirty
Definition qwidget_p.h:724
QFont naturalWidgetFont(uint inheritedMask) const
Definition qwidget.cpp:4707
void activateChildLayoutsRecursively()
Definition qwidget.cpp:8022
void setSystemClip(QPaintEngine *paintEngine, qreal devicePixelRatio, const QRegion &region)
Definition qwidget.cpp:1933
virtual void endBackingStorePainting()
Definition qwidget_p.h:601
virtual QPlatformBackingStoreRhiConfig rhiConfig() const
Definition qwidget_p.h:584
static QWidgetMapper * mapper
Definition qwidget_p.h:653
void render(QPaintDevice *target, const QPoint &targetOffset, const QRegion &sourceRegion, QWidget::RenderFlags renderFlags)
Definition qwidget.cpp:5649
bool shouldDiscardSyncRequest() const
void restoreRedirected()
Definition qwidget_p.h:511
void setWindowIcon_sys()
Definition qwidget.cpp:6196
void updateContentsRect()
Definition qwidget.cpp:7712
void setSharedPainter(QPainter *painter)
Definition qwidget_p.h:836
bool setScreenForPoint(const QPoint &pos)
Definition qwidget.cpp:2412
uint retainSizeWhenHiddenChanged
Definition qwidget_p.h:713
void setWSGeometry()
Definition qwidget.cpp:208
void adjustQuitOnCloseAttribute()
void clipToEffectiveMask(QRegion &region) const
Definition qwidget.cpp:2111
void setFocus_sys()
Definition qwidget.cpp:6643
static QWidgetPrivate * get(QWidget *w)
Definition qwidget_p.h:211
void resolveLayoutDirection()
Definition qwidget.cpp:4860
@ DontSubtractOpaqueChildren
Definition qwidget_p.h:190
void scrollChildren(int dx, int dy)
Definition qwidget.cpp:186
bool stealKeyboardGrab(bool grab)
signed char topLayoutItemMargin
Definition qwidget_p.h:690
void setLocale_helper(const QLocale &l, bool forceUpdate=false)
Definition qwidget.cpp:5893
void reparentFocusWidgets(QWidget *oldtlw)
Definition qwidget.cpp:7100
void resolvePalette()
Definition qwidget.cpp:4604
QWidgetRepaintManager * maybeRepaintManager() const
Definition qwidget_p.h:850
static void setWidgetParentHelper(QObject *widgetAsObject, QObject *newParent)
const QRegion & getOpaqueChildren() const
Definition qwidget.cpp:1984
void showChildren(bool spontaneous)
Definition qwidget.cpp:8458
void propagatePaletteChange()
Definition qwidget.cpp:1836
void paintOnScreen(const QRegion &rgn)
Definition qwidget.cpp:1771
void paintSiblingsRecursive(QPaintDevice *pdev, const QObjectList &children, int index, const QRegion &rgn, const QPoint &offset, DrawWidgetFlags flags, QPainter *sharedPainter, QWidgetRepaintManager *repaintManager)
Definition qwidget.cpp:5721
void updateGeometry_helper(bool forceUpdate)
void setCursor_sys(const QCursor &cursor)
Definition qwidget.cpp:4983
QRegion prepareToRender(const QRegion &region, QWidget::RenderFlags renderFlags)
Definition qwidget.cpp:5330
QPaintEngine * extraPaintEngine
Definition qwidget_p.h:647
QWidget * deepestFocusProxy() const
Definition qwidget.cpp:6623
std::unique_ptr< QWExtra > extra
Definition qwidget_p.h:639
static void checkRestoredGeometry(const QRect &availableGeometry, QRect *restoredGeometry, int frameHeight)
Definition qwidget.cpp:7472
bool setMaximumSize_helper(int &maxw, int &maxh)
Definition qwidget.cpp:3977
void subtractOpaqueSiblings(QRegion &source, bool *hasDirtySiblingsAbove=nullptr, bool alsoNonOpaque=false) const
Definition qwidget.cpp:2025
void sendPaintEvent(const QRegion &toBePainted)
Definition qwidget.cpp:5639
void setStyle_helper(QStyle *newStyle, bool propagate)
Definition qwidget.cpp:2656
signed char bottomLayoutItemMargin
Definition qwidget_p.h:692
QRegion overlappedRegion(const QRect &rect, bool breakAfterFirst=false) const
Definition qwidget.cpp:1711
void updateWidgetTransform(QEvent *event)
Definition qwidget.cpp:215
QRegion dirty
Definition qwidget_p.h:664
void resolveFont()
Definition qwidget.cpp:4768
QLocale locale
Definition qwidget_p.h:698
@ CloseWithSpontaneousEvent
Definition qwidget_p.h:337
void scroll_sys(int dx, int dy)
QGraphicsEffect * graphicsEffect
Definition qwidget_p.h:649
signed char rightLayoutItemMargin
Definition qwidget_p.h:691
void render_helper(QPainter *painter, const QPoint &targetOffset, const QRegion &sourceRegion, QWidget::RenderFlags renderFlags)
Definition qwidget.cpp:5388
void setWinId(WId)
Definition qwidget.cpp:1562
void createTLSysExtra()
Definition qwidget.cpp:1377
uint textureChildSeen
Definition qwidget_p.h:720
bool stealMouseGrab(bool grab)
void setRedirected(QPaintDevice *replacement, const QPoint &offset)
Definition qwidget_p.h:497
void resolveLocale()
Definition qwidget.cpp:5932
void setWindowIcon_helper()
Definition qwidget.cpp:6151
void setNetWmWindowTypes(bool skipIfMissing=false)
QRect frameStrut() const
bool shouldPaintOnScreen() const
Definition qwidget.cpp:2136
void setDirtyOpaqueRegion()
Definition qwidget.cpp:1961
QWidget * focus_child
Definition qwidget_p.h:642
void updateIsOpaque()
Definition qwidget.cpp:2151
std::string flagsForDumping() const override
void syncBackingStore()
Definition qwidget.cpp:1752
virtual void beginCompose()
Definition qwidget_p.h:602
QRegion opaqueChildren
Definition qwidget_p.h:663
bool pointInsideRectAndMask(const QPoint &) const
Definition qwidget_p.h:843
void setWindowModified_helper()
QPalette naturalWidgetPalette(QPalette::ResolveMask inheritedMask) const
Definition qwidget.cpp:4560
void invalidateBackingStore_resizeHelper(const QPoint &oldPos, const QSize &oldSize)
Invalidates the backing store when the widget is resized.
QWidgetItemV2 * widgetItem
Definition qwidget_p.h:646
virtual void resolveSamples()
Definition qwidget_p.h:626
void setWindowTitle_sys(const QString &cap)
Definition qwidget.cpp:6040
void updateSystemBackground()
Definition qwidget.cpp:4624
void setVisible(bool)
Definition qwidget.cpp:8344
void paintBackground(QPainter *, const QRegion &, DrawWidgetFlags flags=DrawAsRoot) const
Definition qwidget.cpp:2268
void setOpaque(bool opaque)
Definition qwidget.cpp:2190
QWidget * childAt_helper(const QPoint &, bool) const
void unsetCursor_sys()
Definition qwidget.cpp:5003
void drawWidget(QPaintDevice *pdev, const QRegion &rgn, const QPoint &offset, DrawWidgetFlags flags, QPainter *sharedPainter=nullptr, QWidgetRepaintManager *repaintManager=nullptr)
Definition qwidget.cpp:5452
void setWindowIconText_helper(const QString &cap)
Definition qwidget.cpp:6051
void updateIsTranslucent()
Definition qwidget.cpp:2198
void inheritStyle()
Definition qwidget.cpp:2703
uint renderToTexture
Definition qwidget_p.h:719
QRect effectiveRectFor(const QRegion &region) const
Definition qwidget_p.h:534
void update(T t)
QWidget * focus_prev
Definition qwidget_p.h:641
QSizePolicy size_policy
Definition qwidget_p.h:697
QRect clipRect() const
Definition qwidget.cpp:1872
QWidget * effectiveFocusWidget()
Definition qwidget_p.h:434
QTLWExtra * topData() const
Definition qwidget_p.h:818
void setLayoutDirection_helper(Qt::LayoutDirection)
Definition qwidget.cpp:4842
void sendPendingMoveAndResizeEvents(bool recursive=false, bool disableUpdates=false)
Definition qwidget.cpp:7990
void setWindowOpacity_sys(qreal opacity)
void moveRect(const QRect &, int dx, int dy)
bool handleClose(CloseMode mode)
Definition qwidget.cpp:8545
void setPalette_helper(const QPalette &)
Definition qwidget.cpp:4611
QPaintDevice * redirected(QPoint *offset) const
Definition qwidget_p.h:504
QPainter * sharedPainter() const
Definition qwidget_p.h:829
bool setMinimumSize_helper(int &minw, int &minh)
Definition qwidget.cpp:3889
void init(QWidget *desktopWidget, Qt::WindowFlags f)
Definition qwidget.cpp:936
uint directFontResolveMask
Definition qwidget_p.h:681
void deleteSysExtra()
Definition qwidget.cpp:1671
void setGeometry_sys(int, int, int, int, bool)
Definition qwidget.cpp:7297
void setFont_helper(const QFont &font)
Definition qwidget_p.h:273
static int maxInstances
Definition qwidget_p.h:694
void createExtra()
Definition qwidget.cpp:1615
decltype(std::declval< QPalette >().resolveMask()) directPaletteResolveMask
Definition qwidget_p.h:683
void invalidateBackingStore(const T &)
void show_recursive()
Definition qwidget.cpp:7972
void setTextureChildSeen()
Definition qwidget_p.h:605
virtual void endCompose()
Definition qwidget_p.h:603
void setWindowIconText_sys(const QString &cap)
Definition qwidget.cpp:6058
virtual QObject * focusObject()
Definition qwidget.cpp:6856
void createWinId()
Definition qwidget.cpp:2377
void setWindowFilePath_helper(const QString &filePath)
Definition qwidget.cpp:6266
void deleteTLSysExtra()
Definition qwidget.cpp:1683
void createRecursively()
Definition qwidget.cpp:1018
QWidgetPrivate(int version=QObjectPrivateVersion)
Definition qwidget.cpp:94
QLayout * layout
Definition qwidget_p.h:643
void fixPosIncludesFrame()
Definition qwidget.cpp:7229
void updateFocusChild()
Definition qwidget.cpp:6661
void stackUnder_sys(QWidget *)
void show_helper()
Definition qwidget.cpp:8052
static QWidgetSet * allWidgets
Definition qwidget_p.h:654
QWindow * windowHandle(WindowHandleMode mode=WindowHandleMode::Direct) const
Definition qwidget.cpp:1029
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:5316
void _q_showIfNotHidden()
Definition qwidget.cpp:8451
void setConstraints_sys()
Definition qwidget.cpp:3922
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.
QWidget * widget() const
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
void setAutoFillBackground(bool enabled)
Definition qwidget.cpp:319
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:6254
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:8713
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:4340
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:6298
QWidget * window() const
Returns the window for this widget, i.e.
Definition qwidget.cpp:4320
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:6085
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:4398
bool autoFillBackground
whether the widget background is filled automatically
Definition qwidget.h:172
void setUpdatesEnabled(bool enable)
Definition qwidget.cpp:7940
QPointF mapFromParent(const QPointF &) const
Translates the parent widget coordinate pos to widget coordinates.
Definition qwidget.cpp:4293
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:9777
void setWindowModality(Qt::WindowModality windowModality)
Definition qwidget.cpp:2806
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:9507
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:7676
Q_INVOKABLE QPixmap grab(const QRect &rectangle=QRect(QPoint(0, 0), QSize(-1, -1)))
Definition qwidget.cpp:5219
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.
QWidget * topLevelWidget() const
Definition qwidget.h:312
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:2637
QWidget * focusProxy() const
Returns the focus proxy, or \nullptr if there is no focus proxy.
Definition qwidget.cpp:6452
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:9902
void setMinimumWidth(int minw)
Definition qwidget.cpp:4119
bool isMinimized() const
Definition qwidget.cpp:2843
bool isFullScreen() const
Definition qwidget.cpp:2989
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:6868
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:6706
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:7002
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:3365
void setWindowOpacity(qreal level)
void setFocusProxy(QWidget *)
Sets the widget's focus proxy to widget w.
Definition qwidget.cpp:6372
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:4537
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:9881
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:9529
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:8689
@ 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:2854
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:6881
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:9576
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:2883
friend class QStyleSheetStyle
Definition qwidget.h:760
QRect contentsRect() const
Returns the area inside the widget's margins.
Definition qwidget.cpp:7753
void overrideWindowState(Qt::WindowStates state)
Definition qwidget.cpp:2907
~QWidget()
Destroys the widget.
Definition qwidget.cpp:1414
void unsetCursor()
Definition qwidget.cpp:4990
void setShortcutAutoRepeat(int id, bool enable=true)
bool close()
Closes this widget.
Definition qwidget.cpp:8608
void adjustSize()
Adjusts the size of the widget to fit its contents.
Definition qwidget.cpp:8789
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:2448
void showFullScreen()
Shows the widget in full-screen mode.
Definition qwidget.cpp:3028
QWidget * focusWidget() const
Returns the last child of this widget that setFocus had been called on.
Definition qwidget.cpp:6851
void setContextMenuPolicy(Qt::ContextMenuPolicy policy)
Definition qwidget.cpp:7872
static QWidget * find(WId)
Returns a pointer to the widget with window identifier/handle id.
Definition qwidget.cpp:2334
virtual void focusInEvent(QFocusEvent *event)
This event handler can be reimplemented in a subclass to receive keyboard focus events (focus receive...
Definition qwidget.cpp:9711
bool isModal() const
Definition qwidget.h:817
void setAcceptDrops(bool on)
Definition qwidget.cpp:3443
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:9554
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:9687
QSizePolicy sizePolicy
the default layout behavior of the widget
Definition qwidget.h:119
void setMaximumHeight(int maxh)
Definition qwidget.cpp:4146
QLocale locale
the widget's locale
Definition qwidget.h:176
void setFocusPolicy(Qt::FocusPolicy policy)
Definition qwidget.cpp:7904
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:9847
void setWindowRole(const QString &)
Sets the window's role to role.
Definition qwidget.cpp:6308
QSize minimumSizeHint
the recommended minimum size for the widget
Definition qwidget.h:149
void hide()
Hides the widget.
Definition qwidget.cpp:8209
void setMinimumHeight(int minh)
Definition qwidget.cpp:4128
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:6800
virtual QVariant inputMethodQuery(Qt::InputMethodQuery) const
This method is only relevant for input widgets.
Definition qwidget.cpp:9959
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:3214
int devType() const override
Definition qwidget.cpp:881
void setHidden(bool hidden)
Convenience function, equivalent to setVisible(!hidden).
Definition qwidget.cpp:8446
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:3097
void setWindowState(Qt::WindowStates state)
Sets the window state to windowState.
Definition qwidget.cpp:2944
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:3457
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:4886
void show()
Shows the widget and its child widgets.
Definition qwidget.cpp:7956
virtual void setVisible(bool visible)
Definition qwidget.cpp:8329
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:3149
void setScreen(QScreen *)
Sets the screen on which the widget should be shown to screen.
Definition qwidget.cpp:2531
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:9761
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:2490
virtual void changeEvent(QEvent *)
This event handler can be reimplemented to handle state changes.
Definition qwidget.cpp:9428
void setFixedHeight(int h)
Sets both the minimum and maximum heights of the widget to h without changing the widths.
Definition qwidget.cpp:4182
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:3051
void setFixedWidth(int w)
Sets both the minimum and maximum width of the widget to w without changing the heights.
Definition qwidget.cpp:4162
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:9944
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:4236
Qt::InputMethodHints inputMethodHints
What input method specific hints the widget has.
Definition qwidget.h:178
WId effectiveWinId() const
Definition qwidget.cpp:2469
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:3134
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:2364
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:6109
QPaintDevice * redirected(QPoint *offset) const override
QByteArray saveGeometry() const
Definition qwidget.cpp:7423
bool event(QEvent *event) override
This is the main event handler; it handles event event.
Definition qwidget.cpp:8912
void setLocale(const QLocale &locale)
Definition qwidget.cpp:5917
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:2607
void setWindowIcon(const QIcon &icon)
Definition qwidget.cpp:6178
void setFont(const QFont &)
Definition qwidget.cpp:4674
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:5099
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:1129
void destroy(bool destroyWindow=true, bool destroySubWindows=true)
Frees up window system resources.
bool hasFocus() const
Definition qwidget.cpp:6471
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:9737
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:9868
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:4418
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:4204
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:2895
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:8868
QBackingStore * backingStore() const
QScreen * screen() const
Returns the screen the widget is on.
Definition qwidget.cpp:2503
void showNormal()
Restores the widget after it has been maximized or minimized.
Definition qwidget.cpp:3067
void setForegroundRole(QPalette::ColorRole)
Sets the foreground role of the widget to role.
Definition qwidget.cpp:4463
void clearMask()
Removes any mask set by setMask().
bool restoreGeometry(const QByteArray &geometry)
Definition qwidget.cpp:7535
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:3183
bool isActiveWindow
whether this widget's window is the active window
Definition qwidget.h:139
void setStyleSheet(const QString &styleSheet)
Definition qwidget.cpp:2562
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:4367
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:9652
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:4270
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:4089
QMargins contentsMargins() const
The contentsMargins function returns the widget's contents margins.
Definition qwidget.cpp:7740
void removeAction(QAction *action)
Removes the action action from this widget's list of actions.
Definition qwidget.cpp:3193
virtual void paintEvent(QPaintEvent *event)
This event handler can be reimplemented in a subclass to receive paint events passed in event.
Definition qwidget.cpp:9829
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:4904
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:3124
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:4967
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:9921
void unsetLocale()
Definition qwidget.cpp:5943
void setMaximumWidth(int maxw)
Definition qwidget.cpp:4137
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)
QPlatformWindow * platformWindow
Definition qwindow_p.h:101
void setAutomaticPositionAndResizeEnabled(bool a)
Definition qwindow_p.h:89
PositionPolicy positionPolicy
Definition qwindow_p.h:116
QSize sizeIncrement
Definition qwindow_p.h:130
bool resizeEventPending
Definition qwindow_p.h:114
QSize minimumSize
Definition qwindow_p.h:127
QSize maximumSize
Definition qwindow_p.h:128
\inmodule QtGui
Definition qevent.h:898
\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
double e
QSet< QString >::iterator it
rect
[4]
direction
QStyleOptionButton opt
short next
Definition keywords.cpp:445
Combined button and popup list for selecting options.
WindowState
Definition qnamespace.h:250
@ WindowFullScreen
Definition qnamespace.h:254
@ WindowNoState
Definition qnamespace.h:251
@ WindowMinimized
Definition qnamespace.h:252
@ WindowMaximized
Definition qnamespace.h:253
@ WindowActive
Definition qnamespace.h:255
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:56
WidgetAttribute
Definition qnamespace.h:281
@ WA_GrabbedShortcut
Definition qnamespace.h:315
@ WA_X11NetWmWindowTypeDND
Definition qnamespace.h:397
@ WA_SetWindowIcon
Definition qnamespace.h:318
@ WA_X11NetWmWindowTypePopupMenu
Definition qnamespace.h:393
@ WA_WState_ExplicitShowHide
Definition qnamespace.h:334
@ WA_AcceptTouchEvents
Definition qnamespace.h:403
@ WA_UnderMouse
Definition qnamespace.h:283
@ WA_AlwaysStackOnTop
Definition qnamespace.h:410
@ WA_WState_WindowOpacitySet
Definition qnamespace.h:400
@ WA_TransparentForMouseEvents
Definition qnamespace.h:316
@ WA_ForceUpdatesDisabled
Definition qnamespace.h:324
@ WA_PendingResizeEvent
Definition qnamespace.h:301
@ WA_SetLayoutDirection
Definition qnamespace.h:322
@ WA_StyleSheet
Definition qnamespace.h:371
@ WA_MacMiniSize
Definition qnamespace.h:362
@ WA_SetLocale
Definition qnamespace.h:357
@ WA_SetPalette
Definition qnamespace.h:302
@ WA_WindowPropagation
Definition qnamespace.h:348
@ WA_MacAlwaysShowToolWindow
Definition qnamespace.h:369
@ WA_SetWindowModality
Definition qnamespace.h:399
@ WA_X11NetWmWindowTypeDock
Definition qnamespace.h:386
@ WA_X11NetWmWindowTypeUtility
Definition qnamespace.h:389
@ WA_RightToLeft
Definition qnamespace.h:321
@ WA_X11NetWmWindowTypeDialog
Definition qnamespace.h:391
@ WA_X11NetWmWindowTypeSplash
Definition qnamespace.h:390
@ WA_SetCursor
Definition qnamespace.h:304
@ WA_X11NetWmWindowTypeDropDownMenu
Definition qnamespace.h:392
@ WA_Resized
Definition qnamespace.h:307
@ WA_QuitOnClose
Definition qnamespace.h:341
@ WA_WState_Polished
Definition qnamespace.h:331
@ WA_TranslucentBackground
Definition qnamespace.h:401
@ WA_NoChildEventsFromChildren
Definition qnamespace.h:305
@ WA_DontShowOnScreen
Definition qnamespace.h:382
@ WA_ContentsMarginsRespectsSafeArea
Definition qnamespace.h:414
@ WA_X11NetWmWindowTypeToolTip
Definition qnamespace.h:394
@ WA_X11NetWmWindowTypeCombo
Definition qnamespace.h:396
@ WA_X11NetWmWindowTypeToolBar
Definition qnamespace.h:387
@ WA_DropSiteRegistered
Definition qnamespace.h:346
@ WA_KeyboardFocusChange
Definition qnamespace.h:343
@ WA_PendingMoveEvent
Definition qnamespace.h:300
@ WA_PaintOnScreen
Definition qnamespace.h:289
@ WA_NoChildEventsForParent
Definition qnamespace.h:323
@ WA_AttributeCount
Definition qnamespace.h:419
@ WA_DontCreateNativeAncestors
Definition qnamespace.h:378
@ WA_Moved
Definition qnamespace.h:308
@ WA_SetStyle
Definition qnamespace.h:355
@ WA_MacNormalSize
Definition qnamespace.h:360
@ WA_NativeWindow
Definition qnamespace.h:377
@ WA_Disabled
Definition qnamespace.h:282
@ WA_TabletTracking
Definition qnamespace.h:412
@ WA_OutsideWSRange
Definition qnamespace.h:314
@ WA_WState_Hidden
Definition qnamespace.h:296
@ WA_StaticContents
Definition qnamespace.h:287
@ WA_ShowWithoutActivating
Definition qnamespace.h:373
@ WA_X11NetWmWindowTypeMenu
Definition qnamespace.h:388
@ WA_WState_Visible
Definition qnamespace.h:295
@ WA_NoSystemBackground
Definition qnamespace.h:290
@ WA_WState_InPaintEvent
Definition qnamespace.h:328
@ WA_WState_OwnSizePolicy
Definition qnamespace.h:333
@ WA_SetFont
Definition qnamespace.h:303
@ WA_StyledBackground
Definition qnamespace.h:365
@ WA_WState_Created
Definition qnamespace.h:326
@ WA_MacSmallSize
Definition qnamespace.h:361
@ WA_TintedBackground
Definition qnamespace.h:351
@ WA_ShowModal
Definition qnamespace.h:336
@ WA_X11NetWmWindowTypeDesktop
Definition qnamespace.h:385
@ WA_UpdatesDisabled
Definition qnamespace.h:291
@ WA_InputMethodEnabled
Definition qnamespace.h:294
@ WA_MouseTracking
Definition qnamespace.h:284
@ WA_ForceDisabled
Definition qnamespace.h:298
@ WA_Mapped
Definition qnamespace.h:292
@ WA_OpaquePaintEvent
Definition qnamespace.h:286
@ WA_DeleteOnClose
Definition qnamespace.h:320
@ WA_WindowModified
Definition qnamespace.h:306
@ WA_LayoutOnEntireRect
Definition qnamespace.h:313
@ WA_AcceptDrops
Definition qnamespace.h:345
@ WA_X11NetWmWindowTypeNotification
Definition qnamespace.h:395
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:105
@ NoFocus
Definition qnamespace.h:106
@ TabFocus
Definition qnamespace.h:107
Orientation
Definition qnamespace.h:97
@ Horizontal
Definition qnamespace.h:98
@ Vertical
Definition qnamespace.h:99
@ ArrowCursor
@ ImhNone
@ transparent
Definition qnamespace.h:46
@ Key_Tab
Definition qnamespace.h:659
@ Key_Right
Definition qnamespace.h:674
@ Key_Backtab
Definition qnamespace.h:660
@ Key_Left
Definition qnamespace.h:672
@ Key_Up
Definition qnamespace.h:673
@ Key_Down
Definition qnamespace.h:675
@ Key_F1
Definition qnamespace.h:685
QTextStream & dec(QTextStream &stream)
Calls QTextStream::setIntegerBase(10) on stream and returns stream.
@ ShiftModifier
@ ControlModifier
@ AltModifier
@ AA_DontCreateNativeWidgetSiblings
Definition qnamespace.h:428
@ AA_UseStyleSheetPropagationInWidgetStyles
Definition qnamespace.h:456
@ AA_NativeWindows
Definition qnamespace.h:427
@ AA_PluginApplication
Definition qnamespace.h:429
QTextStream & forcesign(QTextStream &stream)
Calls QTextStream::setNumberFlags(QTextStream::numberFlags() | QTextStream::ForceSign) on stream and ...
@ SolidPattern
@ TexturePattern
@ NoBrush
@ ApplicationActive
Definition qnamespace.h:265
ConnectionType
CoordinateSystem
@ DeviceCoordinates
GestureType
WindowType
Definition qnamespace.h:204
@ CustomizeWindowHint
Definition qnamespace.h:238
@ Desktop
Definition qnamespace.h:214
@ Widget
Definition qnamespace.h:205
@ FramelessWindowHint
Definition qnamespace.h:224
@ MSWindowsOwnDC
Definition qnamespace.h:221
@ WindowContextHelpButtonHint
Definition qnamespace.h:230
@ ToolTip
Definition qnamespace.h:212
@ Popup
Definition qnamespace.h:210
@ WindowType_Mask
Definition qnamespace.h:219
@ Window
Definition qnamespace.h:206
@ SplashScreen
Definition qnamespace.h:213
@ WindowFullscreenButtonHint
Definition qnamespace.h:244
@ WindowMaximizeButtonHint
Definition qnamespace.h:228
@ WindowMinimizeButtonHint
Definition qnamespace.h:227
@ Dialog
Definition qnamespace.h:207
@ WindowMinMaxButtonsHint
Definition qnamespace.h:229
@ Sheet
Definition qnamespace.h:208
@ WindowTransparentForInput
Definition qnamespace.h:233
@ SubWindow
Definition qnamespace.h:215
@ MaximizeUsingFullscreenGeometryHint
Definition qnamespace.h:236
@ Tool
Definition qnamespace.h:211
@ WindowTitleHint
Definition qnamespace.h:225
@ WindowSystemMenuHint
Definition qnamespace.h:226
@ WindowCloseButtonHint
Definition qnamespace.h:240
ContextMenuPolicy
@ ActionsContextMenu
@ DefaultContextMenu
@ CustomContextMenu
@ PreventContextMenu
FocusReason
@ PopupFocusReason
@ BacktabFocusReason
@ NoFocusReason
@ MenuBarFocusReason
@ OtherFocusReason
@ TabFocusReason
ShortcutContext
Definition brush.cpp:5
static void * context
Q_WIDGETS_EXPORT QWidget * qt_button_down
void qt_qpa_set_cursor(QWidget *w, bool force)
Definition qwidget.cpp:5021
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:303
int qRound(qfloat16 d) noexcept
Definition qfloat16.h:281
#define qDebug
[1]
Definition qlogging.h:160
@ QtWarningMsg
Definition qlogging.h:31
#define qWarning
Definition qlogging.h:162
#define qFatal
Definition qlogging.h:164
#define Q_LOGGING_CATEGORY(name,...)
#define qCInfo(category,...)
#define qCDebug(category,...)
return ret
static const QMetaObjectPrivate * priv(const uint *data)
constexpr const T & qMin(const T &a, const T &b)
Definition qminmax.h:40
constexpr const T & qBound(const T &min, const T &val, const T &max)
Definition qminmax.h:44
constexpr const T & qMax(const T &a, const T &b)
Definition qminmax.h:42
@ QObjectPrivateVersion
Definition qobject_p.h:61
#define SIGNAL(a)
Definition qobjectdefs.h:52
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
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
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLenum GLuint GLintptr offset
GLboolean GLboolean g
GLuint name
GLint first
GLint GLint GLint GLint GLint GLint GLint GLbitfield mask
GLfloat n
GLint GLsizei GLsizei GLenum format
GLint y
GLfloat GLfloat GLfloat GLfloat h
GLsizei GLsizei GLchar * source
struct _cl_event * event
GLuint GLenum GLenum transform
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
GLuint64EXT * result
[6]
GLdouble s
[6]
Definition qopenglext.h:235
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 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:1391
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 int qEnvironmentVariableIntValue(const char *varName, bool *ok=nullptr) noexcept
#define emit
#define Q_UNUSED(x)
unsigned int quint32
Definition qtypes.h:45
unsigned short quint16
Definition qtypes.h:43
int qint32
Definition qtypes.h:44
unsigned int uint
Definition qtypes.h:29
double qreal
Definition qtypes.h:92
unsigned char quint8
Definition qtypes.h:41
ptrdiff_t qintptr
Definition qtypes.h:71
static bool canMapPosition(QWindow *window)
static void unsetCursor(QWidget *w)
Definition qwidget.cpp:5015
static QWidget * keyboardGrb
void q_createNativeChildrenAndSetParent(const QWidget *parentWidget)
Definition qwidget.cpp:1215
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:5996
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:5192
static void applyCursor(QWidget *w, const QCursor &c)
Definition qwidget.cpp:5009
static void formatWidgetAttributes(QDebug debug, const QWidget *widget)
static bool isEmbedded(const QWindow *w)
Definition qwidget.cpp:6637
static void releaseMouseGrabOfWidget(QWidget *widget)
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:86
static void deleteBackingStore(QWidgetPrivate *d)
Definition qwidget.cpp:1675
QWidget * qt_pressGrab
void qt_qpa_set_cursor(QWidget *w, bool force)
Definition qwidget.cpp:5021
bool q_evaluateRhiConfig(const QWidget *w, QPlatformBackingStoreRhiConfig *outConfig, QSurface::SurfaceType *outType)
Definition qwidget.cpp:1095
static QWindow * grabberWindow(const QWidget *w)
static void fillRegion(QPainter *painter, const QRegion &rgn, const QBrush &brush)
Definition qwidget.cpp:2230
static bool q_evaluateRhiConfigRecursive(const QWidget *w, QPlatformBackingStoreRhiConfig *outConfig, QSurface::SurfaceType *outType)
Definition qwidget.cpp:1076
QWidget * qt_mouseGrb
bool qt_sendSpontaneousEvent(QObject *, QEvent *)
#define QWIDGETSIZE_MAX
Definition qwidget.h:930
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:168
Q_GUI_EXPORT QWindowPrivate * qt_window_private(QWindow *window)
Definition qwindow.cpp:2864
QWindow * qobject_cast< QWindow * >(QObject *o)
Definition qwindow.h:367
QT_BEGIN_NAMESPACE typedef QHash< WId, QWidget * > QWidgetMapper
Definition qwindowdefs.h:68
static QWindowsDirect2DWindow * nativeWindow(QWindow *window)
static QRect frameGeometry(HWND hwnd, bool topLevel)
const char property[13]
Definition qwizard.cpp:101
const char className[16]
[1]
Definition qwizard.cpp:100
QWidget * win
Definition settings.cpp:6
if(qFloatDistance(a, b)<(1<< 7))
[0]
obj metaObject() -> className()
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:955
\inmodule QtCore
int indexOfEnumerator(const char *name) const
Finds enumerator name and returns its index; otherwise returns -1.
QMetaEnum enumerator(int index) const
Returns the meta-data for the enumerator with the given index.
QRect frameStrut
Definition qwidget_p.h:108
std::unique_ptr< QWidgetRepaintManager > repaintManager
Definition qwidget_p.h:93
uint posIncludesFrame
Definition qwidget_p.h:117
QRect normalGeometry
Definition qwidget_p.h:109
uint opacity
Definition qwidget_p.h:116
uint sizeAdjusted
Definition qwidget_p.h:118
QScreen * initialScreen
Definition qwidget_p.h:111
QBackingStore * backingStore
Definition qwidget_p.h:94
QWidgetWindow * window
Definition qwidget_p.h:96
static void cleanup(QWidget *that, QWidgetPrivate *d)
Definition qwidget.cpp:810
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent