Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qwidget.cpp
Go to the documentation of this file.
1// Copyright (C) 2017 The Qt Company Ltd.
2// Copyright (C) 2016 Intel Corporation.
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4
5#include "qapplication.h"
6#include "qapplication_p.h"
7#include "qbrush.h"
8#include "qcursor.h"
9#include "private/qduplicatetracker_p.h"
10#include "qevent.h"
11#include "qlayout.h"
12#if QT_CONFIG(menu)
13#include "qmenu.h"
14#endif
15#include "qmetaobject.h"
16#include "qpixmap.h"
17#include "qpointer.h"
18#include "qstack.h"
19#include "qstyle.h"
20#include "qstylefactory.h"
21#include "qvariant.h"
22#include "qwidget.h"
23#include "qstyleoption.h"
24#include "qstylehints.h"
25#if QT_CONFIG(accessibility)
26# include "qaccessible.h"
27#endif
28#include <qpa/qplatformwindow.h>
29#include <qpa/qplatformwindow_p.h>
30#include "private/qwidgetwindow_p.h"
31#include "qpainter.h"
32#if QT_CONFIG(tooltip)
33#include "qtooltip.h"
34#endif
35#if QT_CONFIG(whatsthis)
36#include "qwhatsthis.h"
37#endif
38#include "qdebug.h"
39#include "private/qstylesheetstyle_p.h"
40#include "private/qstyle_p.h"
41#include "qfileinfo.h"
42#include "qscopeguard.h"
43#include <QtGui/private/qhighdpiscaling_p.h>
44#include <QtGui/qinputmethod.h>
45
46#if QT_CONFIG(graphicseffect)
47#include <private/qgraphicseffect_p.h>
48#endif
49#include <qbackingstore.h>
50#include <private/qwidgetrepaintmanager_p.h>
51#include <private/qpaintengine_raster_p.h>
52
53#include "qwidget_p.h"
54#include <QtGui/private/qwindow_p.h>
55#if QT_CONFIG(action)
56# include "QtGui/private/qaction_p.h"
57#endif
58#include "qlayout_p.h"
59#if QT_CONFIG(graphicsview)
60#include "QtWidgets/qgraphicsproxywidget.h"
61#include "QtWidgets/qgraphicsscene.h"
62#include "private/qgraphicsproxywidget_p.h"
63#endif
64#include "QtWidgets/qabstractscrollarea.h"
65#include "private/qabstractscrollarea_p.h"
66#include "private/qevent_p.h"
67
68#include "private/qgesturemanager_p.h"
69
70#ifdef QT_KEYPAD_NAVIGATION
71#if QT_CONFIG(tabwidget)
72#include "qtabwidget.h" // Needed in inTabWidget()
73#endif
74#endif // QT_KEYPAD_NAVIGATION
75
76#include "qwindowcontainer_p.h"
77
78#include <sstream>
79
81
82using namespace QNativeInterface::Private;
83using namespace Qt::StringLiterals;
84
85Q_LOGGING_CATEGORY(lcWidgetPainting, "qt.widgets.painting", QtWarningMsg);
86Q_LOGGING_CATEGORY(lcWidgetShowHide, "qt.widgets.showhide", QtWarningMsg);
87Q_LOGGING_CATEGORY(lcWidgetWindow, "qt.widgets.window", QtWarningMsg);
88Q_LOGGING_CATEGORY(lcWidgetFocus, "qt.widgets.focus")
89
90#ifndef QT_NO_DEBUG_STREAM
91namespace {
92 struct WidgetAttributes { const QWidget *widget; };
93 QDebug operator<<(QDebug debug, const WidgetAttributes &attributes);
94}
95#endif
96
97static inline bool qRectIntersects(const QRect &r1, const QRect &r2)
98{
99 return (qMax(r1.left(), r2.left()) <= qMin(r1.right(), r2.right()) &&
100 qMax(r1.top(), r2.top()) <= qMin(r1.bottom(), r2.bottom()));
101}
102
103extern bool qt_sendSpontaneousEvent(QObject*, QEvent*); // qapplication.cpp
104
106 : QObjectPrivate(version)
107 , focus_next(nullptr)
108 , focus_prev(nullptr)
109 , focus_child(nullptr)
110 , layout(nullptr)
111 , needsFlush(nullptr)
112 , redirectDev(nullptr)
113 , widgetItem(nullptr)
114 , extraPaintEngine(nullptr)
115 , polished(nullptr)
116 , graphicsEffect(nullptr)
117#if !defined(QT_NO_IM)
118 , imHints(Qt::ImhNone)
119#endif
120#if QT_CONFIG(tooltip)
121 , toolTipDuration(-1)
122#endif
123 , directFontResolveMask(0)
124 , inheritedFontResolveMask(0)
125 , directPaletteResolveMask(0)
126 , inheritedPaletteResolveMask(0)
127 , leftmargin(0)
128 , topmargin(0)
129 , rightmargin(0)
130 , bottommargin(0)
131 , leftLayoutItemMargin(0)
132 , topLayoutItemMargin(0)
133 , rightLayoutItemMargin(0)
134 , bottomLayoutItemMargin(0)
135 , hd(nullptr)
136 , size_policy(QSizePolicy::Preferred, QSizePolicy::Preferred)
137 , fg_role(QPalette::NoRole)
138 , bg_role(QPalette::NoRole)
139 , dirtyOpaqueChildren(1)
140 , isOpaque(0)
141 , retainSizeWhenHiddenChanged(0)
142 , inDirtyList(0)
143 , isScrolled(0)
144 , isMoved(0)
145 , usesDoubleBufferedGLContext(0)
146 , mustHaveWindowHandle(0)
147 , renderToTexture(0)
148 , textureChildSeen(0)
149#ifndef QT_NO_IM
150 , inheritsInputMethodHints(0)
151#endif
152 , renderToTextureReallyDirty(1)
153 , usesRhiFlush(0)
154 , childrenHiddenByWState(0)
155 , childrenShownByExpose(0)
156#if defined(Q_OS_WIN)
157 , noPaintOnScreen(0)
158#endif
159{
160 if (Q_UNLIKELY(!qApp)) {
161 qFatal("QWidget: Must construct a QApplication before a QWidget");
162 return;
163 }
164
165#ifdef QT_BUILD_INTERNAL
166 // Don't check the version parameter in internal builds.
167 // This allows incompatible versions to be loaded, possibly for testing.
168 Q_UNUSED(version);
169#else
170 if (Q_UNLIKELY(version != QObjectPrivateVersion))
171 qFatal("Cannot mix incompatible Qt library (version 0x%x) with this library (version 0x%x)",
172 version, QObjectPrivateVersion);
173#endif
174
175 willBeWidget = true; // used in QObject's ctor
176 memset(high_attributes, 0, sizeof(high_attributes));
177
178#ifdef QWIDGET_EXTRA_DEBUG
179 static int count = 0;
180 qDebug() << "widgets" << ++count;
181#endif
182}
183
184
186{
187 if (widgetItem)
188 widgetItem->wid = nullptr;
189
190 if (extra)
191 deleteExtra();
192}
193
198{
199 Q_Q(QWidget);
200 if (q->children().size() > 0) { // scroll children
201 QPoint pd(dx, dy);
202 QObjectList childObjects = q->children();
203 for (int i = 0; i < childObjects.size(); ++i) { // move all children
204 QWidget *w = qobject_cast<QWidget*>(childObjects.at(i));
205 if (w && !w->isWindow()) {
206 QPoint oldp = w->pos();
207 QRect r(w->pos() + pd, w->size());
208 w->data->crect = r;
209 if (w->testAttribute(Qt::WA_WState_Created))
210 w->d_func()->setWSGeometry();
211 w->d_func()->setDirtyOpaqueRegion();
212 QMoveEvent e(r.topLeft(), oldp);
214 }
215 }
216 }
217}
218
220{
221 Q_Q(QWidget);
222 if (QWindow *window = q->windowHandle())
223 window->setGeometry(data.crect);
224}
225
227{
228 Q_Q(QWidget);
229 if (q == QGuiApplication::focusObject() || event->type() == QEvent::FocusIn) {
231 QPoint p = q->mapTo(q->topLevelWidget(), QPoint(0,0));
232 t.translate(p.x(), p.y());
233 QGuiApplication::inputMethod()->setInputItemTransform(t);
234 QGuiApplication::inputMethod()->setInputItemRectangle(q->rect());
236 }
237}
238
239#ifdef QT_KEYPAD_NAVIGATION
240QPointer<QWidget> QWidgetPrivate::editingWidget;
241
249bool QWidget::hasEditFocus() const
250{
251 const QWidget* w = this;
252 while (w->d_func()->extra && w->d_func()->extra->focus_proxy)
253 w = w->d_func()->extra->focus_proxy;
254 return QWidgetPrivate::editingWidget == w;
255}
256
269void QWidget::setEditFocus(bool on)
270{
271 QWidget *f = this;
272 while (f->d_func()->extra && f->d_func()->extra->focus_proxy)
273 f = f->d_func()->extra->focus_proxy;
274
275 if (QWidgetPrivate::editingWidget && QWidgetPrivate::editingWidget != f)
276 QWidgetPrivate::editingWidget->setEditFocus(false);
277
278 if (on && !f->hasFocus())
279 f->setFocus();
280
281 if ((!on && !QWidgetPrivate::editingWidget)
282 || (on && QWidgetPrivate::editingWidget == f)) {
283 return;
284 }
285
286 if (!on && QWidgetPrivate::editingWidget == f) {
287 QWidgetPrivate::editingWidget = 0;
288 QEvent event(QEvent::LeaveEditFocus);
291 } else if (on) {
292 QWidgetPrivate::editingWidget = f;
293 QEvent event(QEvent::EnterEditFocus);
296 }
297}
298#endif
299
325{
326 Q_D(const QWidget);
327 return d->extra && d->extra->autoFillBackground;
328}
329
331{
332 Q_D(QWidget);
333 if (!d->extra)
334 d->createExtra();
335 if (d->extra->autoFillBackground == enabled)
336 return;
337
338 d->extra->autoFillBackground = enabled;
339 d->updateIsOpaque();
340 update();
341 d->updateIsOpaque();
342}
343
789QWidgetMapper *QWidgetPrivate::mapper = nullptr; // widget with wid
790QWidgetSet *QWidgetPrivate::allWidgets = nullptr; // widgets with no wid
791
792
793/*****************************************************************************
794 QWidget member functions
795 *****************************************************************************/
796
797/*
798 Widget state flags:
799 \list
800 \li Qt::WA_WState_Created The widget has a valid winId().
801 \li Qt::WA_WState_Visible The widget is currently visible.
802 \li Qt::WA_WState_Hidden The widget is hidden, i.e. it won't
803 become visible unless you call show() on it. Qt::WA_WState_Hidden
804 implies !Qt::WA_WState_Visible.
805 \li Qt::WA_WState_CompressKeys Compress keyboard events.
806 \li Qt::WA_WState_BlockUpdates Repaints and updates are disabled.
807 \li Qt::WA_WState_InPaintEvent Currently processing a paint event.
808 \li Qt::WA_WState_Reparented The widget has been reparented.
809 \li Qt::WA_WState_ConfigPending A configuration (resize/move) event is pending.
810 \endlist
811*/
812
814{
815 /* this cleans up when the constructor throws an exception */
816 static inline void cleanup(QWidget *that, QWidgetPrivate *d)
817 {
818#ifdef QT_NO_EXCEPTIONS
819 Q_UNUSED(that);
820 Q_UNUSED(d);
821#else
822 QWidgetPrivate::allWidgets->remove(that);
823 d->removeFromFocusChain();
824#endif
825 }
826};
827
853QWidget::QWidget(QWidget *parent, Qt::WindowFlags f)
855{
856 QT_TRY {
857 d_func()->init(parent, f);
858 } QT_CATCH(...) {
859 QWidgetExceptionCleaner::cleanup(this, d_func());
861 }
862}
863
864
867QWidget::QWidget(QWidgetPrivate &dd, QWidget* parent, Qt::WindowFlags f)
869{
870 Q_D(QWidget);
871 QT_TRY {
872 d->init(parent, f);
873 } QT_CATCH(...) {
874 QWidgetExceptionCleaner::cleanup(this, d_func());
876 }
877}
878
883{
884 return QInternal::Widget;
885}
886
887
888//### w is a "this" ptr, passed as a param because QWorkspace needs special logic
890{
891 bool customize = (flags & (Qt::CustomizeWindowHint
899
901
902 if ((type == Qt::Widget || type == Qt::SubWindow) && w && !w->parent()) {
904 flags |= Qt::Window;
905 }
906
908 // modify window flags to make them consistent.
909 // Only enable this on non-Mac platforms. Since the old way of doing this would
910 // interpret WindowSystemMenuHint as a close button and we can't change that behavior
911 // we can't just add this in.
913# ifdef Q_OS_WIN
914 && type != Qt::Dialog // QTBUG-2027, allow for menu-less dialogs.
915# endif
916 ) {
919 flags &= ~Qt::FramelessWindowHint;
920 }
921 } else if (customize && !(flags & Qt::FramelessWindowHint)) {
922 // if any of the window hints that affect the titlebar are set
923 // and the window is supposed to have frame, we add a titlebar
924 // and system menu by default.
927 }
928 if (!customize) { // don't modify window flags if the user explicitly set them.
930 if (type != Qt::Dialog && type != Qt::Sheet && type != Qt::Tool)
932 }
933 if (w->testAttribute(Qt::WA_TransparentForMouseEvents))
935}
936
937void QWidgetPrivate::init(QWidget *parentWidget, Qt::WindowFlags f)
938{
939 Q_Q(QWidget);
940 isWidget = true;
941 wasWidget = true;
942
943 Q_ASSERT_X(q != parentWidget, Q_FUNC_INFO, "Cannot parent a QWidget to itself");
944
945 if (Q_UNLIKELY(!qobject_cast<QApplication *>(QCoreApplication::instance())))
946 qFatal("QWidget: Cannot create a QWidget without QApplication");
947
949 if (allWidgets)
950 allWidgets->insert(q);
951
952 q->data = &data;
953
954#if QT_CONFIG(thread)
955 if (!parent) {
956 Q_ASSERT_X(q->thread() == qApp->thread(), "QWidget",
957 "Widgets must be created in the GUI thread.");
958 }
959#endif
960
961 data.fstrut_dirty = true;
962
963 data.winid = 0;
964 data.widget_attributes = 0;
965 data.window_flags = f;
966 data.window_state = 0;
967 data.focus_policy = 0;
968 data.context_menu_policy = Qt::DefaultContextMenu;
969 data.window_modality = Qt::NonModal;
970
971 data.sizehint_forced = 0;
972 data.is_closing = false;
973 data.in_show = 0;
974 data.in_set_window_state = 0;
975 data.in_destructor = false;
976
977 // Widgets with Qt::MSWindowsOwnDC (typically QGLWidget) must have a window handle.
978 if (f & Qt::MSWindowsOwnDC) {
980 q->setAttribute(Qt::WA_NativeWindow);
981 }
982
983 q->setAttribute(Qt::WA_QuitOnClose); // might be cleared in adjustQuitOnCloseAttribute()
985
987 q->setAttribute(Qt::WA_WState_Hidden);
988
989 //give potential windows a bigger "pre-initial" size; create() will give them a new size later
990 data.crect = parentWidget ? QRect(0,0,100,30) : QRect(0,0,640,480);
992
994 q->create();
995 else if (parentWidget)
996 q->setParent(parentWidget, data.window_flags);
997 else {
998 adjustFlags(data.window_flags, q);
1000 // opaque system background?
1001 const QBrush &background = q->palette().brush(QPalette::Window);
1002 setOpaque(q->isWindow() && background.style() != Qt::NoBrush && background.isOpaque());
1003 }
1004 data.fnt = QFont(data.fnt, q);
1005
1006 q->setAttribute(Qt::WA_PendingMoveEvent);
1007 q->setAttribute(Qt::WA_PendingResizeEvent);
1008
1011
1015
1016 extraPaintEngine = nullptr;
1017}
1018
1020{
1021 Q_Q(QWidget);
1022 q->create(0, true, true);
1023 for (int i = 0; i < children.size(); ++i) {
1025 if (child && !child->isHidden() && !child->isWindow() && !child->testAttribute(Qt::WA_WState_Created))
1026 child->d_func()->createRecursively();
1027 }
1028}
1029
1031{
1032 if (QWidgetRepaintManager *repaintManager = maybeRepaintManager())
1033 return repaintManager->rhi();
1034 else
1035 return nullptr;
1036}
1037
1047{
1048 Q_Q(const QWidget);
1049 QWidget *parent = q->parentWidget();
1050 while (parent && !parent->windowHandle())
1051 parent = parent->parentWidget();
1052 return parent;
1053}
1054
1056{
1058 if (QTLWExtra *x = maybeTopData()) {
1059 if (x->window != nullptr || mode == WindowHandleMode::Direct)
1060 return x->window;
1061 }
1062 }
1064 // FIXME: Use closestParentWidgetWithWindowHandle instead
1065 if (auto nativeParent = q_func()->nativeParentWidget()) {
1066 if (auto window = nativeParent->windowHandle())
1067 return window;
1068 }
1069 }
1071 if (auto topLevel = q_func()->topLevelWidget()) {
1072 if (auto window = topLevel ->windowHandle())
1073 return window;
1074 }
1075 }
1076 return nullptr;
1077}
1078
1089
1091{
1092#if QT_CONFIG(graphicsview)
1093 // embedded widgets never have a screen associated, let QWidget::screen fall back to toplevel
1094 if (nearestGraphicsProxyWidget(q_func()))
1095 return nullptr;
1096#endif
1098 return window->screen();
1099 return nullptr;
1100}
1101
1102// finds the first rhiconfig in the hierarchy that has enable==true
1104{
1106 if (config.isEnabled()) {
1107 if (outConfig)
1108 *outConfig = config;
1109 if (outType)
1111 return true;
1112 }
1113 for (const QObject *child : w->children()) {
1114 if (const QWidget *childWidget = qobject_cast<const QWidget *>(child)) {
1115 if (q_evaluateRhiConfigRecursive(childWidget, outConfig, outType))
1116 return true;
1117 }
1118 }
1119 return false;
1120}
1121
1123{
1124 // First, check env.vars. or other means that force the usage of rhi-based
1125 // flushing with a specific graphics API. This takes precedence over what
1126 // the widgets themselves declare. This is global, applying to all
1127 // top-levels.
1128 if (QBackingStoreRhiSupport::checkForceRhi(outConfig, outType)) {
1129 qCDebug(lcWidgetPainting) << "Tree with root" << w << "evaluated to forced flushing with QRhi";
1130 return true;
1131 }
1132
1133 // Otherwise, check the widget hierarchy to see if there is a child (or
1134 // ourselves) that declare the need for rhi-based composition.
1135 if (q_evaluateRhiConfigRecursive(w, outConfig, outType)) {
1136 qCDebug(lcWidgetPainting) << "Tree with root" << w << "evaluates to flushing with QRhi";
1137 return true;
1138 }
1139
1140 return false;
1141}
1142
1143// ### fixme: Qt 6: Remove parameter window from QWidget::create()
1144
1156void QWidget::create(WId window, bool initializeWindow, bool destroyOldWindow)
1157{
1158 Q_UNUSED(initializeWindow);
1159 Q_UNUSED(destroyOldWindow);
1160
1161 Q_D(QWidget);
1162 if (Q_UNLIKELY(window))
1163 qWarning("QWidget::create(): Parameter 'window' does not have any effect.");
1165 return;
1166
1167 if (d->data.in_destructor)
1168 return;
1169
1171 Qt::WindowFlags &flags = data->window_flags;
1172
1173 if ((type == Qt::Widget || type == Qt::SubWindow) && !parentWidget()) {
1174 type = Qt::Window;
1175 flags |= Qt::Window;
1176 }
1177
1178 if (QWidget *parent = parentWidget()) {
1179 if (type & Qt::Window) {
1180 if (!parent->testAttribute(Qt::WA_WState_Created))
1181 parent->createWinId();
1182 } else if (testAttribute(Qt::WA_NativeWindow) && !parent->internalWinId()
1184 // We're about to create a native child widget that doesn't have a native parent;
1185 // enforce a native handle for the parent unless the Qt::WA_DontCreateNativeAncestors
1186 // attribute is set.
1187 d->createWinId();
1188 // Nothing more to do.
1191 return;
1192 }
1193 }
1194
1195
1196 static const bool paintOnScreenEnv = qEnvironmentVariableIntValue("QT_ONSCREEN_PAINT") > 0;
1197 if (paintOnScreenEnv)
1199
1202
1203 d->updateIsOpaque();
1204
1205 setAttribute(Qt::WA_WState_Created); // set created flag
1206 d->create();
1207
1208 // A real toplevel window needs a paint manager
1209 if (isWindow() && windowType() != Qt::Desktop)
1210 d->topData()->repaintManager.reset(new QWidgetRepaintManager(this));
1211
1212 d->setModal_sys();
1213
1216
1217 // need to force the resting of the icon after changing parents
1219 d->setWindowIcon_sys();
1220
1221 if (isWindow() && !d->topData()->iconText.isEmpty())
1222 d->setWindowIconText_helper(d->topData()->iconText);
1223 if (isWindow() && !d->topData()->caption.isEmpty())
1224 d->setWindowTitle_helper(d->topData()->caption);
1225 if (isWindow() && !d->topData()->filePath.isEmpty())
1226 d->setWindowFilePath_helper(d->topData()->filePath);
1227 if (windowType() != Qt::Desktop) {
1228 d->updateSystemBackground();
1229
1231 d->setWindowIcon_sys();
1232 }
1233
1234 // Frame strut update needed in cases where there are native widgets such as QGLWidget,
1235 // as those force native window creation on their ancestors before they are shown.
1236 // If the strut is not updated, any subsequent move of the top level window before show
1237 // will cause window frame to be ignored when positioning the window.
1238 // Note that this only helps on platforms that handle window creation synchronously.
1239 d->updateFrameStrut();
1240}
1241
1243{
1244 QObjectList children = parentWidget->children();
1245 for (int i = 0; i < children.size(); i++) {
1246 if (children.at(i)->isWidgetType()) {
1247 const QWidget *childWidget = qobject_cast<const QWidget *>(children.at(i));
1248 if (childWidget) { // should not be necessary
1249 if (childWidget->testAttribute(Qt::WA_NativeWindow)) {
1250 if (!childWidget->internalWinId())
1251 childWidget->winId();
1252 if (childWidget->windowHandle()) {
1253 if (childWidget->isWindow()) {
1254 childWidget->windowHandle()->setTransientParent(parentWidget->window()->windowHandle());
1255 } else {
1256 childWidget->windowHandle()->setParent(childWidget->nativeParentWidget()->windowHandle());
1257 }
1258 }
1259 } else {
1261 }
1262 }
1263 }
1264 }
1265
1266}
1267
1269{
1270 Q_Q(QWidget);
1271
1272 if (!q->testAttribute(Qt::WA_NativeWindow) && !q->isWindow())
1273 return; // we only care about real toplevels
1274
1276 // topData() ensures the extra is created but does not ensure 'window' is non-null
1277 // in case the extra was already valid.
1278 if (!win) {
1281 win = topData()->window;
1282 }
1283
1284 const auto dynamicPropertyNames = q->dynamicPropertyNames();
1285 for (const QByteArray &propertyName : dynamicPropertyNames) {
1286 if (!qstrncmp(propertyName, "_q_platform_", 12))
1287 win->setProperty(propertyName, q->property(propertyName));
1288 }
1289
1290 Qt::WindowFlags &flags = data.window_flags;
1291
1292#if defined(QT_PLATFORM_UIKIT)
1293 if (q->testAttribute(Qt::WA_ContentsMarginsRespectsSafeArea))
1295#endif
1296
1297 if (q->testAttribute(Qt::WA_ShowWithoutActivating))
1298 win->setProperty("_q_showWithoutActivating", QVariant(true));
1299 if (q->testAttribute(Qt::WA_MacAlwaysShowToolWindow))
1300 win->setProperty("_q_macAlwaysShowToolWindow", QVariant(true));
1301 win->setFlags(flags);
1303 if (q->testAttribute(Qt::WA_Moved)
1305 win->setGeometry(q->geometry());
1306 else
1307 win->resize(q->size());
1308 if (win->isTopLevel()) {
1309 QScreen *targetScreen = topData()->initialScreen;
1310 topData()->initialScreen = nullptr;
1311 if (!targetScreen) {
1312 targetScreen = q->windowType() != Qt::Desktop
1313 ? q->screen() : nullptr;
1314 }
1315 win->setScreen(targetScreen);
1316 }
1317
1318 QSurfaceFormat format = win->requestedFormat();
1319 if ((flags & Qt::Window) && win->surfaceType() != QSurface::OpenGLSurface
1321 format.setAlphaBufferSize(8);
1322 }
1323 win->setFormat(format);
1324
1325 if (QWidget *nativeParent = q->nativeParentWidget()) {
1326 if (nativeParent->windowHandle()) {
1327 if (flags & Qt::Window) {
1328 win->setTransientParent(nativeParent->window()->windowHandle());
1329 win->setParent(nullptr);
1330 } else {
1331 win->setTransientParent(nullptr);
1332 win->setParent(nativeParent->windowHandle());
1333 }
1334 }
1335 }
1336
1337 qt_window_private(win)->positionPolicy = topData()->posIncludesFrame ?
1339
1340 if (q->windowType() != Qt::Desktop || q->testAttribute(Qt::WA_NativeWindow)) {
1341 win->create();
1342 // Enable nonclient-area events for QDockWidget and other NonClientArea-mouse event processing.
1343 if (QPlatformWindow *platformWindow = win->handle())
1344 platformWindow->setFrameStrutEventsEnabled(true);
1345 }
1346
1347 data.window_flags = win->flags();
1348
1349#if QT_CONFIG(xcb)
1350 if (!topData()->role.isNull()) {
1351 if (auto *xcbWindow = dynamic_cast<QXcbWindow*>(win->handle()))
1352 xcbWindow->setWindowRole(topData()->role);
1353 }
1354#endif
1355
1356 QBackingStore *store = q->backingStore();
1357 usesRhiFlush = false;
1358
1359 if (!store) {
1360 if (q->windowType() != Qt::Desktop) {
1361 if (q->isWindow()) {
1362 q->setBackingStore(new QBackingStore(win));
1366 }
1367 } else {
1368 q->setAttribute(Qt::WA_PaintOnScreen, true);
1369 }
1370 } else if (win->handle()) {
1371 usesRhiFlush = q_evaluateRhiConfig(q, nullptr, nullptr);
1372 }
1373
1375
1376 if (win->handle()) {
1377 WId id = win->winId();
1378 // See the QPlatformWindow::winId() documentation
1379 Q_ASSERT(id != WId(0));
1380 setWinId(id);
1381 }
1382 setNetWmWindowTypes(true); // do nothing if none of WA_X11NetWmWindowType* is set
1383
1384 // Check children and create windows for them if necessary
1386
1387 if (extra && !extra->mask.isEmpty())
1388 setMask_sys(extra->mask);
1389
1390 if (data.crect.width() == 0 || data.crect.height() == 0) {
1391 q->setAttribute(Qt::WA_OutsideWSRange, true);
1392 } else if (q->isVisible()) {
1393 // If widget is already shown, set window visible, too
1394 win->setNativeWindowVisibility(true);
1395 }
1396}
1397
1398#ifdef Q_OS_WIN
1399static const char activeXNativeParentHandleProperty[] = "_q_embedded_native_parent_handle";
1400#endif
1401
1403{
1404 Q_Q(QWidget);
1405 if (!extra->topextra->window && (q->testAttribute(Qt::WA_NativeWindow) || q->isWindow())) {
1406 extra->topextra->window = new QWidgetWindow(q);
1407 if (extra->minw || extra->minh)
1408 extra->topextra->window->setMinimumSize(QSize(extra->minw, extra->minh));
1409 if (extra->maxw != QWIDGETSIZE_MAX || extra->maxh != QWIDGETSIZE_MAX)
1410 extra->topextra->window->setMaximumSize(QSize(extra->maxw, extra->maxh));
1411 if (extra->topextra->opacity != 255 && q->isWindow())
1412 extra->topextra->window->setOpacity(qreal(extra->topextra->opacity) / qreal(255));
1413
1414 const bool isTipLabel = q->inherits("QTipLabel");
1415 const bool isAlphaWidget = !isTipLabel && q->inherits("QAlphaWidget");
1416#ifdef Q_OS_WIN
1417 // Pass on native parent handle for Widget embedded into Active X.
1418 const QVariant activeXNativeParentHandle = q->property(activeXNativeParentHandleProperty);
1419 if (activeXNativeParentHandle.isValid())
1420 extra->topextra->window->setProperty(activeXNativeParentHandleProperty, activeXNativeParentHandle);
1421 if (isTipLabel || isAlphaWidget)
1422 extra->topextra->window->setProperty("_q_windowsDropShadow", QVariant(true));
1423#endif
1424 if (isTipLabel || isAlphaWidget || q->inherits("QRollEffect"))
1425 qt_window_private(extra->topextra->window)->setAutomaticPositionAndResizeEnabled(false);
1426
1428 }
1429
1430}
1431
1440{
1441 Q_D(QWidget);
1442 d->data.in_destructor = true;
1443
1444#if defined (QT_CHECK_STATE)
1446 qWarning("QWidget: %s (%s) deleted while being painted", className(), name());
1447#endif
1448
1449#ifndef QT_NO_GESTURES
1451 // \forall Qt::GestureType type : ungrabGesture(type) (inlined)
1452 for (auto it = d->gestureContext.keyBegin(), end = d->gestureContext.keyEnd(); it != end; ++it)
1453 manager->cleanupCachedGestures(this, *it);
1454 }
1455 d->gestureContext.clear();
1456#endif
1457
1458#ifndef QT_NO_ACTION
1459 // remove all actions from this widget
1460 for (auto action : std::as_const(d->actions)) {
1461 QActionPrivate *apriv = action->d_func();
1462 apriv->associatedObjects.removeAll(this);
1463 }
1464 d->actions.clear();
1465#endif
1466
1467#ifndef QT_NO_SHORTCUT
1468 // Remove all shortcuts grabbed by this
1469 // widget, unless application is closing
1471 QGuiApplicationPrivate::instance()->shortcutMap.removeShortcut(0, this, QKeySequence());
1472#endif
1473
1474 // delete layout while we still are a valid widget
1475 delete d->layout;
1476 d->layout = nullptr;
1477
1478 // Remove this from focus list
1480
1481 QT_TRY {
1482#if QT_CONFIG(graphicsview)
1483 const QWidget* w = this;
1484 while (w->d_func()->extra && w->d_func()->extra->focus_proxy)
1485 w = w->d_func()->extra->focus_proxy;
1486 QWidget *window = w->window();
1487 QWExtra *e = window ? window->d_func()->extra.get() : nullptr ;
1488 if (!e || !e->proxyWidget || (w->parentWidget() && w->parentWidget()->d_func()->focus_child == this))
1489#endif
1490 clearFocus();
1491 } QT_CATCH(...) {
1492 // swallow this problem because we are in a destructor
1493 }
1494
1495 d->setDirtyOpaqueRegion();
1496
1497 if (isWindow() && isVisible() && internalWinId()) {
1498 QT_TRY {
1499 d->close();
1500 } QT_CATCH(...) {
1501 // if we're out of memory, at least hide the window.
1502 QT_TRY {
1503 hide();
1504 } QT_CATCH(...) {
1505 // and if that also doesn't work, then give up
1506 }
1507 }
1508 } else if (isVisible()) {
1509 qApp->d_func()->sendSyntheticEnterLeave(this);
1510 }
1511
1512 if (QWidgetRepaintManager *repaintManager = d->maybeRepaintManager()) {
1513 repaintManager->removeDirtyWidget(this);
1515 repaintManager->removeStaticWidget(this);
1516 }
1517
1518 delete d->needsFlush;
1519 d->needsFlush = nullptr;
1520
1521 // The next 20 lines are duplicated from QObject, but required here
1522 // since QWidget deletes is children itself
1523 bool blocked = d->blockSig;
1524 d->blockSig = 0; // unblock signals so we always emit destroyed()
1525
1526 if (d->isSignalConnected(0)) {
1527 QT_TRY {
1528 emit destroyed(this);
1529 } QT_CATCH(...) {
1530 // all the signal/slots connections are still in place - if we don't
1531 // quit now, we will crash pretty soon.
1532 qWarning("Detected an unexpected exception in ~QWidget while emitting destroyed().");
1533 QT_RETHROW;
1534 }
1535 }
1536
1537 if (d->declarativeData) {
1538 d->wasDeleted = true; // needed, so that destroying the declarative data does the right thing
1540 QAbstractDeclarativeData::destroyed(d->declarativeData, this);
1541 d->declarativeData = nullptr; // don't activate again in ~QObject
1542 d->wasDeleted = false;
1543 }
1544
1545 d->blockSig = blocked;
1546
1547 if (!d->children.isEmpty())
1548 d->deleteChildren();
1549
1551
1552 QT_TRY {
1553 destroy(); // platform-dependent cleanup
1554 } QT_CATCH(...) {
1555 // if this fails we can't do anything about it but at least we are not allowed to throw.
1556 }
1558
1559 if (QWidgetPrivate::allWidgets) // might have been deleted by ~QApplication
1560 QWidgetPrivate::allWidgets->remove(this);
1561
1562 QT_TRY {
1565 } QT_CATCH(const std::exception&) {
1566 // if this fails we can't do anything about it but at least we are not allowed to throw.
1567 }
1568
1569#if QT_CONFIG(graphicseffect)
1570 delete d->graphicsEffect;
1571#endif
1572
1573 d->isWidget = false;
1574}
1575
1576int QWidgetPrivate::instanceCounter = 0; // Current number of widget instances
1577int QWidgetPrivate::maxInstances = 0; // Maximum number of widget instances
1578
1579void QWidgetPrivate::setWinId(WId id) // set widget identifier
1580{
1581 Q_Q(QWidget);
1582 if (mapper && data.winid) {
1583 mapper->remove(data.winid);
1584 }
1585
1586 const WId oldWinId = data.winid;
1587
1588 data.winid = id;
1589 if (mapper && id) {
1590 mapper->insert(data.winid, q);
1591 }
1592
1593 if (oldWinId != id) {
1596 }
1597}
1598
1600{
1601 if (!extra)
1602 createExtra();
1603 if (!extra->topextra) {
1604 extra->topextra = std::make_unique<QTLWExtra>();
1605 QTLWExtra* x = extra->topextra.get();
1606 x->backingStore = nullptr;
1607 x->sharedPainter = nullptr;
1608 x->incw = x->inch = 0;
1609 x->basew = x->baseh = 0;
1610 x->frameStrut.setCoords(0, 0, 0, 0);
1611 x->normalGeometry = QRect(0,0,-1,-1);
1612 x->savedFlags = { };
1613 x->opacity = 255;
1614 x->posIncludesFrame = 0;
1615 x->sizeAdjusted = false;
1616 x->embedded = 0;
1617 x->window = nullptr;
1618 x->initialScreen = nullptr;
1619
1620#ifdef QWIDGET_EXTRA_DEBUG
1621 static int count = 0;
1622 qDebug() << "tlextra" << ++count;
1623#endif
1624 }
1625}
1626
1633{
1634 if (!extra) { // if not exists
1635 extra = std::make_unique<QWExtra>();
1636 extra->glContext = nullptr;
1637#if QT_CONFIG(graphicsview)
1638 extra->proxyWidget = nullptr;
1639#endif
1640 extra->minw = 0;
1641 extra->minh = 0;
1642 extra->maxw = QWIDGETSIZE_MAX;
1643 extra->maxh = QWIDGETSIZE_MAX;
1644 extra->customDpiX = 0;
1645 extra->customDpiY = 0;
1646 extra->explicitMinSize = 0;
1647 extra->explicitMaxSize = 0;
1648 extra->autoFillBackground = 0;
1649 extra->nativeChildrenForced = 0;
1650 extra->inRenderWithPainter = 0;
1651 extra->hasWindowContainer = false;
1652 extra->hasMask = 0;
1654#ifdef QWIDGET_EXTRA_DEBUG
1655 static int count = 0;
1656 qDebug() << "extra" << ++count;
1657#endif
1658 }
1659}
1660
1664
1671{
1672 if (extra) { // if exists
1674#ifndef QT_NO_STYLE_STYLESHEET
1675 // dereference the stylesheet style
1677 proxy->deref();
1678#endif
1679 if (extra->topextra)
1681
1682 // extra->xic destroyed in QWidget::destroy()
1683 extra.reset();
1684 }
1685}
1686
1690
1692{
1693 if (extra && extra->topextra) {
1694 delete extra->topextra->window;
1695 extra->topextra->window = nullptr;
1696 }
1697}
1698
1699/*
1700 Returns \c region of widgets above this which overlap with
1701 \a rect, which is in parent's coordinate system (same as crect).
1702*/
1703
1704QRegion QWidgetPrivate::overlappedRegion(const QRect &rect, bool breakAfterFirst) const
1705{
1706 Q_Q(const QWidget);
1707
1708 const QWidget *w = q;
1709 QRect r = rect;
1710 QPoint p;
1711 QRegion region;
1712 while (w) {
1713 if (w->isWindow())
1714 break;
1715 QWidgetPrivate *pd = w->parentWidget()->d_func();
1716 bool above = false;
1717 for (int i = 0; i < pd->children.size(); ++i) {
1718 QWidget *sibling = qobject_cast<QWidget *>(pd->children.at(i));
1719 if (!sibling || !sibling->isVisible() || sibling->isWindow())
1720 continue;
1721 if (!above) {
1722 above = (sibling == w);
1723 continue;
1724 }
1725
1726 const QRect siblingRect = sibling->d_func()->effectiveRectFor(sibling->data->crect);
1727 if (qRectIntersects(siblingRect, r)) {
1728 const auto &siblingExtra = sibling->d_func()->extra;
1729 if (siblingExtra && siblingExtra->hasMask && !sibling->d_func()->graphicsEffect
1730 && !siblingExtra->mask.translated(sibling->data->crect.topLeft()).intersects(r)) {
1731 continue;
1732 }
1733 region += siblingRect.translated(-p);
1734 if (breakAfterFirst)
1735 break;
1736 }
1737 }
1738 w = w->parentWidget();
1739 r.translate(pd->data.crect.topLeft());
1740 p += pd->data.crect.topLeft();
1741 }
1742 return region;
1743}
1744
1746{
1747 if (shouldPaintOnScreen()) {
1749 dirty = QRegion();
1750 } else if (QWidgetRepaintManager *repaintManager = maybeRepaintManager()) {
1751 repaintManager->sync();
1752 }
1753}
1754
1756{
1757 if (shouldPaintOnScreen())
1758 paintOnScreen(region);
1759 else if (QWidgetRepaintManager *repaintManager = maybeRepaintManager()) {
1760 repaintManager->sync(q_func(), region);
1761 }
1762}
1763
1765{
1766 if (data.in_destructor)
1767 return;
1768
1770 return;
1771
1772 Q_Q(QWidget);
1773 if (q->testAttribute(Qt::WA_StaticContents)) {
1774 if (!extra)
1775 createExtra();
1776 extra->staticContentsSize = data.crect.size();
1777 }
1778
1779 QPaintEngine *engine = q->paintEngine();
1780
1781 // QGLWidget does not support partial updates if:
1782 // 1) The context is double buffered
1783 // 2) The context is single buffered and auto-fill background is enabled.
1784 const bool noPartialUpdateSupport = (engine && (engine->type() == QPaintEngine::OpenGL
1785 || engine->type() == QPaintEngine::OpenGL2))
1786 && (usesDoubleBufferedGLContext || q->autoFillBackground());
1787 QRegion toBePainted(noPartialUpdateSupport ? q->rect() : rgn);
1788
1789 toBePainted &= clipRect();
1790 clipToEffectiveMask(toBePainted);
1791 if (toBePainted.isEmpty())
1792 return; // Nothing to repaint.
1793
1795
1796 if (Q_UNLIKELY(q->paintingActive()))
1797 qWarning("QWidget::repaint: It is dangerous to leave painters active on a widget outside of the PaintEvent");
1798}
1799
1801{
1802 Q_Q(QWidget);
1803
1804 if (enable && !q->isWindow() && q->parentWidget() && !q->parentWidget()->updatesEnabled())
1805 return; // nothing we can do
1806
1807 if (enable != q->testAttribute(Qt::WA_UpdatesDisabled))
1808 return; // nothing to do
1809
1810 q->setAttribute(Qt::WA_UpdatesDisabled, !enable);
1811 if (enable)
1812 q->update();
1813
1815 for (int i = 0; i < children.size(); ++i) {
1817 if (w && !w->isWindow() && !w->testAttribute(attribute))
1818 w->d_func()->setUpdatesEnabled_helper(enable);
1819 }
1820}
1821
1830{
1831 Q_Q(QWidget);
1832 // Propagate a new inherited mask to all children.
1833#if QT_CONFIG(graphicsview)
1834 if (!q->parentWidget() && extra && extra->proxyWidget) {
1835 QGraphicsProxyWidget *p = extra->proxyWidget;
1836 inheritedPaletteResolveMask = p->d_func()->inheritedPaletteResolveMask | p->palette().resolveMask();
1837 } else
1838#endif // QT_CONFIG(graphicsview)
1839 if (q->isWindow() && !q->testAttribute(Qt::WA_WindowPropagation)) {
1841 }
1842
1843 directPaletteResolveMask = data.pal.resolveMask();
1845
1846 const bool useStyleSheetPropagationInWidgetStyles =
1848
1851 for (int i = 0; i < children.size(); ++i) {
1853 if (w && (!w->testAttribute(Qt::WA_StyleSheet) || useStyleSheetPropagationInWidgetStyles)
1854 && (!w->isWindow() || w->testAttribute(Qt::WA_WindowPropagation))) {
1855 QWidgetPrivate *wd = w->d_func();
1857 wd->resolvePalette();
1858 }
1859 }
1860}
1861
1862/*
1863 Returns the widget's clipping rectangle.
1864*/
1866{
1867 Q_Q(const QWidget);
1868 const QWidget * w = q;
1869 if (!w->isVisible())
1870 return QRect();
1871 QRect r = effectiveRectFor(q->rect());
1872 int ox = 0;
1873 int oy = 0;
1874 while (w
1875 && w->isVisible()
1876 && !w->isWindow()
1877 && w->parentWidget()) {
1878 ox -= w->x();
1879 oy -= w->y();
1880 w = w->parentWidget();
1881 r &= QRect(ox, oy, w->width(), w->height());
1882 }
1883 return r;
1884}
1885
1886/*
1887 Returns the widget's clipping region (without siblings).
1888*/
1890{
1891 Q_Q(const QWidget);
1892 if (!q->isVisible())
1893 return QRegion();
1894 QRegion r(q->rect());
1895 const QWidget * w = q;
1896 const QWidget *ignoreUpTo;
1897 int ox = 0;
1898 int oy = 0;
1899 while (w
1900 && w->isVisible()
1901 && !w->isWindow()
1902 && w->parentWidget()) {
1903 ox -= w->x();
1904 oy -= w->y();
1905 ignoreUpTo = w;
1906 w = w->parentWidget();
1907 r &= QRegion(ox, oy, w->width(), w->height());
1908
1909 int i = 0;
1910 while(w->d_func()->children.at(i++) != static_cast<const QObject *>(ignoreUpTo))
1911 ;
1912 for ( ; i < w->d_func()->children.size(); ++i) {
1913 if (QWidget *sibling = qobject_cast<QWidget *>(w->d_func()->children.at(i))) {
1914 if (sibling->isVisible() && !sibling->isWindow()) {
1915 QRect siblingRect(ox+sibling->x(), oy+sibling->y(),
1916 sibling->width(), sibling->height());
1917 if (qRectIntersects(siblingRect, q->rect()))
1918 r -= QRegion(siblingRect);
1919 }
1920 }
1921 }
1922 }
1923 return r;
1924}
1925
1926void QWidgetPrivate::setSystemClip(QPaintEngine *paintEngine, qreal devicePixelRatio, const QRegion &region)
1927{
1928// Transform the system clip region from device-independent pixels to device pixels
1929 QTransform scaleTransform;
1930 scaleTransform.scale(devicePixelRatio, devicePixelRatio);
1931
1932 paintEngine->d_func()->baseSystemClip = region;
1933 paintEngine->d_func()->setSystemTransform(scaleTransform);
1934
1935}
1936
1937#if QT_CONFIG(graphicseffect)
1938void QWidgetPrivate::invalidateGraphicsEffectsRecursively()
1939{
1940 Q_Q(QWidget);
1941 QWidget *w = q;
1942 do {
1943 if (w->graphicsEffect()) {
1944 QWidgetEffectSourcePrivate *sourced =
1945 static_cast<QWidgetEffectSourcePrivate *>(w->graphicsEffect()->source()->d_func());
1946 if (!sourced->updateDueToGraphicsEffect)
1947 w->graphicsEffect()->source()->d_func()->invalidateCache();
1948 }
1949 w = w->parentWidget();
1950 } while (w);
1951}
1952#endif // QT_CONFIG(graphicseffect)
1953
1955{
1956 Q_Q(QWidget);
1957
1958 dirtyOpaqueChildren = true;
1959
1960#if QT_CONFIG(graphicseffect)
1961 invalidateGraphicsEffectsRecursively();
1962#endif // QT_CONFIG(graphicseffect)
1963
1964 if (q->isWindow())
1965 return;
1966
1967 QWidget *parent = q->parentWidget();
1968 if (!parent)
1969 return;
1970
1971 // TODO: instead of setting dirtyflag, manipulate the dirtyregion directly?
1972 QWidgetPrivate *pd = parent->d_func();
1973 if (!pd->dirtyOpaqueChildren)
1975}
1976
1978{
1980 return opaqueChildren;
1981
1982 QWidgetPrivate *that = const_cast<QWidgetPrivate*>(this);
1983 that->opaqueChildren = QRegion();
1984
1985 for (int i = 0; i < children.size(); ++i) {
1987 if (!child || !child->isVisible() || child->isWindow())
1988 continue;
1989
1990 const QPoint offset = child->geometry().topLeft();
1991 QWidgetPrivate *childd = child->d_func();
1992 QRegion r = childd->isOpaque ? child->rect() : childd->getOpaqueChildren();
1993 if (childd->extra && childd->extra->hasMask)
1994 r &= childd->extra->mask;
1995 if (r.isEmpty())
1996 continue;
1997 r.translate(offset);
1998 that->opaqueChildren += r;
1999 }
2000
2001 that->opaqueChildren &= q_func()->rect();
2002 that->dirtyOpaqueChildren = false;
2003
2004 return that->opaqueChildren;
2005}
2006
2008{
2009 if (children.isEmpty() || clipRect.isEmpty())
2010 return;
2011
2012 const QRegion &r = getOpaqueChildren();
2013 if (!r.isEmpty())
2014 source -= (r & clipRect);
2015}
2016
2017//subtract any relatives that are higher up than me --- this is too expensive !!!
2018void QWidgetPrivate::subtractOpaqueSiblings(QRegion &sourceRegion, bool *hasDirtySiblingsAbove,
2019 bool alsoNonOpaque) const
2020{
2021 Q_Q(const QWidget);
2022 static int disableSubtractOpaqueSiblings = qEnvironmentVariableIntValue("QT_NO_SUBTRACTOPAQUESIBLINGS");
2023 if (disableSubtractOpaqueSiblings || q->isWindow())
2024 return;
2025
2026 QRect clipBoundingRect;
2027 bool dirtyClipBoundingRect = true;
2028
2029 QRegion parentClip;
2030 bool dirtyParentClip = true;
2031
2032 QPoint parentOffset = data.crect.topLeft();
2033
2034 const QWidget *w = q;
2035
2036 while (w) {
2037 if (w->isWindow())
2038 break;
2039 QWidgetPrivate *pd = w->parentWidget()->d_func();
2040 const int myIndex = pd->children.indexOf(const_cast<QWidget *>(w));
2041 const QRect widgetGeometry = w->d_func()->effectiveRectFor(w->data->crect);
2042 for (int i = myIndex + 1; i < pd->children.size(); ++i) {
2043 QWidget *sibling = qobject_cast<QWidget *>(pd->children.at(i));
2044 if (!sibling || !sibling->isVisible() || sibling->isWindow())
2045 continue;
2046
2047 const QRect siblingGeometry = sibling->d_func()->effectiveRectFor(sibling->data->crect);
2048 if (!qRectIntersects(siblingGeometry, widgetGeometry))
2049 continue;
2050
2051 if (dirtyClipBoundingRect) {
2052 clipBoundingRect = sourceRegion.boundingRect();
2053 dirtyClipBoundingRect = false;
2054 }
2055
2056 if (!qRectIntersects(siblingGeometry, clipBoundingRect.translated(parentOffset)))
2057 continue;
2058
2059 if (dirtyParentClip) {
2060 parentClip = sourceRegion.translated(parentOffset);
2061 dirtyParentClip = false;
2062 }
2063
2064 const QPoint siblingPos(sibling->data->crect.topLeft());
2065 const QRect siblingClipRect(sibling->d_func()->clipRect());
2066 QRegion siblingDirty(parentClip);
2067 siblingDirty &= (siblingClipRect.translated(siblingPos));
2068 const bool hasMask = sibling->d_func()->extra && sibling->d_func()->extra->hasMask
2069 && !sibling->d_func()->graphicsEffect;
2070 if (hasMask)
2071 siblingDirty &= sibling->d_func()->extra->mask.translated(siblingPos);
2072 if (siblingDirty.isEmpty())
2073 continue;
2074
2075 if (sibling->d_func()->isOpaque || alsoNonOpaque) {
2076 if (hasMask) {
2077 siblingDirty.translate(-parentOffset);
2078 sourceRegion -= siblingDirty;
2079 } else {
2080 sourceRegion -= siblingGeometry.translated(-parentOffset);
2081 }
2082 } else {
2083 if (hasDirtySiblingsAbove)
2084 *hasDirtySiblingsAbove = true;
2085 if (sibling->d_func()->children.isEmpty())
2086 continue;
2087 QRegion opaqueSiblingChildren(sibling->d_func()->getOpaqueChildren());
2088 opaqueSiblingChildren.translate(-parentOffset + siblingPos);
2089 sourceRegion -= opaqueSiblingChildren;
2090 }
2091 if (sourceRegion.isEmpty())
2092 return;
2093
2094 dirtyClipBoundingRect = true;
2095 dirtyParentClip = true;
2096 }
2097
2098 w = w->parentWidget();
2099 parentOffset += pd->data.crect.topLeft();
2100 dirtyParentClip = true;
2101 }
2102}
2103
2105{
2106 Q_Q(const QWidget);
2107
2108 const QWidget *w = q;
2109 QPoint offset;
2110
2111#if QT_CONFIG(graphicseffect)
2112 if (graphicsEffect) {
2113 w = q->parentWidget();
2114 offset -= data.crect.topLeft();
2115 }
2116#endif // QT_CONFIG(graphicseffect)
2117
2118 while (w) {
2119 const QWidgetPrivate *wd = w->d_func();
2120 if (wd->extra && wd->extra->hasMask)
2121 region &= (w != q) ? wd->extra->mask.translated(offset) : wd->extra->mask;
2122 if (w->isWindow())
2123 return;
2124 offset -= wd->data.crect.topLeft();
2125 w = w->parentWidget();
2126 }
2127}
2128
2130{
2131#if defined(QT_NO_BACKINGSTORE)
2132 return true;
2133#else
2134 Q_Q(const QWidget);
2135 if (q->testAttribute(Qt::WA_PaintOnScreen)
2136 || (!q->isWindow() && q->window()->testAttribute(Qt::WA_PaintOnScreen))) {
2137 return true;
2138 }
2139
2140 return false;
2141#endif
2142}
2143
2145{
2146 // hw: todo: only needed if opacity actually changed
2148
2149#if QT_CONFIG(graphicseffect)
2150 if (graphicsEffect) {
2151 // ### We should probably add QGraphicsEffect::isOpaque at some point.
2152 setOpaque(false);
2153 return;
2154 }
2155#endif // QT_CONFIG(graphicseffect)
2156
2157 Q_Q(QWidget);
2158 if (q->testAttribute(Qt::WA_OpaquePaintEvent) || q->testAttribute(Qt::WA_PaintOnScreen)) {
2159 setOpaque(true);
2160 return;
2161 }
2162
2163 const QPalette &pal = q->palette();
2164
2165 if (q->autoFillBackground()) {
2166 const QBrush &autoFillBrush = pal.brush(q->backgroundRole());
2167 if (autoFillBrush.style() != Qt::NoBrush && autoFillBrush.isOpaque()) {
2168 setOpaque(true);
2169 return;
2170 }
2171 }
2172
2173 if (q->isWindow() && !q->testAttribute(Qt::WA_NoSystemBackground)) {
2174 const QBrush &windowBrush = q->palette().brush(QPalette::Window);
2175 if (windowBrush.style() != Qt::NoBrush && windowBrush.isOpaque()) {
2176 setOpaque(true);
2177 return;
2178 }
2179 }
2180 setOpaque(false);
2181}
2182
2184{
2185 if (isOpaque != opaque) {
2186 isOpaque = opaque;
2188 }
2189}
2190
2192{
2193 Q_Q(QWidget);
2194 if (QWindow *window = q->windowHandle()) {
2195 QSurfaceFormat format = window->format();
2196 const int oldAlpha = format.alphaBufferSize();
2197 const int newAlpha = q->testAttribute(Qt::WA_TranslucentBackground) ? 8 : -1;
2198 if (oldAlpha != newAlpha) {
2199 // QTBUG-85714: Do this only when the QWindow has not yet been create()'ed yet.
2200 //
2201 // If that is not the case, then the setFormat() is not just futile
2202 // but downright dangerous. Futile because the format matters only
2203 // when creating the native window, no point in changing it
2204 // afterwards. Dangerous because a QOpenGLContext or something else
2205 // may eventually query the QWindow's format(), in order to ensure
2206 // compatibility (in terms of native concepts such as pixel format,
2207 // EGLConfig, etc.), and if we change it here, then the returned
2208 // format does not describe reality anymore. (reality being the
2209 // settings with which the native resource was created).
2210 //
2211 // Whereas if one does a destroy()-create() then this all here
2212 // won't matter because the format is updated in
2213 // QWidgetPrivate::create() again.
2214 //
2215 if (!window->handle()) {
2216 format.setAlphaBufferSize(newAlpha);
2217 window->setFormat(format);
2218 }
2219 }
2220 }
2221}
2222
2223static inline void fillRegion(QPainter *painter, const QRegion &rgn, const QBrush &brush)
2224{
2226
2227 if (brush.style() == Qt::TexturePattern) {
2228 const QRect rect(rgn.boundingRect());
2229 painter->setClipRegion(rgn);
2230 painter->drawTiledPixmap(rect, brush.texture(), rect.topLeft());
2231 } else if (brush.gradient()
2232 && (brush.gradient()->coordinateMode() == QGradient::ObjectBoundingMode
2233 || brush.gradient()->coordinateMode() == QGradient::ObjectMode)) {
2234 painter->save();
2235 painter->setClipRegion(rgn);
2237 painter->restore();
2238 } else {
2239 for (const QRect &rect : rgn)
2241 }
2242}
2243
2245{
2246#if QT_CONFIG(scrollarea)
2247 Q_Q(const QWidget);
2248 //If we are painting the viewport of a scrollarea, we must apply an offset to the brush in case we are drawing a texture
2249 if (brush.style() == Qt::NoBrush || brush.style() == Qt::SolidPattern)
2250 return false;
2251 QAbstractScrollArea *scrollArea = qobject_cast<QAbstractScrollArea *>(parent);
2252 if (scrollArea && scrollArea->viewport() == q) {
2253 QObjectData *scrollPrivate = static_cast<QWidget *>(scrollArea)->d_ptr.data();
2254 QAbstractScrollAreaPrivate *priv = static_cast<QAbstractScrollAreaPrivate *>(scrollPrivate);
2255 painter->setBrushOrigin(-priv->contentsOffset());
2256 }
2257#endif // QT_CONFIG(scrollarea)
2258 return true;
2259}
2260
2261void QWidgetPrivate::paintBackground(QPainter *painter, const QRegion &rgn, DrawWidgetFlags flags) const
2262{
2263 Q_Q(const QWidget);
2264
2265 bool brushOriginSet = false;
2266 const QBrush autoFillBrush = q->palette().brush(q->backgroundRole());
2267
2268 if ((flags & DrawAsRoot) && !(q->autoFillBackground() && autoFillBrush.isOpaque())) {
2269 const QBrush bg = q->palette().brush(QPalette::Window);
2270 if (!brushOriginSet)
2271 brushOriginSet = updateBrushOrigin(painter, bg);
2272 if (!(flags & DontSetCompositionMode)) {
2273 //copy alpha straight in
2276 fillRegion(painter, rgn, bg);
2277 painter->setCompositionMode(oldMode);
2278 } else {
2279 fillRegion(painter, rgn, bg);
2280 }
2281 }
2282
2283 if (q->autoFillBackground()) {
2284 if (!brushOriginSet)
2285 brushOriginSet = updateBrushOrigin(painter, autoFillBrush);
2286 fillRegion(painter, rgn, autoFillBrush);
2287 }
2288
2289 if (q->testAttribute(Qt::WA_StyledBackground)) {
2290 painter->setClipRegion(rgn);
2292 opt.initFrom(q);
2293 q->style()->drawPrimitive(QStyle::PE_Widget, &opt, painter, q);
2294 }
2295}
2296
2297/*
2298 \internal
2299 This function is called when a widget is hidden or destroyed.
2300 It resets some application global pointers that should only refer active,
2301 visible widgets.
2302*/
2303
2304extern QWidget *qt_button_down;
2305
2307{
2308 Q_Q(QWidget);
2309 // If this was the active application window, reset it
2312 // If the is the active mouse press widget, reset it
2313 if (q == qt_button_down)
2314 qt_button_down = nullptr;
2315}
2316
2317
2328{
2329 return QWidgetPrivate::mapper ? QWidgetPrivate::mapper->value(id, 0) : nullptr;
2330}
2331
2332
2333
2358{
2359 if (!data->in_destructor
2361 {
2362 QWidget *that = const_cast<QWidget*>(this);
2364 that->d_func()->createWinId();
2365 return that->data->winid;
2366 }
2367 return data->winid;
2368}
2369
2371{
2372 Q_Q(QWidget);
2373
2374 const bool forceNativeWindow = q->testAttribute(Qt::WA_NativeWindow);
2375 if (!q->testAttribute(Qt::WA_WState_Created) || (forceNativeWindow && !q->internalWinId())) {
2376 if (!q->isWindow()) {
2377 QWidget *parent = q->parentWidget();
2378 QWidgetPrivate *pd = parent->d_func();
2379 if (forceNativeWindow && !q->testAttribute(Qt::WA_DontCreateNativeAncestors))
2380 parent->setAttribute(Qt::WA_NativeWindow);
2381 if (!parent->internalWinId()) {
2382 pd->createWinId();
2383 }
2384
2385 for (int i = 0; i < pd->children.size(); ++i) {
2387 if (w && !w->isWindow() && (!w->testAttribute(Qt::WA_WState_Created)
2388 || (!w->internalWinId() && w->testAttribute(Qt::WA_NativeWindow)))) {
2389 w->create();
2390 }
2391 }
2392 } else {
2393 q->create();
2394 }
2395 }
2396}
2397
2406{
2407 Q_Q(QWidget);
2408 if (!q->isWindow())
2409 return false;
2410 // Find the screen for pos and make the widget understand it is on that screen.
2412}
2413
2421{
2422 Q_Q(QWidget);
2423 if (!screen || !q->isWindow())
2424 return false;
2425 const QScreen *currentScreen = windowHandle() ? windowHandle()->screen() : nullptr;
2426 if (currentScreen != screen) {
2428 if (windowHandle())
2429 windowHandle()->setScreen(screen);
2430 return true;
2431 }
2432 return false;
2433}
2434
2442{
2443 Q_D(QWidget);
2444 d->createWinId();
2445}
2446
2463{
2464 const WId id = internalWinId();
2466 return id;
2467 if (const QWidget *realParent = nativeParentWidget())
2468 return realParent->internalWinId();
2469 return 0;
2470}
2471
2484{
2485 Q_D(const QWidget);
2486 return d->windowHandle();
2487}
2488
2497{
2498 Q_D(const QWidget);
2499 if (auto associatedScreen = d->associatedScreen())
2500 return associatedScreen;
2501 if (auto topLevel = window()) {
2502 if (auto topData = qt_widget_private(topLevel)->topData()) {
2503 if (topData->initialScreen)
2504 return topData->initialScreen;
2505 }
2506 if (auto screenByPos = QGuiApplication::screenAt(topLevel->geometry().center()))
2507 return screenByPos;
2508 }
2510}
2511
2525{
2526 Q_D(QWidget);
2527 d->setScreen(screen);
2528}
2529
2530#ifndef QT_NO_STYLE_STYLESHEET
2531
2548{
2549 Q_D(const QWidget);
2550 if (!d->extra)
2551 return QString();
2552 return d->extra->styleSheet;
2553}
2554
2555void QWidget::setStyleSheet(const QString& styleSheet)
2556{
2557 Q_D(QWidget);
2558 if (data->in_destructor)
2559 return;
2560 d->createExtra();
2561
2562 QStyleSheetStyle *proxy = qt_styleSheet(d->extra->style);
2563 d->extra->styleSheet = styleSheet;
2564 if (styleSheet.isEmpty()) { // stylesheet removed
2565 if (!proxy)
2566 return;
2567
2568 d->inheritStyle();
2569 return;
2570 }
2571
2572 if (proxy) { // style sheet update
2573 bool repolish = d->polished;
2574 if (!repolish) {
2575 const auto childWidgets = findChildren<QWidget*>();
2576 for (auto child : childWidgets) {
2577 repolish = child->d_func()->polished;
2578 if (repolish)
2579 break;
2580 }
2581 }
2582 if (repolish)
2583 proxy->repolish(this);
2584 return;
2585 }
2586
2588 d->setStyle_helper(new QStyleSheetStyle(d->extra->style), true);
2589 } else {
2590 d->setStyle_helper(new QStyleSheetStyle(nullptr), true);
2591 }
2592}
2593
2594#endif // QT_NO_STYLE_STYLESHEET
2595
2601{
2602 Q_D(const QWidget);
2603
2604 if (d->extra && d->extra->style)
2605 return d->extra->style;
2606 return QApplication::style();
2607}
2608
2631{
2632 Q_D(QWidget);
2633 setAttribute(Qt::WA_SetStyle, style != nullptr);
2634 d->createExtra();
2635#ifndef QT_NO_STYLE_STYLESHEET
2636 if (QStyleSheetStyle *styleSheetStyle = qt_styleSheet(style)) {
2637 //if for some reason someone try to set a QStyleSheetStyle, ref it
2638 //(this may happen for example in QButtonDialogBox which propagates its style)
2639 styleSheetStyle->ref();
2640 d->setStyle_helper(style, false);
2641 } else if (qt_styleSheet(d->extra->style) || !qApp->styleSheet().isEmpty()) {
2642 // if we have an application stylesheet or have a proxy already, propagate
2643 d->setStyle_helper(new QStyleSheetStyle(style), true);
2644 } else
2645#endif
2646 d->setStyle_helper(style, false);
2647}
2648
2649void QWidgetPrivate::setStyle_helper(QStyle *newStyle, bool propagate)
2650{
2651 Q_Q(QWidget);
2652 QStyle *oldStyle = q->style();
2653
2654 createExtra();
2655
2656#ifndef QT_NO_STYLE_STYLESHEET
2657 QPointer<QStyle> origStyle = extra->style;
2658#endif
2659 extra->style = newStyle;
2660
2661 // repolish
2662 if (polished && q->windowType() != Qt::Desktop) {
2663 oldStyle->unpolish(q);
2664 q->style()->polish(q);
2665 }
2666
2667 if (propagate) {
2668 // We copy the list because the order may be modified
2669 const QObjectList childrenList = children;
2670 for (int i = 0; i < childrenList.size(); ++i) {
2671 QWidget *c = qobject_cast<QWidget*>(childrenList.at(i));
2672 if (c)
2673 c->d_func()->inheritStyle();
2674 }
2675 }
2676
2677#ifndef QT_NO_STYLE_STYLESHEET
2678 if (!qt_styleSheet(newStyle)) {
2679 if (const QStyleSheetStyle* cssStyle = qt_styleSheet(origStyle)) {
2680 cssStyle->clearWidgetFont(q);
2681 }
2682 }
2683#endif
2684
2687
2688#ifndef QT_NO_STYLE_STYLESHEET
2689 // dereference the old stylesheet style
2690 if (QStyleSheetStyle *proxy = qt_styleSheet(origStyle))
2691 proxy->deref();
2692#endif
2693}
2694
2695// Inherits style from the current parent and propagates it as necessary
2697{
2698#ifndef QT_NO_STYLE_STYLESHEET
2699 Q_Q(QWidget);
2700
2701 QStyle *extraStyle = extra ? (QStyle*)extra->style : nullptr;
2702
2703 QStyleSheetStyle *proxy = qt_styleSheet(extraStyle);
2704
2705 if (!q->styleSheet().isEmpty()) {
2706 Q_ASSERT(proxy);
2707 proxy->repolish(q);
2708 return;
2709 }
2710
2711 QStyle *origStyle = proxy ? proxy->base : extraStyle;
2712 QWidget *parent = q->parentWidget();
2713 QStyle *parentStyle = (parent && parent->d_func()->extra) ? (QStyle*)parent->d_func()->extra->style : nullptr;
2714 // If we have stylesheet on app or parent has stylesheet style, we need
2715 // to be running a proxy
2716 if (!qApp->styleSheet().isEmpty() || qt_styleSheet(parentStyle)) {
2717 QStyle *newStyle = parentStyle;
2718 if (q->testAttribute(Qt::WA_SetStyle))
2719 newStyle = new QStyleSheetStyle(origStyle);
2720 else if (QStyleSheetStyle *newProxy = qt_styleSheet(parentStyle))
2721 newProxy->ref();
2722
2723 setStyle_helper(newStyle, true);
2724 return;
2725 }
2726
2727 // So, we have no stylesheet on parent/app and we have an empty stylesheet
2728 // we just need our original style back
2729 if (origStyle == extraStyle) // is it any different?
2730 return;
2731
2732 // We could have inherited the proxy from our parent (which has a custom style)
2733 // In such a case we need to start following the application style (i.e revert
2734 // the propagation behavior of QStyleSheetStyle)
2735 if (!q->testAttribute(Qt::WA_SetStyle))
2736 origStyle = nullptr;
2737
2738 setStyle_helper(origStyle, true);
2739#endif // QT_NO_STYLE_STYLESHEET
2740}
2741
2742
2795{
2796 return static_cast<Qt::WindowModality>(data->window_modality);
2797}
2798
2800{
2801 data->window_modality = windowModality;
2802 // setModal_sys() will be called by setAttribute()
2803 setAttribute(Qt::WA_ShowModal, (data->window_modality != Qt::NonModal));
2805}
2806
2808{
2809 Q_Q(QWidget);
2810 if (q->windowHandle())
2811 q->windowHandle()->setModality(q->windowModality());
2812}
2813
2837{ return data->window_state & Qt::WindowMinimized; }
2838
2848{
2849 bool isMin = isMinimized();
2850 if (isMin && isVisible())
2851 return;
2852
2854
2855 if (!isMin)
2857 setVisible(true);
2858}
2859
2877{ return data->window_state & Qt::WindowMaximized; }
2878
2879
2880
2888Qt::WindowStates QWidget::windowState() const
2889{
2890 return Qt::WindowStates(data->window_state);
2891}
2892
2900void QWidget::overrideWindowState(Qt::WindowStates newstate)
2901{
2902 QWindowStateChangeEvent e(Qt::WindowStates(data->window_state), true);
2903 data->window_state = newstate;
2905}
2906
2937void QWidget::setWindowState(Qt::WindowStates newstate)
2938{
2939 Q_D(QWidget);
2940 Qt::WindowStates oldstate = windowState();
2941 if (newstate.testFlag(Qt::WindowMinimized)) // QTBUG-46763
2942 newstate.setFlag(Qt::WindowActive, false);
2943 if (oldstate == newstate)
2944 return;
2946 create();
2947
2948 data->window_state = newstate;
2949 data->in_set_window_state = 1;
2950 if (isWindow()) {
2951 // Ensure the initial size is valid, since we store it as normalGeometry below.
2953 adjustSize();
2954
2955 d->createTLExtra();
2957 d->topData()->normalGeometry = geometry();
2958
2960 windowHandle()->setWindowStates(newstate & ~Qt::WindowActive);
2961 }
2962 data->in_set_window_state = 0;
2963
2964 if (newstate & Qt::WindowActive)
2966
2967 QWindowStateChangeEvent e(oldstate);
2969}
2970
2983{ return data->window_state & Qt::WindowFullScreen; }
2984
3022{
3024
3027 setVisible(true);
3028#if !defined Q_OS_QNX // On QNX this window will be activated anyway from libscreen
3029 // activating it here before libscreen activates it causes problems
3031#endif
3032}
3033
3052
3069
3090bool QWidget::isEnabledTo(const QWidget *ancestor) const
3091{
3092 const QWidget * w = this;
3093 while (!w->testAttribute(Qt::WA_ForceDisabled)
3094 && !w->isWindow()
3095 && w->parentWidget()
3096 && w->parentWidget() != ancestor)
3097 w = w->parentWidget();
3099}
3100
3101#ifndef QT_NO_ACTION
3118{
3119 insertAction(nullptr, action);
3120}
3121
3127void QWidget::addActions(const QList<QAction *> &actions)
3128{
3129 for(int i = 0; i < actions.size(); i++)
3130 insertAction(nullptr, actions.at(i));
3131}
3132
3143{
3144 if (Q_UNLIKELY(!action)) {
3145 qWarning("QWidget::insertAction: Attempt to insert null action");
3146 return;
3147 }
3148
3149 Q_D(QWidget);
3150 if (d->actions.contains(action))
3151 removeAction(action);
3152
3153 int pos = d->actions.indexOf(before);
3154 if (pos < 0) {
3155 before = nullptr;
3156 pos = d->actions.size();
3157 }
3158 d->actions.insert(pos, action);
3159
3160 QActionPrivate *apriv = action->d_func();
3161 apriv->associatedObjects.append(this);
3162
3163 QActionEvent e(QEvent::ActionAdded, action, before);
3165}
3166
3176void QWidget::insertActions(QAction *before, const QList<QAction*> &actions)
3177{
3178 for(int i = 0; i < actions.size(); ++i)
3179 insertAction(before, actions.at(i));
3180}
3181
3187{
3188 if (!action)
3189 return;
3190
3191 Q_D(QWidget);
3192
3193 QActionPrivate *apriv = action->d_func();
3194 apriv->associatedObjects.removeAll(this);
3195
3196 if (d->actions.removeAll(action)) {
3199 }
3200}
3201
3207QList<QAction*> QWidget::actions() const
3208{
3209 Q_D(const QWidget);
3210 return d->actions;
3211}
3212
3230{
3231 QAction *ret = new QAction(text, this);
3232 addAction(ret);
3233 return ret;
3234}
3235
3237{
3238 QAction *ret = new QAction(icon, text, this);
3239 addAction(ret);
3240 return ret;
3241}
3242
3243#if QT_CONFIG(shortcut)
3245{
3247 ret->setShortcut(shortcut);
3248 return ret;
3249}
3250
3252{
3254 ret->setShortcut(shortcut);
3255 return ret;
3256}
3257#endif
3258
3277QAction *QWidget::addAction(const QString &text, const QObject *receiver, const char* member,
3279{
3280 QAction *action = addAction(text);
3281 QObject::connect(action, SIGNAL(triggered(bool)), receiver, member, type);
3282 return action;
3283}
3284
3286 const QObject *receiver, const char* member,
3288{
3289 QAction *action = addAction(icon, text);
3290 QObject::connect(action, SIGNAL(triggered(bool)), receiver, member, type);
3291 return action;
3292}
3293
3294#if QT_CONFIG(shortcut)
3296 const QObject *receiver, const char* member,
3298{
3299 QAction *action = addAction(text, receiver, member, type);
3300 action->setShortcut(shortcut);
3301 return action;
3302}
3303
3305 const QObject *receiver, const char* member,
3307{
3308 QAction *action = addAction(icon, text, receiver, member, type);
3309 action->setShortcut(shortcut);
3310 return action;
3311}
3312#endif // QT_CONFIG(shortcut)
3313
3335#endif // QT_NO_ACTION
3336
3359{
3360 Q_D(QWidget);
3362 d->setEnabled_helper(enable);
3363}
3364
3366{
3367 Q_Q(QWidget);
3368
3369 if (enable && !q->isWindow() && q->parentWidget() && !q->parentWidget()->isEnabled())
3370 return; // nothing we can do
3371
3372 if (enable != q->testAttribute(Qt::WA_Disabled))
3373 return; // nothing to do
3374
3375 q->setAttribute(Qt::WA_Disabled, !enable);
3377
3378 if (!enable && q->window()->focusWidget() == q) {
3379 bool parentIsEnabled = (!q->parentWidget() || q->parentWidget()->isEnabled());
3380 if (!parentIsEnabled || !q->focusNextChild())
3381 q->clearFocus();
3382 }
3383
3385 for (int i = 0; i < children.size(); ++i) {
3387 if (w && !w->testAttribute(attribute))
3388 w->d_func()->setEnabled_helper(enable);
3389 }
3390#ifndef QT_NO_CURSOR
3391 if (q->testAttribute(Qt::WA_SetCursor) || q->isWindow()) {
3392 // enforce the windows behavior of clearing the cursor on
3393 // disabled widgets
3394 qt_qpa_set_cursor(q, false);
3395 }
3396#endif
3397#ifndef QT_NO_IM
3398 if (q->testAttribute(Qt::WA_InputMethodEnabled) && q->hasFocus()) {
3399 QWidget *focusWidget = effectiveFocusWidget();
3400
3401 if (enable) {
3402 if (focusWidget->testAttribute(Qt::WA_InputMethodEnabled))
3404 } else {
3405 QGuiApplication::inputMethod()->commit();
3407 }
3408 }
3409#endif //QT_NO_IM
3412}
3413
3432{
3434}
3435
3437{
3439
3440}
3441
3450void QWidget::setDisabled(bool disable)
3451{
3452 setEnabled(!disable);
3453}
3454
3469{
3470 Q_D(const QWidget);
3471 if (isWindow() && ! (windowType() == Qt::Popup)) {
3472 QRect fs = d->frameStrut();
3473 return QRect(data->crect.x() - fs.left(),
3474 data->crect.y() - fs.top(),
3475 data->crect.width() + fs.left() + fs.right(),
3476 data->crect.height() + fs.top() + fs.bottom());
3477 }
3478 return data->crect;
3479}
3480
3494int QWidget::x() const
3495{
3496 Q_D(const QWidget);
3497 if (isWindow() && ! (windowType() == Qt::Popup))
3498 return data->crect.x() - d->frameStrut().left();
3499 return data->crect.x();
3500}
3501
3514int QWidget::y() const
3515{
3516 Q_D(const QWidget);
3517 if (isWindow() && ! (windowType() == Qt::Popup))
3518 return data->crect.y() - d->frameStrut().top();
3519 return data->crect.y();
3520}
3521
3550{
3551 Q_D(const QWidget);
3552 QPoint result = data->crect.topLeft();
3553 if (isWindow() && ! (windowType() == Qt::Popup))
3554 if (!d->maybeTopData() || !d->maybeTopData()->posIncludesFrame)
3555 result -= d->frameStrut().topLeft();
3556 return result;
3557}
3558
3669{
3670 Q_D(const QWidget);
3671 if (!isWindow())
3672 return QRect();
3673
3674 if (!isMaximized() && !isFullScreen())
3675 return geometry();
3676
3677 return d->topData()->normalGeometry;
3678}
3679
3680
3694{
3695 Q_D(const QWidget);
3696 QRect r(0, 0, 0, 0);
3697 for (int i = 0; i < d->children.size(); ++i) {
3698 QWidget *w = qobject_cast<QWidget *>(d->children.at(i));
3699 if (w && !w->isWindow() && !w->isHidden())
3700 r |= w->geometry();
3701 }
3702 return r;
3703}
3704
3718{
3719 Q_D(const QWidget);
3720 QRegion r;
3721 for (int i = 0; i < d->children.size(); ++i) {
3722 QWidget *w = qobject_cast<QWidget *>(d->children.at(i));
3723 if (w && !w->isWindow() && !w->isHidden()) {
3724 QRegion mask = w->mask();
3725 if (mask.isEmpty())
3726 r |= w->geometry();
3727 else
3728 r |= mask.translated(w->pos());
3729 }
3730 }
3731 return r;
3732}
3733
3734
3753{
3754 Q_D(const QWidget);
3755 return d->extra ? QSize(d->extra->minw, d->extra->minh) : QSize(0, 0);
3756}
3757
3775{
3776 Q_D(const QWidget);
3777 return d->extra ? QSize(d->extra->maxw, d->extra->maxh)
3779}
3780
3781
3854{
3855 Q_D(const QWidget);
3856 return (d->extra && d->extra->topextra)
3857 ? QSize(d->extra->topextra->incw, d->extra->topextra->inch)
3858 : QSize(0, 0);
3859}
3860
3875{
3876 Q_D(const QWidget);
3877 return (d->extra && d->extra->topextra)
3878 ? QSize(d->extra->topextra->basew, d->extra->topextra->baseh)
3879 : QSize(0, 0);
3880}
3881
3883{
3884 Q_Q(QWidget);
3885
3886 int mw = minw, mh = minh;
3887 if (mw == QWIDGETSIZE_MAX)
3888 mw = 0;
3889 if (mh == QWIDGETSIZE_MAX)
3890 mh = 0;
3891 if (Q_UNLIKELY(minw > QWIDGETSIZE_MAX || minh > QWIDGETSIZE_MAX)) {
3892 qWarning("QWidget::setMinimumSize: (%s/%s) "
3893 "The largest allowed size is (%d,%d)",
3894 q->objectName().toLocal8Bit().data(), q->metaObject()->className(), QWIDGETSIZE_MAX,
3896 minw = mw = qMin<int>(minw, QWIDGETSIZE_MAX);
3897 minh = mh = qMin<int>(minh, QWIDGETSIZE_MAX);
3898 }
3899 if (Q_UNLIKELY(minw < 0 || minh < 0)) {
3900 qWarning("QWidget::setMinimumSize: (%s/%s) Negative sizes (%d,%d) "
3901 "are not possible",
3902 q->objectName().toLocal8Bit().data(), q->metaObject()->className(), minw, minh);
3903 minw = mw = qMax(minw, 0);
3904 minh = mh = qMax(minh, 0);
3905 }
3906 createExtra();
3907 if (extra->minw == mw && extra->minh == mh)
3908 return false;
3909 extra->minw = mw;
3910 extra->minh = mh;
3911 extra->explicitMinSize = (mw ? Qt::Horizontal : 0) | (mh ? Qt::Vertical : 0);
3912 return true;
3913}
3914
3916{
3917 Q_Q(QWidget);
3918 if (extra && q->windowHandle()) {
3919 QWindow *win = q->windowHandle();
3921
3922 winp->minimumSize = QSize(extra->minw, extra->minh);
3923 winp->maximumSize = QSize(extra->maxw, extra->maxh);
3924
3925 if (extra->topextra) {
3926 winp->baseSize = QSize(extra->topextra->basew, extra->topextra->baseh);
3927 winp->sizeIncrement = QSize(extra->topextra->incw, extra->topextra->inch);
3928 }
3929
3930 if (winp->platformWindow) {
3932 winp->platformWindow->propagateSizeHints();
3933 }
3934 }
3935}
3936
3945void QWidget::setMinimumSize(int minw, int minh)
3946{
3947 Q_D(QWidget);
3948 if (!d->setMinimumSize_helper(minw, minh))
3949 return;
3950
3951 if (isWindow())
3952 d->setConstraints_sys();
3953 if (minw > width() || minh > height()) {
3954 bool resized = testAttribute(Qt::WA_Resized);
3955 bool maximized = isMaximized();
3956 resize(qMax(minw,width()), qMax(minh,height()));
3957 setAttribute(Qt::WA_Resized, resized); //not a user resize
3958 if (maximized)
3959 data->window_state = data->window_state | Qt::WindowMaximized;
3960 }
3961#if QT_CONFIG(graphicsview)
3962 if (d->extra) {
3963 if (d->extra->proxyWidget)
3964 d->extra->proxyWidget->setMinimumSize(minw, minh);
3965 }
3966#endif
3967 d->updateGeometry_helper(d->extra->minw == d->extra->maxw && d->extra->minh == d->extra->maxh);
3968}
3969
3971{
3972 Q_Q(QWidget);
3973 if (Q_UNLIKELY(maxw > QWIDGETSIZE_MAX || maxh > QWIDGETSIZE_MAX)) {
3974 qWarning("QWidget::setMaximumSize: (%s/%s) "
3975 "The largest allowed size is (%d,%d)",
3976 q->objectName().toLocal8Bit().data(), q->metaObject()->className(), QWIDGETSIZE_MAX,
3978 maxw = qMin<int>(maxw, QWIDGETSIZE_MAX);
3979 maxh = qMin<int>(maxh, QWIDGETSIZE_MAX);
3980 }
3981 if (Q_UNLIKELY(maxw < 0 || maxh < 0)) {
3982 qWarning("QWidget::setMaximumSize: (%s/%s) Negative sizes (%d,%d) "
3983 "are not possible",
3984 q->objectName().toLocal8Bit().data(), q->metaObject()->className(), maxw, maxh);
3985 maxw = qMax(maxw, 0);
3986 maxh = qMax(maxh, 0);
3987 }
3988 createExtra();
3989 if (extra->maxw == maxw && extra->maxh == maxh)
3990 return false;
3991 extra->maxw = maxw;
3992 extra->maxh = maxh;
3993 extra->explicitMaxSize = (maxw != QWIDGETSIZE_MAX ? Qt::Horizontal : 0) |
3994 (maxh != QWIDGETSIZE_MAX ? Qt::Vertical : 0);
3995 return true;
3996}
3997
4005void QWidget::setMaximumSize(int maxw, int maxh)
4006{
4007 Q_D(QWidget);
4008 if (!d->setMaximumSize_helper(maxw, maxh))
4009 return;
4010
4011 if (isWindow())
4012 d->setConstraints_sys();
4013 if (maxw < width() || maxh < height()) {
4014 bool resized = testAttribute(Qt::WA_Resized);
4015 resize(qMin(maxw,width()), qMin(maxh,height()));
4016 setAttribute(Qt::WA_Resized, resized); //not a user resize
4017 }
4018
4019#if QT_CONFIG(graphicsview)
4020 if (d->extra) {
4021 if (d->extra->proxyWidget)
4022 d->extra->proxyWidget->setMaximumSize(maxw, maxh);
4023 }
4024#endif
4025
4026 d->updateGeometry_helper(d->extra->minw == d->extra->maxw && d->extra->minh == d->extra->maxh);
4027}
4028
4036{
4037 Q_D(QWidget);
4038 d->createTLExtra();
4039 QTLWExtra* x = d->topData();
4040 if (x->incw == w && x->inch == h)
4041 return;
4042 x->incw = w;
4043 x->inch = h;
4044 if (isWindow())
4045 d->setConstraints_sys();
4046}
4047
4054void QWidget::setBaseSize(int basew, int baseh)
4055{
4056 Q_D(QWidget);
4057 d->createTLExtra();
4058 QTLWExtra* x = d->topData();
4059 if (x->basew == basew && x->baseh == baseh)
4060 return;
4061 x->basew = basew;
4062 x->baseh = baseh;
4063 if (isWindow())
4064 d->setConstraints_sys();
4065}
4066
4083{
4084 setFixedSize(s.width(), s.height());
4085}
4086
4087
4096{
4097 Q_D(QWidget);
4098 bool minSizeSet = d->setMinimumSize_helper(w, h);
4099 bool maxSizeSet = d->setMaximumSize_helper(w, h);
4100 if (!minSizeSet && !maxSizeSet)
4101 return;
4102
4103 if (isWindow())
4104 d->setConstraints_sys();
4105 else
4106 d->updateGeometry_helper(true);
4107
4108 if (w != QWIDGETSIZE_MAX || h != QWIDGETSIZE_MAX)
4109 resize(w, h);
4110}
4111
4113{
4114 Q_D(QWidget);
4115 d->createExtra();
4116 uint expl = d->extra->explicitMinSize | (w ? Qt::Horizontal : 0);
4118 d->extra->explicitMinSize = expl;
4119}
4120
4122{
4123 Q_D(QWidget);
4124 d->createExtra();
4125 uint expl = d->extra->explicitMinSize | (h ? Qt::Vertical : 0);
4127 d->extra->explicitMinSize = expl;
4128}
4129
4131{
4132 Q_D(QWidget);
4133 d->createExtra();
4134 uint expl = d->extra->explicitMaxSize | (w == QWIDGETSIZE_MAX ? 0 : Qt::Horizontal);
4136 d->extra->explicitMaxSize = expl;
4137}
4138
4140{
4141 Q_D(QWidget);
4142 d->createExtra();
4143 uint expl = d->extra->explicitMaxSize | (h == QWIDGETSIZE_MAX ? 0 : Qt::Vertical);
4145 d->extra->explicitMaxSize = expl;
4146}
4147
4156{
4157 Q_D(QWidget);
4158 d->createExtra();
4159 uint explMin = d->extra->explicitMinSize | Qt::Horizontal;
4160 uint explMax = d->extra->explicitMaxSize | Qt::Horizontal;
4163 d->extra->explicitMinSize = explMin;
4164 d->extra->explicitMaxSize = explMax;
4165}
4166
4167
4176{
4177 Q_D(QWidget);
4178 d->createExtra();
4179 uint explMin = d->extra->explicitMinSize | Qt::Vertical;
4180 uint explMax = d->extra->explicitMaxSize | Qt::Vertical;
4183 d->extra->explicitMinSize = explMin;
4184 d->extra->explicitMaxSize = explMax;
4185}
4186
4187
4197QPointF QWidget::mapTo(const QWidget *parent, const QPointF &pos) const
4198{
4199 QPointF p = pos;
4200 if (parent) {
4201 const QWidget * w = this;
4202 while (w != parent) {
4203 Q_ASSERT_X(w, "QWidget::mapTo(const QWidget *parent, const QPointF &pos)",
4204 "parent must be in parent hierarchy");
4205 p = w->mapToParent(p);
4206 w = w->parentWidget();
4207 }
4208 }
4209 return p;
4210}
4211
4215QPoint QWidget::mapTo(const QWidget *parent, const QPoint &pos) const
4216{
4217 return mapTo(parent, QPointF(pos)).toPoint();
4218}
4219
4229QPointF QWidget::mapFrom(const QWidget *parent, const QPointF &pos) const
4230{
4231 QPointF p(pos);
4232 if (parent) {
4233 const QWidget * w = this;
4234 while (w != parent) {
4235 Q_ASSERT_X(w, "QWidget::mapFrom(const QWidget *parent, const QPoint &pos)",
4236 "parent must be in parent hierarchy");
4237
4238 p = w->mapFromParent(p);
4239 w = w->parentWidget();
4240 }
4241 }
4242 return p;
4243}
4244
4248QPoint QWidget::mapFrom(const QWidget *parent, const QPoint &pos) const
4249{
4250 return mapFrom(parent, QPointF(pos)).toPoint();
4251}
4252
4264{
4265 return pos + QPointF(data->crect.topLeft());
4266}
4267
4272{
4273 return pos + data->crect.topLeft();
4274}
4275
4287{
4288 return pos - QPointF(data->crect.topLeft());
4289}
4290
4295{
4296 return pos - data->crect.topLeft();
4297}
4298
4299
4314{
4315 QWidget *w = const_cast<QWidget *>(this);
4316 QWidget *p = w->parentWidget();
4317 while (!w->isWindow() && p) {
4318 w = p;
4319 p = p->parentWidget();
4320 }
4321 return w;
4322}
4323
4334{
4336 while (parent && !parent->internalWinId())
4337 parent = parent->parentWidget();
4338 return parent;
4339}
4340
4361{
4362
4363 const QWidget *w = this;
4364 do {
4365 QPalette::ColorRole role = w->d_func()->bg_role;
4366 if (role != QPalette::NoRole)
4367 return role;
4368 if (w->isWindow() || w->windowType() == Qt::SubWindow)
4369 break;
4370 w = w->parentWidget();
4371 } while (w);
4372 return QPalette::Window;
4373}
4374
4392{
4393 Q_D(QWidget);
4394 d->bg_role = role;
4395 d->updateSystemBackground();
4396 d->propagatePaletteChange();
4397 d->updateIsOpaque();
4398}
4399
4412{
4413 Q_D(const QWidget);
4415 if (rl != QPalette::NoRole)
4416 return rl;
4418 switch (backgroundRole()) {
4419 case QPalette::Button:
4420 role = QPalette::ButtonText;
4421 break;
4422 case QPalette::Base:
4423 role = QPalette::Text;
4424 break;
4425 case QPalette::Dark:
4426 case QPalette::Shadow:
4427 role = QPalette::Light;
4428 break;
4431 break;
4433 role = QPalette::ToolTipText;
4434 break;
4435 default:
4436 ;
4437 }
4438 return role;
4439}
4440
4457{
4458 Q_D(QWidget);
4459 d->fg_role = role;
4460 d->updateSystemBackground();
4461 d->propagatePaletteChange();
4462}
4463
4515{
4516 if (!isEnabled()) {
4518 } else if ((!isVisible() || isActiveWindow())
4519#if defined(Q_OS_WIN)
4520 && !QApplicationPrivate::isBlockedByModal(const_cast<QWidget *>(this))
4521#endif
4522 ) {
4523 data->pal.setCurrentColorGroup(QPalette::Active);
4524 } else {
4525 data->pal.setCurrentColorGroup(QPalette::Inactive);
4526 }
4527 return data->pal;
4528}
4529
4531{
4532 Q_D(QWidget);
4534
4535 // Determine which palette is inherited from this widget's ancestors and
4536 // QApplication::palette, resolve this against \a palette (attributes from
4537 // the inherited palette are copied over this widget's palette). Then
4538 // propagate this palette to this widget's children.
4539 QPalette naturalPalette = d->naturalWidgetPalette(d->inheritedPaletteResolveMask);
4540 QPalette resolvedPalette = palette.resolve(naturalPalette);
4541 d->setPalette_helper(resolvedPalette);
4542}
4543
4554{
4555 Q_Q(const QWidget);
4556
4557 const bool useStyleSheetPropagationInWidgetStyles =
4559
4560 QPalette naturalPalette = QApplication::palette(q);
4561 if ((!q->testAttribute(Qt::WA_StyleSheet) || useStyleSheetPropagationInWidgetStyles)
4562 && (!q->isWindow() || q->testAttribute(Qt::WA_WindowPropagation)
4563#if QT_CONFIG(graphicsview)
4564 || (extra && extra->proxyWidget)
4565#endif // QT_CONFIG(graphicsview)
4566 )) {
4567 if (QWidget *p = q->parentWidget()) {
4568 if (!p->testAttribute(Qt::WA_StyleSheet) || useStyleSheetPropagationInWidgetStyles) {
4569 if (!naturalPalette.isCopyOf(QGuiApplication::palette())) {
4570 QPalette inheritedPalette = p->palette();
4571 inheritedPalette.setResolveMask(inheritedMask);
4572 naturalPalette = inheritedPalette.resolve(naturalPalette);
4573 } else {
4574 naturalPalette = p->palette();
4575 }
4576 }
4577 }
4578#if QT_CONFIG(graphicsview)
4579 else if (extra && extra->proxyWidget) {
4580 QPalette inheritedPalette = extra->proxyWidget->palette();
4581 inheritedPalette.setResolveMask(inheritedMask);
4582 naturalPalette = inheritedPalette.resolve(naturalPalette);
4583 }
4584#endif // QT_CONFIG(graphicsview)
4585 }
4586 naturalPalette.setResolveMask(0);
4587 return naturalPalette;
4588}
4598{
4600 QPalette resolvedPalette = data.pal.resolve(naturalPalette);
4601 setPalette_helper(resolvedPalette);
4602}
4603
4605{
4606 Q_Q(QWidget);
4607 if (data.pal == palette && data.pal.resolveMask() == palette.resolveMask())
4608 return;
4609 data.pal = palette;
4613 q->update();
4615}
4616
4620
4668{
4669 Q_D(QWidget);
4670
4671#ifndef QT_NO_STYLE_STYLESHEET
4672 const QStyleSheetStyle* style;
4673 if (d->extra && (style = qt_styleSheet(d->extra->style)))
4674 style->saveWidgetFont(this, font);
4675#endif
4676
4678
4679 // Determine which font is inherited from this widget's ancestors and
4680 // QApplication::font, resolve this against \a font (attributes from the
4681 // inherited font are copied over). Then propagate this font to this
4682 // widget's children.
4683 QFont naturalFont = d->naturalWidgetFont(d->inheritedFontResolveMask);
4684 QFont resolvedFont = font.resolve(naturalFont);
4685 d->setFont_helper(resolvedFont);
4686}
4687
4688/*
4689 \internal
4690
4691 Returns the font that the widget \a w inherits from its ancestors and
4692 QApplication::font. \a inheritedMask is the combination of the widget's
4693 ancestors font request masks (i.e., which attributes from the parent
4694 widget's font are implicitly imposed on this widget by the user). Note
4695 that this font does not take into account the font set on \a w itself.
4696
4697 ### Stylesheet has a different font propagation mechanism. When a stylesheet
4698 is applied, fonts are not propagated anymore
4699*/
4701{
4702 Q_Q(const QWidget);
4703
4704 const bool useStyleSheetPropagationInWidgetStyles =
4706
4707 QFont naturalFont = QApplication::font(q);
4708 if ((!q->testAttribute(Qt::WA_StyleSheet) || useStyleSheetPropagationInWidgetStyles)
4709 && (!q->isWindow() || q->testAttribute(Qt::WA_WindowPropagation)
4710#if QT_CONFIG(graphicsview)
4711 || (extra && extra->proxyWidget)
4712#endif // QT_CONFIG(graphicsview)
4713 )) {
4714 if (QWidget *p = q->parentWidget()) {
4715 if (!p->testAttribute(Qt::WA_StyleSheet) || useStyleSheetPropagationInWidgetStyles) {
4716 if (!naturalFont.isCopyOf(QApplication::font())) {
4717 if (inheritedMask != 0) {
4718 QFont inheritedFont = p->font();
4719 inheritedFont.setResolveMask(inheritedMask);
4720 naturalFont = inheritedFont.resolve(naturalFont);
4721 } // else nothing to do (naturalFont = naturalFont)
4722 } else {
4723 naturalFont = p->font();
4724 }
4725 }
4726 }
4727#if QT_CONFIG(graphicsview)
4728 else if (extra && extra->proxyWidget) {
4729 if (inheritedMask != 0) {
4730 QFont inheritedFont = extra->proxyWidget->font();
4731 inheritedFont.setResolveMask(inheritedMask);
4732 naturalFont = inheritedFont.resolve(naturalFont);
4733 } // else nothing to do (naturalFont = naturalFont)
4734 }
4735#endif // QT_CONFIG(graphicsview)
4736 }
4737 naturalFont.setResolveMask(0);
4738 return naturalFont;
4739}
4740
4747{
4748 QFont localfont = data.fnt;
4750 return localfont;
4751}
4752
4762{
4764 QFont resolvedFont = localFont().resolve(naturalFont);
4765 setFont_helper(resolvedFont);
4766}
4767
4778{
4779 Q_Q(QWidget);
4780#ifndef QT_NO_STYLE_STYLESHEET
4781 const QStyleSheetStyle* cssStyle;
4782 cssStyle = extra ? qt_styleSheet(extra->style) : nullptr;
4783 const bool useStyleSheetPropagationInWidgetStyles =
4785#endif
4786
4787 data.fnt = QFont(font, q);
4788
4789 // Combine new mask with natural mask and propagate to children.
4790#if QT_CONFIG(graphicsview)
4791 if (!q->parentWidget() && extra && extra->proxyWidget) {
4792 QGraphicsProxyWidget *p = extra->proxyWidget;
4793 inheritedFontResolveMask = p->d_func()->inheritedFontResolveMask | p->font().resolveMask();
4794 } else
4795#endif // QT_CONFIG(graphicsview)
4796 if (q->isWindow() && !q->testAttribute(Qt::WA_WindowPropagation)) {
4798 }
4799 uint newMask = data.fnt.resolveMask() | inheritedFontResolveMask;
4800 // Set the font as also having resolved inherited traits, so the result of reading QWidget::font()
4801 // isn't all weak information, but save the original mask to be able to let new changes on the
4802 // parent widget font propagate correctly.
4803 directFontResolveMask = data.fnt.resolveMask();
4804 data.fnt.setResolveMask(newMask);
4805
4806 for (int i = 0; i < children.size(); ++i) {
4808 if (w) {
4809 if (0) {
4810#ifndef QT_NO_STYLE_STYLESHEET
4811 } else if (!useStyleSheetPropagationInWidgetStyles && w->testAttribute(Qt::WA_StyleSheet)) {
4812 // Style sheets follow a different font propagation scheme.
4813 if (cssStyle)
4814 cssStyle->updateStyleSheetFont(w);
4815#endif
4816 } else if ((!w->isWindow() || w->testAttribute(Qt::WA_WindowPropagation))) {
4817 // Propagate font changes.
4818 QWidgetPrivate *wd = w->d_func();
4819 wd->inheritedFontResolveMask = newMask;
4820 wd->resolveFont();
4821 }
4822 }
4823 }
4824
4825#ifndef QT_NO_STYLE_STYLESHEET
4826 if (!useStyleSheetPropagationInWidgetStyles && cssStyle) {
4827 cssStyle->updateStyleSheetFont(q);
4828 }
4829#endif
4830
4833}
4834
4836{
4837 Q_Q(QWidget);
4838
4839 if ( (direction == Qt::RightToLeft) == q->testAttribute(Qt::WA_RightToLeft))
4840 return;
4841 q->setAttribute(Qt::WA_RightToLeft, (direction == Qt::RightToLeft));
4842 if (!children.isEmpty()) {
4843 for (int i = 0; i < children.size(); ++i) {
4845 if (w && !w->isWindow() && !w->testAttribute(Qt::WA_SetLayoutDirection))
4846 w->d_func()->setLayoutDirection_helper(direction);
4847 }
4848 }
4851}
4852
4854{
4855 Q_Q(const QWidget);
4856 if (!q->testAttribute(Qt::WA_SetLayoutDirection))
4857 setLayoutDirection_helper(q->isWindow() ? QGuiApplication::layoutDirection() : q->parentWidget()->layoutDirection());
4858}
4859
4880{
4881 Q_D(QWidget);
4882
4885 return;
4886 }
4887
4889 d->setLayoutDirection_helper(direction);
4890}
4891
4896
4898{
4899 Q_D(QWidget);
4901 d->resolveLayoutDirection();
4902}
4903
4947#ifndef QT_NO_CURSOR
4949{
4950 Q_D(const QWidget);
4952 return (d->extra && d->extra->curs)
4953 ? *d->extra->curs
4955 if (isWindow() || !parentWidget())
4956 return QCursor(Qt::ArrowCursor);
4957 return parentWidget()->cursor();
4958}
4959
4961{
4962 Q_D(QWidget);
4964 || (d->extra && d->extra->curs))
4965 {
4966 d->createExtra();
4967 d->extra->curs = std::make_unique<QCursor>(cursor);
4968 }
4970 d->setCursor_sys(cursor);
4971
4974}
4975
4977{
4979 Q_Q(QWidget);
4980 qt_qpa_set_cursor(q, false);
4981}
4982
4984{
4985 Q_D(QWidget);
4986 if (d->extra)
4987 d->extra->curs.reset();
4988 if (!isWindow())
4990 d->unsetCursor_sys();
4991
4994}
4995
4997{
4998 Q_Q(QWidget);
4999 qt_qpa_set_cursor(q, false);
5000}
5001
5002static inline void applyCursor(QWidget *w, const QCursor &c)
5003{
5004 if (QWindow *window = w->windowHandle())
5005 window->setCursor(c);
5006}
5007
5008static inline void unsetCursor(QWidget *w)
5009{
5010 if (QWindow *window = w->windowHandle())
5011 window->unsetCursor();
5012}
5013
5014void qt_qpa_set_cursor(QWidget *w, bool force)
5015{
5016 if (!w->testAttribute(Qt::WA_WState_Created))
5017 return;
5018
5019 static QPointer<QWidget> lastUnderMouse = nullptr;
5020 if (force) {
5021 lastUnderMouse = w;
5022 } else if (lastUnderMouse) {
5023 const WId lastWinId = lastUnderMouse->effectiveWinId();
5024 const WId winId = w->effectiveWinId();
5025 if (lastWinId && lastWinId == winId)
5026 w = lastUnderMouse;
5027 } else if (!w->internalWinId()) {
5028 return; // The mouse is not under this widget, and it's not native, so don't change it.
5029 }
5030
5031 while (!w->internalWinId() && w->parentWidget() && !w->isWindow()
5032 && !w->testAttribute(Qt::WA_SetCursor))
5033 w = w->parentWidget();
5034
5035 QWidget *nativeParent = w;
5036 if (!w->internalWinId())
5037 nativeParent = w->nativeParentWidget();
5038 if (!nativeParent || !nativeParent->internalWinId())
5039 return;
5040
5041 if (w->isWindow() || w->testAttribute(Qt::WA_SetCursor)) {
5042 if (w->isEnabled())
5043 applyCursor(nativeParent, w->cursor());
5044 else
5045 // Enforce the windows behavior of clearing the cursor on
5046 // disabled widgets.
5047 unsetCursor(nativeParent);
5048 } else {
5049 unsetCursor(nativeParent);
5050 }
5051}
5052#endif
5053
5092void QWidget::render(QPaintDevice *target, const QPoint &targetOffset,
5093 const QRegion &sourceRegion, RenderFlags renderFlags)
5094{
5095 QPainter p(target);
5096 render(&p, targetOffset, sourceRegion, renderFlags);
5097}
5098
5112void QWidget::render(QPainter *painter, const QPoint &targetOffset,
5113 const QRegion &sourceRegion, RenderFlags renderFlags)
5114{
5115 if (Q_UNLIKELY(!painter)) {
5116 qWarning("QWidget::render: Null pointer to painter");
5117 return;
5118 }
5119
5120 if (Q_UNLIKELY(!painter->isActive())) {
5121 qWarning("QWidget::render: Cannot render with an inactive painter");
5122 return;
5123 }
5124
5125 const qreal opacity = painter->opacity();
5126 if (qFuzzyIsNull(opacity))
5127 return; // Fully transparent.
5128
5129 Q_D(QWidget);
5130 const bool inRenderWithPainter = d->extra && d->extra->inRenderWithPainter;
5131 const QRegion toBePainted = !inRenderWithPainter ? d->prepareToRender(sourceRegion, renderFlags)
5132 : sourceRegion;
5133 if (toBePainted.isEmpty())
5134 return;
5135
5136 if (!d->extra)
5137 d->createExtra();
5138 d->extra->inRenderWithPainter = true;
5139
5142 QPaintEnginePrivate *enginePriv = engine->d_func();
5143 Q_ASSERT(enginePriv);
5144 QPaintDevice *target = engine->paintDevice();
5146
5147 // Render via a pixmap when dealing with non-opaque painters or printers.
5148 if (!inRenderWithPainter && (opacity < 1.0 || (target->devType() == QInternal::Printer))) {
5149 d->render_helper(painter, targetOffset, toBePainted, renderFlags);
5150 d->extra->inRenderWithPainter = inRenderWithPainter;
5151 return;
5152 }
5153
5154 // Set new shared painter.
5155 QPainter *oldPainter = d->sharedPainter();
5156 d->setSharedPainter(painter);
5157
5158 // Save current system clip, viewport and transform,
5159 const QTransform oldTransform = enginePriv->systemTransform;
5160 const QRegion oldSystemClip = enginePriv->systemClip;
5161 const QRegion oldBaseClip = enginePriv->baseSystemClip;
5162 const QRegion oldSystemViewport = enginePriv->systemViewport;
5163 const Qt::LayoutDirection oldLayoutDirection = painter->layoutDirection();
5164
5165 // This ensures that all painting triggered by render() is clipped to the current engine clip.
5166 if (painter->hasClipping()) {
5167 const QRegion painterClip = painter->deviceTransform().map(painter->clipRegion());
5168 enginePriv->setSystemViewport(oldSystemClip.isEmpty() ? painterClip : oldSystemClip & painterClip);
5169 } else {
5170 enginePriv->setSystemViewport(oldSystemClip);
5171 }
5173
5174 d->render(target, targetOffset, toBePainted, renderFlags);
5175
5176 // Restore system clip, viewport and transform.
5177 enginePriv->baseSystemClip = oldBaseClip;
5178 enginePriv->setSystemTransformAndViewport(oldTransform, oldSystemViewport);
5179 enginePriv->systemStateChanged();
5180 painter->setLayoutDirection(oldLayoutDirection);
5181
5182 // Restore shared painter.
5183 d->setSharedPainter(oldPainter);
5184
5185 d->extra->inRenderWithPainter = inRenderWithPainter;
5186}
5187
5189{
5190 QResizeEvent e(target->size(), QSize());
5192
5193 const QObjectList children = target->children();
5194 for (int i = 0; i < children.size(); ++i) {
5195 if (!children.at(i)->isWidgetType())
5196 continue;
5197 QWidget *child = static_cast<QWidget*>(children.at(i));
5198 if (!child->isWindow() && child->testAttribute(Qt::WA_PendingResizeEvent))
5200 }
5201}
5202
5215QPixmap QWidget::grab(const QRect &rectangle)
5216{
5217 Q_D(QWidget);
5219 sendResizeEvents(this);
5220
5221 const QWidget::RenderFlags renderFlags = QWidget::DrawWindowBackground | QWidget::DrawChildren | QWidget::IgnoreMask;
5222
5223 const bool oldDirtyOpaqueChildren = d->dirtyOpaqueChildren;
5224 QRect r(rectangle);
5225 if (r.width() < 0 || r.height() < 0) {
5226 // For grabbing widgets that haven't been shown yet,
5227 // we trigger the layouting mechanism to determine the widget's size.
5228 r = d->prepareToRender(QRegion(), renderFlags).boundingRect();
5229 r.setTopLeft(rectangle.topLeft());
5230 }
5231
5232 if (!r.intersects(rect()))
5233 return QPixmap();
5234
5235 const qreal dpr = devicePixelRatio();
5236 QPixmap res((QSizeF(r.size()) * dpr).toSize());
5237 res.setDevicePixelRatio(dpr);
5238 if (!d->isOpaque)
5239 res.fill(Qt::transparent);
5240 d->render(&res, QPoint(), QRegion(r), renderFlags);
5241
5242 d->dirtyOpaqueChildren = oldDirtyOpaqueChildren;
5243 return res;
5244}
5245
5256#if QT_CONFIG(graphicseffect)
5257QGraphicsEffect *QWidget::graphicsEffect() const
5258{
5259 Q_D(const QWidget);
5260 return d->graphicsEffect;
5261}
5262#endif // QT_CONFIG(graphicseffect)
5263
5286#if QT_CONFIG(graphicseffect)
5287void QWidget::setGraphicsEffect(QGraphicsEffect *effect)
5288{
5289 Q_D(QWidget);
5290 if (d->graphicsEffect == effect)
5291 return;
5292
5293 if (d->graphicsEffect) {
5294 d->invalidateBackingStore(rect());
5295 delete d->graphicsEffect;
5296 d->graphicsEffect = nullptr;
5297 }
5298
5299 if (effect) {
5300 // Set new effect.
5303 d->graphicsEffect = effect;
5304 effect->d_func()->setGraphicsEffectSource(source);
5305 update();
5306 }
5307
5308 d->updateIsOpaque();
5309}
5310#endif // QT_CONFIG(graphicseffect)
5311
5313{
5314 if (data.in_show)
5315 return true;
5316
5317 Q_Q(const QWidget);
5318 if (q->isHidden())
5319 return false;
5320
5321 // The widget will be shown if any of its ancestors are about to show.
5322 QWidget *parent = q->parentWidget();
5323 return parent ? parent->d_func()->isAboutToShow() : false;
5324}
5325
5326QRegion QWidgetPrivate::prepareToRender(const QRegion &region, QWidget::RenderFlags renderFlags)
5327{
5328 Q_Q(QWidget);
5329 const bool isVisible = q->isVisible();
5330
5331 // Make sure the widget is laid out correctly.
5332 if (!isVisible && !isAboutToShow()) {
5333 QWidget *topLevel = q->window();
5334 (void)topLevel->d_func()->topData(); // Make sure we at least have top-data.
5335 topLevel->ensurePolished();
5336
5337 // Invalidate the layout of hidden ancestors (incl. myself) and pretend
5338 // they're not explicitly hidden.
5339 QWidget *widget = q;
5340 QWidgetList hiddenWidgets;
5341 while (widget) {
5342 if (widget->isHidden()) {
5344 hiddenWidgets.append(widget);
5345 if (!widget->isWindow() && widget->parentWidget()->d_func()->layout)
5346 widget->d_func()->updateGeometry_helper(true);
5347 }
5349 }
5350
5351 // Activate top-level layout.
5352 if (topLevel->d_func()->layout)
5353 topLevel->d_func()->layout->activate();
5354
5355 // Adjust size if necessary.
5356 QTLWExtra *topLevelExtra = topLevel->d_func()->maybeTopData();
5357 if (topLevelExtra && !topLevelExtra->sizeAdjusted
5358 && !topLevel->testAttribute(Qt::WA_Resized)) {
5359 topLevel->adjustSize();
5360 topLevel->setAttribute(Qt::WA_Resized, false);
5361 }
5362
5363 // Activate child layouts.
5364 topLevel->d_func()->activateChildLayoutsRecursively();
5365
5366 // We're not cheating with WA_WState_Hidden anymore.
5367 for (int i = 0; i < hiddenWidgets.size(); ++i) {
5368 QWidget *widget = hiddenWidgets.at(i);
5370 if (!widget->isWindow() && widget->parentWidget()->d_func()->layout)
5371 widget->parentWidget()->d_func()->layout->invalidate();
5372 }
5373 } else if (isVisible) {
5374 q->window()->d_func()->sendPendingMoveAndResizeEvents(true, true);
5375 }
5376
5377 // Calculate the region to be painted.
5378 QRegion toBePainted = !region.isEmpty() ? region : QRegion(q->rect());
5379 if (!(renderFlags & QWidget::IgnoreMask) && extra && extra->hasMask)
5380 toBePainted &= extra->mask;
5381 return toBePainted;
5382}
5383
5384void QWidgetPrivate::render_helper(QPainter *painter, const QPoint &targetOffset, const QRegion &toBePainted,
5385 QWidget::RenderFlags renderFlags)
5386{
5388 Q_ASSERT(!toBePainted.isEmpty());
5389
5390 Q_Q(QWidget);
5391 const QTransform originalTransform = painter->worldTransform();
5392 const bool useDeviceCoordinates = originalTransform.isScaling();
5393 if (!useDeviceCoordinates) {
5394 // Render via a pixmap.
5395 const QRect rect = toBePainted.boundingRect();
5396 const QSize size = rect.size();
5397 if (size.isNull())
5398 return;
5399
5400 const qreal pixmapDevicePixelRatio = painter->device()->devicePixelRatio();
5401 QPixmap pixmap(size * pixmapDevicePixelRatio);
5402 pixmap.setDevicePixelRatio(pixmapDevicePixelRatio);
5403
5404 if (!(renderFlags & QWidget::DrawWindowBackground) || !isOpaque)
5405 pixmap.fill(Qt::transparent);
5406 q->render(&pixmap, QPoint(), toBePainted, renderFlags);
5407
5408 const bool restore = !(painter->renderHints() & QPainter::SmoothPixmapTransform);
5410
5411 painter->drawPixmap(targetOffset, pixmap);
5412
5413 if (restore)
5415
5416 } else {
5417 // Render via a pixmap in device coordinates (to avoid pixmap scaling).
5418 QTransform transform = originalTransform;
5419 transform.translate(targetOffset.x(), targetOffset.y());
5420
5423
5424 // Calculate device rect.
5425 const QRectF rect(toBePainted.boundingRect());
5426 QRect deviceRect = transform.mapRect(QRectF(0, 0, rect.width(), rect.height())).toAlignedRect();
5427 deviceRect &= QRect(0, 0, device->width(), device->height());
5428
5430 pixmap.fill(Qt::transparent);
5431
5432 // Create a pixmap device coordinate painter.
5433 QPainter pixmapPainter(&pixmap);
5434 pixmapPainter.setRenderHints(painter->renderHints());
5436 pixmapPainter.setTransform(transform);
5437
5438 q->render(&pixmapPainter, QPoint(), toBePainted, renderFlags);
5439 pixmapPainter.end();
5440
5441 // And then draw the pixmap.
5444 painter->setTransform(originalTransform);
5445 }
5446}
5447
5448void QWidgetPrivate::drawWidget(QPaintDevice *pdev, const QRegion &rgn, const QPoint &offset, DrawWidgetFlags flags,
5449 QPainter *sharedPainter, QWidgetRepaintManager *repaintManager)
5450{
5451 if (rgn.isEmpty())
5452 return;
5453
5454 Q_Q(QWidget);
5455
5456 qCInfo(lcWidgetPainting) << "Drawing" << rgn << "of" << q << "at" << offset
5457 << "into paint device" << pdev << "with" << flags;
5458
5459 const bool asRoot = flags & DrawAsRoot;
5460 bool onScreen = shouldPaintOnScreen();
5461
5462#if QT_CONFIG(graphicseffect)
5465 QWidgetEffectSourcePrivate *sourced = static_cast<QWidgetEffectSourcePrivate *>
5466 (source->d_func());
5467 if (!sourced->context) {
5468 const QRegion effectRgn((flags & UseEffectRegionBounds) ? rgn.boundingRect() : rgn);
5469 QWidgetPaintContext context(pdev, effectRgn, offset, flags, sharedPainter, repaintManager);
5470 sourced->context = &context;
5471 if (!sharedPainter) {
5472 setSystemClip(pdev->paintEngine(), pdev->devicePixelRatio(), effectRgn.translated(offset));
5473 QPainter p(pdev);
5474 p.translate(offset);
5475 context.painter = &p;
5477 setSystemClip(pdev->paintEngine(), 1, QRegion());
5478 } else {
5479 context.painter = sharedPainter;
5480 if (sharedPainter->worldTransform() != sourced->lastEffectTransform) {
5481 sourced->invalidateCache();
5482 sourced->lastEffectTransform = sharedPainter->worldTransform();
5483 }
5490 }
5491 sourced->context = nullptr;
5492
5493 if (repaintManager)
5494 repaintManager->markNeedsFlush(q, effectRgn, offset);
5495
5496 return;
5497 }
5498 }
5499#endif // QT_CONFIG(graphicseffect)
5500 flags = flags & ~UseEffectRegionBounds;
5501
5502 const bool alsoOnScreen = flags & DrawPaintOnScreen;
5503 const bool recursive = flags & DrawRecursive;
5504 const bool alsoInvisible = flags & DrawInvisible;
5505
5507
5508 QRegion toBePainted(rgn);
5509 if (asRoot && !alsoInvisible)
5510 toBePainted &= clipRect(); //(rgn & visibleRegion());
5512 subtractOpaqueChildren(toBePainted, q->rect());
5513
5514 if (!toBePainted.isEmpty()) {
5515 if (!onScreen || alsoOnScreen) {
5516 //update the "in paint event" flag
5517 if (Q_UNLIKELY(q->testAttribute(Qt::WA_WState_InPaintEvent)))
5518 qWarning("QWidget::repaint: Recursive repaint detected");
5519 q->setAttribute(Qt::WA_WState_InPaintEvent);
5520
5521 //clip away the new area
5522 QPaintEngine *paintEngine = pdev->paintEngine();
5523 if (paintEngine) {
5524 setRedirected(pdev, -offset);
5525
5526 if (sharedPainter)
5527 setSystemClip(pdev->paintEngine(), pdev->devicePixelRatio(), toBePainted);
5528 else
5529 paintEngine->d_func()->systemRect = q->data->crect;
5530
5531 //paint the background
5532 if ((asRoot || q->autoFillBackground() || onScreen || q->testAttribute(Qt::WA_StyledBackground))
5533 && !q->testAttribute(Qt::WA_OpaquePaintEvent) && !q->testAttribute(Qt::WA_NoSystemBackground)) {
5535 QPainter p(q);
5536 p.setRenderHint(QPainter::SmoothPixmapTransform);
5537 paintBackground(&p, toBePainted, (asRoot || onScreen) ? (flags | DrawAsRoot) : DrawWidgetFlags());
5539 }
5540
5541 if (!sharedPainter)
5542 setSystemClip(pdev->paintEngine(), pdev->devicePixelRatio(), toBePainted.translated(offset));
5543
5544 if (!onScreen && !asRoot && !isOpaque && q->testAttribute(Qt::WA_TintedBackground)) {
5546 QPainter p(q);
5547 QColor tint = q->palette().window().color();
5548 tint.setAlphaF(.6f);
5549 p.fillRect(toBePainted.boundingRect(), tint);
5551 }
5552 }
5553
5554#if 0
5555 qDebug() << "painting" << q << "opaque ==" << isOpaque();
5556 qDebug() << "clipping to" << toBePainted << "location == " << offset
5557 << "geometry ==" << QRect(q->mapTo(q->window(), QPoint(0, 0)), q->size());
5558#endif
5559
5560 bool skipPaintEvent = false;
5561 if (renderToTexture) {
5562 // This widget renders into a texture which is composed later. We just need to
5563 // punch a hole in the backingstore, so the texture will be visible.
5565 if (!q->testAttribute(Qt::WA_AlwaysStackOnTop) && repaintManager) {
5566 QPainter p(q);
5567 p.setCompositionMode(QPainter::CompositionMode_Source);
5568 p.fillRect(q->rect(), Qt::transparent);
5569 } else if (!repaintManager) {
5570 // We are not drawing to a backingstore: fall back to QImage
5572 // grabFramebuffer() always sets the format to RGB32
5573 // regardless of whether it is transparent or not.
5574 if (img.format() == QImage::Format_RGB32)
5575 img.reinterpretAsFormat(QImage::Format_ARGB32_Premultiplied);
5576 QPainter p(q);
5577 p.drawImage(q->rect(), img);
5578 skipPaintEvent = true;
5579 }
5583 else
5584 skipPaintEvent = true;
5585 }
5586
5587 if (!skipPaintEvent) {
5588 //actually send the paint event
5589 sendPaintEvent(toBePainted);
5590 }
5591
5592 if (repaintManager)
5593 repaintManager->markNeedsFlush(q, toBePainted, offset);
5594
5595 //restore
5596 if (paintEngine) {
5598 if (!sharedPainter)
5599 paintEngine->d_func()->systemRect = QRect();
5600 else
5601 paintEngine->d_func()->currentClipDevice = nullptr;
5602
5603 setSystemClip(pdev->paintEngine(), 1, QRegion());
5604 }
5605 q->setAttribute(Qt::WA_WState_InPaintEvent, false);
5606 if (Q_UNLIKELY(q->paintingActive()))
5607 qWarning("QWidget::repaint: It is dangerous to leave painters active on a widget outside of the PaintEvent");
5608
5609 if (paintEngine && paintEngine->autoDestruct()) {
5610 delete paintEngine;
5611 }
5612 } else if (q->isWindow()) {
5613 QPaintEngine *engine = pdev->paintEngine();
5614 if (engine) {
5615 QPainter p(pdev);
5616 p.setClipRegion(toBePainted);
5617 const QBrush bg = q->palette().brush(QPalette::Window);
5618 if (bg.style() == Qt::TexturePattern)
5619 p.drawTiledPixmap(q->rect(), bg.texture());
5620 else
5621 p.fillRect(q->rect(), bg);
5622
5623 if (engine->autoDestruct())
5624 delete engine;
5625 }
5626 }
5627 }
5628
5629 if (recursive && !children.isEmpty()) {
5631 sharedPainter, repaintManager);
5632 }
5633}
5634
5636{
5637 Q_Q(QWidget);
5638 QPaintEvent e(toBePainted);
5639 QCoreApplication::sendSpontaneousEvent(q, &e);
5640
5641 if (renderToTexture)
5643}
5644
5646 const QRegion &sourceRegion, QWidget::RenderFlags renderFlags)
5647{
5648 if (Q_UNLIKELY(!target)) {
5649 qWarning("QWidget::render: null pointer to paint device");
5650 return;
5651 }
5652
5653 const bool inRenderWithPainter = extra && extra->inRenderWithPainter;
5654 QRegion paintRegion = !inRenderWithPainter
5655 ? prepareToRender(sourceRegion, renderFlags)
5656 : sourceRegion;
5657 if (paintRegion.isEmpty())
5658 return;
5659
5660 QPainter *oldSharedPainter = inRenderWithPainter ? sharedPainter() : nullptr;
5661
5662 // Use the target's shared painter if set (typically set when doing
5663 // "other->render(widget);" in the widget's paintEvent.
5664 if (target->devType() == QInternal::Widget) {
5665 QWidgetPrivate *targetPrivate = static_cast<QWidget *>(target)->d_func();
5666 if (targetPrivate->extra && targetPrivate->extra->inRenderWithPainter) {
5667 QPainter *targetPainter = targetPrivate->sharedPainter();
5668 if (targetPainter && targetPainter->isActive())
5669 setSharedPainter(targetPainter);
5670 }
5671 }
5672
5673 // Use the target's redirected device if set and adjust offset and paint
5674 // region accordingly. This is typically the case when people call render
5675 // from the paintEvent.
5676 QPoint offset = targetOffset;
5677 offset -= paintRegion.boundingRect().topLeft();
5678 QPoint redirectionOffset;
5679 QPaintDevice *redirected = nullptr;
5680
5681 if (target->devType() == QInternal::Widget)
5682 redirected = static_cast<QWidget *>(target)->d_func()->redirected(&redirectionOffset);
5683
5684 if (redirected) {
5686 offset -= redirectionOffset;
5687 }
5688
5689 if (!inRenderWithPainter) { // Clip handled by shared painter (in qpainter.cpp).
5690 if (QPaintEngine *targetEngine = target->paintEngine()) {
5691 const QRegion targetSystemClip = targetEngine->systemClip();
5692 if (!targetSystemClip.isEmpty())
5693 paintRegion &= targetSystemClip.translated(-offset);
5694 }
5695 }
5696
5697 // Set backingstore flags.
5698 DrawWidgetFlags flags = DrawPaintOnScreen | DrawInvisible;
5699 if (renderFlags & QWidget::DrawWindowBackground)
5700 flags |= DrawAsRoot;
5701
5702 if (renderFlags & QWidget::DrawChildren)
5704 else
5706
5708
5709 // Render via backingstore.
5710 drawWidget(target, paintRegion, offset, flags, sharedPainter());
5711
5712 // Restore shared painter.
5713 if (oldSharedPainter)
5714 setSharedPainter(oldSharedPainter);
5715}
5716
5718 const QPoint &offset, DrawWidgetFlags flags
5719 , QPainter *sharedPainter, QWidgetRepaintManager *repaintManager)
5720{
5721 QWidget *w = nullptr;
5723 bool dirtyBoundingRect = true;
5724 const bool exludeOpaqueChildren = (flags & DontDrawOpaqueChildren);
5725 const bool excludeNativeChildren = (flags & DontDrawNativeChildren);
5726
5727 do {
5728 QWidget *x = qobject_cast<QWidget*>(siblings.at(index));
5729 if (x && !(exludeOpaqueChildren && x->d_func()->isOpaque) && !x->isHidden() && !x->isWindow()
5730 && !(excludeNativeChildren && x->internalWinId())) {
5731 if (dirtyBoundingRect) {
5732 boundingRect = rgn.boundingRect();
5733 dirtyBoundingRect = false;
5734 }
5735
5736 if (qRectIntersects(boundingRect, x->d_func()->effectiveRectFor(x->data->crect))) {
5737 w = x;
5738 break;
5739 }
5740 }
5741 --index;
5742 } while (index >= 0);
5743
5744 if (!w)
5745 return;
5746
5747 QWidgetPrivate *wd = w->d_func();
5748 const QPoint widgetPos(w->data->crect.topLeft());
5749 const bool hasMask = wd->extra && wd->extra->hasMask && !wd->graphicsEffect;
5750 if (index > 0) {
5751 QRegion wr(rgn);
5752 if (wd->isOpaque)
5753 wr -= hasMask ? wd->extra->mask.translated(widgetPos) : w->data->crect;
5754 paintSiblingsRecursive(pdev, siblings, --index, wr, offset, flags,
5755 sharedPainter, repaintManager);
5756 }
5757
5758 if (w->updatesEnabled()
5759#if QT_CONFIG(graphicsview)
5760 && (!w->d_func()->extra || !w->d_func()->extra->proxyWidget)
5761#endif // QT_CONFIG(graphicsview)
5762 ) {
5763 QRegion wRegion(rgn);
5764 wRegion &= wd->effectiveRectFor(w->data->crect);
5765 wRegion.translate(-widgetPos);
5766 if (hasMask)
5767 wRegion &= wd->extra->mask;
5768 wd->drawWidget(pdev, wRegion, offset + widgetPos, flags, sharedPainter, repaintManager);
5769 }
5770}
5771
5772#if QT_CONFIG(graphicseffect)
5773QRectF QWidgetEffectSourcePrivate::boundingRect(Qt::CoordinateSystem system) const
5774{
5775 if (system != Qt::DeviceCoordinates)
5776 return m_widget->rect();
5777
5778 if (Q_UNLIKELY(!context)) {
5779 // Device coordinates without context not yet supported.
5780 qWarning("QGraphicsEffectSource::boundingRect: Not yet implemented, lacking device context");
5781 return QRectF();
5782 }
5783
5784 return context->painter->worldTransform().mapRect(m_widget->rect());
5785}
5786
5787void QWidgetEffectSourcePrivate::draw(QPainter *painter)
5788{
5789 if (!context || context->painter != painter) {
5790 m_widget->render(painter);
5791 return;
5792 }
5793
5794 // The region saved in the context is neither clipped to the rect
5795 // nor the mask, so we have to clip it here before calling drawWidget.
5796 QRegion toBePainted = context->rgn;
5797 toBePainted &= m_widget->rect();
5798 QWidgetPrivate *wd = qt_widget_private(m_widget);
5799 if (wd->extra && wd->extra->hasMask)
5800 toBePainted &= wd->extra->mask;
5801
5802 wd->drawWidget(context->pdev, toBePainted, context->offset, context->flags,
5803 context->sharedPainter, context->repaintManager);
5804}
5805
5806QPixmap QWidgetEffectSourcePrivate::pixmap(Qt::CoordinateSystem system, QPoint *offset,
5808{
5809 const bool deviceCoordinates = (system == Qt::DeviceCoordinates);
5810 if (Q_UNLIKELY(!context && deviceCoordinates)) {
5811 // Device coordinates without context not yet supported.
5812 qWarning("QGraphicsEffectSource::pixmap: Not yet implemented, lacking device context");
5813 return QPixmap();
5814 }
5815
5816 QPoint pixmapOffset;
5817 QRectF sourceRect = m_widget->rect();
5818
5819 if (deviceCoordinates) {
5820 const QTransform &painterTransform = context->painter->worldTransform();
5821 sourceRect = painterTransform.mapRect(sourceRect);
5822 pixmapOffset = painterTransform.map(pixmapOffset);
5823 }
5824
5825 QRect effectRect;
5826
5828 effectRect = m_widget->graphicsEffect()->boundingRectFor(sourceRect).toAlignedRect();
5830 effectRect = sourceRect.adjusted(-1, -1, 1, 1).toAlignedRect();
5831 else
5832 effectRect = sourceRect.toAlignedRect();
5833
5834 if (offset)
5835 *offset = effectRect.topLeft();
5836
5837 pixmapOffset -= effectRect.topLeft();
5838
5839 qreal dpr(1.0);
5840 if (const auto *paintDevice = context->painter->device())
5841 dpr = paintDevice->devicePixelRatio();
5842 else
5843 qWarning("QWidgetEffectSourcePrivate::pixmap: Painter not active");
5844 QPixmap pixmap(effectRect.size() * dpr);
5845 pixmap.setDevicePixelRatio(dpr);
5846
5847 pixmap.fill(Qt::transparent);
5848 m_widget->render(&pixmap, pixmapOffset, QRegion(), QWidget::DrawChildren);
5849 return pixmap;
5850}
5851#endif // QT_CONFIG(graphicseffect)
5852
5853#if QT_CONFIG(graphicsview)
5862QGraphicsProxyWidget *QWidgetPrivate::nearestGraphicsProxyWidget(const QWidget *origin)
5863{
5864 if (origin) {
5865 const auto &extra = origin->d_func()->extra;
5866 if (extra && extra->proxyWidget)
5867 return extra->proxyWidget;
5868 return nearestGraphicsProxyWidget(origin->parentWidget());
5869 }
5870 return nullptr;
5871}
5872#endif
5873
5890{
5891 Q_Q(QWidget);
5892 if (locale == loc && !forceUpdate)
5893 return;
5894
5895 locale = loc;
5896
5897 if (!children.isEmpty()) {
5898 for (int i = 0; i < children.size(); ++i) {
5900 if (!w)
5901 continue;
5902 if (w->testAttribute(Qt::WA_SetLocale))
5903 continue;
5904 if (w->isWindow() && !w->testAttribute(Qt::WA_WindowPropagation))
5905 continue;
5906 w->d_func()->setLocale_helper(loc, forceUpdate);
5907 }
5908 }
5911}
5912
5913void QWidget::setLocale(const QLocale &locale)
5914{
5915 Q_D(QWidget);
5916
5918 d->setLocale_helper(locale);
5919}
5920
5922{
5923 Q_D(const QWidget);
5924
5925 return d->locale;
5926}
5927
5929{
5930 Q_Q(const QWidget);
5931
5932 if (!q->testAttribute(Qt::WA_SetLocale)) {
5933 QWidget *parent = q->parentWidget();
5934 setLocale_helper(!parent || (q->isWindow() && !q->testAttribute(Qt::WA_WindowPropagation))
5935 ? QLocale() : parent->locale());
5936 }
5937}
5938
5940{
5941 Q_D(QWidget);
5943 d->resolveLocale();
5944}
5945
5970{
5971 Q_D(const QWidget);
5972 if (d->extra && d->extra->topextra) {
5973 if (!d->extra->topextra->caption.isEmpty())
5974 return d->extra->topextra->caption;
5975 if (!d->extra->topextra->filePath.isEmpty())
5976 return QFileInfo(d->extra->topextra->filePath).fileName() + "[*]"_L1;
5977 }
5978 return QString();
5979}
5980
5993{
5995
5996 QString cap = title;
5997 if (cap.isEmpty())
5998 return cap;
5999
6000 const auto placeHolder = "[*]"_L1;
6001 int index = cap.indexOf(placeHolder);
6002
6003 // here the magic begins
6004 while (index != -1) {
6005 index += placeHolder.size();
6006 int count = 1;
6007 while (cap.indexOf(placeHolder, index) == index) {
6008 ++count;
6009 index += placeHolder.size();
6010 }
6011
6012 if (count%2) { // odd number of [*] -> replace last one
6013 int lastIndex = cap.lastIndexOf(placeHolder, index - 1);
6016 cap.replace(lastIndex, 3, QWidget::tr("*"));
6017 else
6018 cap.remove(lastIndex, 3);
6019 }
6020
6021 index = cap.indexOf(placeHolder, index);
6022 }
6023
6024 cap.replace("[*][*]"_L1, placeHolder);
6025
6026 return cap;
6027}
6028
6035
6037{
6038 Q_Q(QWidget);
6039 if (!q->isWindow())
6040 return;
6041
6042 if (QWindow *window = q->windowHandle())
6043 window->setTitle(caption);
6044
6045}
6046
6053
6055{
6056#if QT_CONFIG(xcb)
6057 Q_Q(QWidget);
6058 // ### The QWidget property is deprecated, but the XCB window function is not.
6059 // It should remain available for the rare application that needs it.
6060 if (QWindow *window = q->windowHandle()) {
6061 if (auto *xcbWindow = dynamic_cast<QXcbWindow*>(window->handle()))
6062 xcbWindow->setWindowIconText(iconText);
6063 }
6064#else
6065 Q_UNUSED(iconText);
6066#endif
6067}
6068
6082{
6083 if (QWidget::windowIconText() == iconText)
6084 return;
6085
6086 Q_D(QWidget);
6087 d->topData()->iconText = iconText;
6088 d->setWindowIconText_helper(iconText);
6089
6092
6093 emit windowIconTextChanged(iconText);
6094}
6095
6106{
6107 if (QWidget::windowTitle() == title && !title.isEmpty() && !title.isNull())
6108 return;
6109
6110 Q_D(QWidget);
6111 d->topData()->caption = title;
6112 d->setWindowTitle_helper(title);
6113
6116
6118}
6119
6120
6136{
6137 const QWidget *w = this;
6138 while (w) {
6139 const QWidgetPrivate *d = w->d_func();
6140 if (d->extra && d->extra->topextra && d->extra->topextra->icon)
6141 return *d->extra->topextra->icon;
6142 w = w->parentWidget();
6143 }
6144 return QApplication::windowIcon();
6145}
6146
6148{
6149 Q_Q(QWidget);
6151
6152 // Do not send the event if the widget is a top level.
6153 // In that case, setWindowIcon_sys does it, and event propagation from
6154 // QWidgetWindow to the top level QWidget ensures that the event reaches
6155 // the top level anyhow
6156 if (!q->windowHandle())
6158 for (int i = 0; i < children.size(); ++i) {
6160 if (w && !w->isWindow())
6162 }
6163}
6164
6175{
6176 Q_D(QWidget);
6177
6179 d->createTLExtra();
6180
6181 if (!d->extra->topextra->icon)
6182 d->extra->topextra->icon = std::make_unique<QIcon>(icon);
6183 else
6184 *d->extra->topextra->icon = icon;
6185
6186 d->setWindowIcon_sys();
6187 d->setWindowIcon_helper();
6188
6190}
6191
6193{
6194 Q_Q(QWidget);
6195 if (QWindow *window = q->windowHandle())
6196 window->setIcon(q->windowIcon());
6197}
6198
6215{
6216 Q_D(const QWidget);
6217 return (d->extra && d->extra->topextra) ? d->extra->topextra->iconText : QString();
6218}
6219
6245{
6246 Q_D(const QWidget);
6247 return (d->extra && d->extra->topextra) ? d->extra->topextra->filePath : QString();
6248}
6249
6251{
6252 if (filePath == windowFilePath())
6253 return;
6254
6255 Q_D(QWidget);
6256
6257 d->createTLExtra();
6258 d->extra->topextra->filePath = filePath;
6259 d->setWindowFilePath_helper(filePath);
6260}
6261
6263{
6264 if (extra->topextra && extra->topextra->caption.isEmpty()) {
6265#ifdef Q_OS_MAC
6267#else
6268 Q_Q(QWidget);
6269 Q_UNUSED(filePath);
6270 setWindowTitle_helper(q->windowTitle());
6271#endif
6272 }
6273#ifdef Q_OS_MAC
6274 setWindowFilePath_sys(filePath);
6275#endif
6276}
6277
6279{
6280 Q_Q(QWidget);
6281 if (!q->isWindow())
6282 return;
6283
6284 if (QWindow *window = q->windowHandle())
6285 window->setFilePath(filePath);
6286}
6287
6295{
6296 Q_D(const QWidget);
6297 return (d->extra && d->extra->topextra) ? d->extra->topextra->role : QString();
6298}
6299
6305{
6306#if QT_CONFIG(xcb)
6307 Q_D(QWidget);
6308 d->createTLExtra();
6309 d->topData()->role = role;
6310 if (windowHandle()) {
6311 if (auto *xcbWindow = dynamic_cast<QXcbWindow*>(windowHandle()->handle()))
6312 xcbWindow->setWindowRole(role);
6313 }
6314#else
6315 Q_UNUSED(role);
6316#endif
6317}
6318
6369{
6370 Q_D(QWidget);
6371 if (!w && !d->extra)
6372 return;
6373
6374 for (QWidget* fp = w; fp; fp = fp->focusProxy()) {
6375 if (Q_UNLIKELY(fp == this)) {
6376 qWarning("QWidget: %s (%s) already in focus proxy chain", metaObject()->className(), objectName().toLocal8Bit().constData());
6377 return;
6378 }
6379 }
6380
6381 const bool moveFocusToProxy = (QApplicationPrivate::focus_widget == this);
6382
6383 d->createExtra();
6384 d->extra->focus_proxy = w;
6385
6386 if (w && isAncestorOf(w)) {
6387 // If the focus proxy is a child of this (so this is a compound widget), then
6388 // we need to make sure that this widget is immediately in front of its own children
6389 // in the focus chain. Otherwise focusNextPrev_helper might jump over unrelated
6390 // widgets that are positioned between this compound widget, and its proxy in
6391 // the focus chain.
6392 const QWidget *parentOfW = w->parentWidget();
6393 Q_ASSERT(parentOfW); // can't be nullptr since we are an ancestor of w
6394 QWidget *firstChild = nullptr;
6395 const auto childList = children();
6396 for (QObject *child : childList) {
6397 if ((firstChild = qobject_cast<QWidget *>(child)))
6398 break;
6399 }
6400 Q_ASSERT(firstChild); // can't be nullptr since w is a child
6401 d->insertIntoFocusChainBefore(firstChild);
6402 } else if (w && w->isAncestorOf(this)) {
6403 // If the focus proxy is a parent, 'this' has to be inserted directly after its parent in the focus chain
6404 // remove it from the chain and insert this into the focus chain after its parent
6405
6406 // is this the case already?
6407 QWidget *parentsNext = w->nextInFocusChain();
6408 if (parentsNext == this) {
6409 // nothing to do.
6411 } else {
6412 d->QWidgetPrivate::insertIntoFocusChainAfter(w);
6413 }
6414 }
6415
6416 if (moveFocusToProxy)
6418}
6419
6420
6428{
6429 Q_D(const QWidget);
6430 return d->extra ? d->extra->focus_proxy.data() : nullptr;
6431}
6432
6433
6447{
6448 const QWidget* w = this;
6449 while (w->d_func()->extra && w->d_func()->extra->focus_proxy)
6450 w = w->d_func()->extra->focus_proxy;
6451#if QT_CONFIG(graphicsview)
6452 if (QWidget *window = w->window()) {
6453 const auto &e = window->d_func()->extra;
6454 if (e && e->proxyWidget && e->proxyWidget->hasFocus() && window->focusWidget() == w)
6455 return true;
6456 }
6457#endif // QT_CONFIG(graphicsview)
6458 return (QApplication::focusWidget() == w);
6459}
6460
6497{
6498 if (!isEnabled())
6499 return;
6500
6501 QWidget *f = d_func()->deepestFocusProxy();
6502 if (!f)
6503 f = this;
6504
6506 return;
6507
6508#if QT_CONFIG(graphicsview)
6509 QWidget *previousProxyFocus = nullptr;
6510 if (const auto &topData = window()->d_func()->extra) {
6511 if (topData->proxyWidget && topData->proxyWidget->hasFocus()) {
6512 previousProxyFocus = topData->proxyWidget->widget()->focusWidget();
6513 if (previousProxyFocus && previousProxyFocus->focusProxy())
6514 previousProxyFocus = previousProxyFocus->focusProxy();
6515 if (previousProxyFocus == f && !topData->proxyWidget->d_func()->proxyIsGivingFocus)
6516 return;
6517 }
6518 }
6519#endif
6520
6521#if QT_CONFIG(graphicsview)
6522 // Update proxy state
6523 if (const auto &topData = window()->d_func()->extra) {
6524 if (topData->proxyWidget && !topData->proxyWidget->hasFocus()) {
6525 f->d_func()->updateFocusChild();
6526 topData->proxyWidget->d_func()->focusFromWidgetToProxy = 1;
6527 topData->proxyWidget->setFocus(reason);
6528 topData->proxyWidget->d_func()->focusFromWidgetToProxy = 0;
6529 }
6530 }
6531#endif
6532
6533 if (f->isActiveWindow()) {
6535 if (prev) {
6536 if (reason != Qt::PopupFocusReason && reason != Qt::MenuBarFocusReason
6538 QGuiApplication::inputMethod()->commit();
6539 }
6540
6541 if (reason != Qt::NoFocusReason) {
6542 QFocusEvent focusAboutToChange(QEvent::FocusAboutToChange, reason);
6543 QCoreApplication::sendEvent(prev, &focusAboutToChange);
6544 }
6545 }
6546
6547 f->d_func()->updateFocusChild();
6548
6550#if QT_CONFIG(accessibility)
6551 // menus update the focus manually and this would create bogus events
6552 if (!(f->inherits("QMenuBar") || f->inherits("QMenu") || f->inherits("QMenuItem")))
6553 {
6554 QAccessibleEvent event(f, QAccessible::Focus);
6555 QAccessible::updateAccessibility(&event);
6556 }
6557#endif
6558#if QT_CONFIG(graphicsview)
6559 if (const auto &topData = window()->d_func()->extra) {
6560 if (topData->proxyWidget) {
6561 if (previousProxyFocus && previousProxyFocus != f) {
6562 // Send event to self
6564 QPointer<QWidget> that = previousProxyFocus;
6565 QCoreApplication::sendEvent(previousProxyFocus, &event);
6566 if (that)
6567 QCoreApplication::sendEvent(that->style(), &event);
6568 }
6569 if (!isHidden()) {
6570#if QT_CONFIG(graphicsview)
6571 // Update proxy state
6572 if (const auto &topData = window()->d_func()->extra)
6573 if (topData->proxyWidget && topData->proxyWidget->hasFocus())
6574 topData->proxyWidget->d_func()->updateProxyInputMethodAcceptanceFromWidget();
6575#endif
6576 // Send event to self
6578 QPointer<QWidget> that = f;
6580 if (that)
6581 QCoreApplication::sendEvent(that->style(), &event);
6582 }
6583 }
6584 }
6585#endif
6586 } else {
6587 f->d_func()->updateFocusChild();
6588 }
6589}
6590
6591
6599{
6600 Q_Q(const QWidget);
6601
6602 QWidget *focusProxy = q->focusProxy();
6603 if (!focusProxy)
6604 return nullptr;
6605
6606 while (QWidget *nextFocusProxy = focusProxy->focusProxy())
6607 focusProxy = nextFocusProxy;
6608
6609 return focusProxy;
6610}
6611
6612static inline bool isEmbedded(const QWindow *w)
6613{
6614 const auto platformWindow = w->handle();
6615 return platformWindow && platformWindow->isEmbedded();
6616}
6617
6619{
6620 Q_Q(QWidget);
6621 // Embedded native widget may have taken the focus; get it back to toplevel
6622 // if that is the case (QTBUG-25852), unless widget is a window container.
6623 if (extra && extra->hasWindowContainer)
6624 return;
6625 // Do not activate in case the popup menu opens another application (QTBUG-70810)
6626 // unless the application is embedded (QTBUG-71991).
6627 if (QWindow *nativeWindow = q->testAttribute(Qt::WA_WState_Created) ? q->window()->windowHandle() : nullptr) {
6631 || isEmbedded(nativeWindow))) {
6632 nativeWindow->requestActivate();
6633 }
6634 }
6635}
6636
6637// updates focus_child on parent widgets to point into this widget
6639{
6640 Q_Q(QWidget);
6641
6642 QWidget *w = q;
6643 if (q->isHidden()) {
6644 while (w && w->isHidden()) {
6645 w->d_func()->focus_child = q;
6646 w = w->isWindow() ? nullptr : w->parentWidget();
6647 }
6648 } else {
6649 while (w) {
6650 w->d_func()->focus_child = q;
6651 w = w->isWindow() ? nullptr : w->parentWidget();
6652 }
6653 }
6654
6655 if (QTLWExtra *extra = q->window()->d_func()->maybeTopData()) {
6656 if (extra->window)
6657 emit extra->window->focusObjectChanged(q);
6658 }
6659}
6660
6684{
6685 if (hasFocus()) {
6687 QGuiApplication::inputMethod()->commit();
6688
6689 QFocusEvent focusAboutToChange(QEvent::FocusAboutToChange);
6690 QCoreApplication::sendEvent(this, &focusAboutToChange);
6691 }
6692
6693 QTLWExtra *extra = window()->d_func()->maybeTopData();
6694 QObject *originalFocusObject = nullptr;
6695 if (extra && extra->window) {
6696 originalFocusObject = extra->window->focusObject();
6697 // the window's focus object might already be nullptr if we are in the destructor, but we still
6698 // need to update QGuiApplication and input context if we have a focus widget.
6699 if (!originalFocusObject)
6700 originalFocusObject = focusWidget();
6701 }
6702
6703 QWidget *w = this;
6704 while (w) {
6705 // Just like setFocus(), we update (clear) the focus_child of our parents
6706 if (w->d_func()->focus_child == this)
6707 w->d_func()->focus_child = nullptr;
6708 w = w->parentWidget();
6709 }
6710
6711 // We've potentially cleared the focus_child of our parents, so we need
6712 // to report this to the rest of Qt. Note that the focus_child is not the same
6713 // thing as the application's focusWidget, which is why this piece of code is
6714 // not inside a hasFocus() block.
6715 if (originalFocusObject && originalFocusObject != extra->window->focusObject())
6716 emit extra->window->focusObjectChanged(extra->window->focusObject());
6717
6718#if QT_CONFIG(graphicsview)
6719 const auto &topData = d_func()->extra;
6720 if (topData && topData->proxyWidget)
6721 topData->proxyWidget->clearFocus();
6722#endif
6723
6724 if (hasFocus()) {
6725 // Update proxy state
6727#if QT_CONFIG(accessibility)
6728 QAccessibleEvent event(this, QAccessible::Focus);
6729 QAccessible::updateAccessibility(&event);
6730#endif
6731 }
6732}
6733
6734
6778{
6779 QWidget* p = parentWidget();
6780 bool isSubWindow = (windowType() == Qt::SubWindow);
6781 if (!isWindow() && !isSubWindow && p)
6782 return p->focusNextPrevChild(next);
6783#if QT_CONFIG(graphicsview)
6784 Q_D(QWidget);
6785 if (d->extra && d->extra->proxyWidget)
6786 return d->extra->proxyWidget->focusNextPrevChild(next);
6787#endif
6788
6789 bool wrappingOccurred = false;
6791 &wrappingOccurred);
6792 if (!w) return false;
6793
6795
6796 /* If we are about to wrap the focus chain, give the platform
6797 * implementation a chance to alter the wrapping behavior. This is
6798 * especially needed when the window is embedded in a window created by
6799 * another process.
6800 */
6801 if (wrappingOccurred) {
6803 if (window != nullptr) {
6805
6806 if (winp->platformWindow != nullptr) {
6808 event.ignore();
6809 winp->platformWindow->windowEvent(&event);
6810 if (event.isAccepted()) return true;
6811 }
6812 }
6813 }
6814
6815 w->setFocus(reason);
6816 return true;
6817}
6818
6829{
6830 return const_cast<QWidget *>(d_func()->focus_child);
6831}
6832
6834{
6835 Q_Q(QWidget);
6837 return proxy ? proxy : q;
6838}
6839
6846{
6847 Q_D(const QWidget);
6848 return d->nextPrevElementInFocusChain(QWidgetPrivate::FocusDirection::Next);
6849}
6850
6860{
6861 Q_D(const QWidget);
6862 return d->nextPrevElementInFocusChain(QWidgetPrivate::FocusDirection::Previous);
6863}
6864
6881{
6882 QWidget *tlw = window();
6883 if (tlw == QApplication::activeWindow() || (isVisible() && (tlw->windowType() == Qt::Popup)))
6884 return true;
6885
6886#if QT_CONFIG(graphicsview)
6887 if (const auto &tlwExtra = tlw->d_func()->extra) {
6888 if (isVisible() && tlwExtra->proxyWidget)
6889 return tlwExtra->proxyWidget->isActiveWindow();
6890 }
6891#endif
6892
6893 if (style()->styleHint(QStyle::SH_Widget_ShareActivation, nullptr, this)) {
6894 if (tlw->windowType() == Qt::Tool &&
6895 !tlw->isModal() &&
6896 (!tlw->parentWidget() || tlw->parentWidget()->isActiveWindow()))
6897 return true;
6899 while(w && tlw->windowType() == Qt::Tool &&
6900 !w->isModal() && w->parentWidget()) {
6901 w = w->parentWidget()->window();
6902 if (w == tlw)
6903 return true;
6904 }
6905 }
6906
6907 // Check for an active window container
6909 while (ww) {
6910 QWidgetWindow *qww = qobject_cast<QWidgetWindow *>(ww);
6911 QWindowContainer *qwc = qww ? qobject_cast<QWindowContainer *>(qww->widget()) : 0;
6912 if (qwc && qwc->topLevelWidget() == tlw)
6913 return true;
6914 ww = ww->parent();
6915 }
6916 }
6917
6918 // Check if platform adaptation thinks the window is active. This is necessary for
6919 // example in case of ActiveQt servers that are embedded into another application.
6920 // Those are separate processes that are not part of the parent application Qt window/widget
6921 // hierarchy, so they need to rely on native methods to determine if they are part of the
6922 // active window.
6923 if (const QWindow *w = tlw->windowHandle()) {
6924 if (w->handle())
6925 return w->handle()->isActive();
6926 }
6927
6928 return false;
6929}
6930
6982{
6983 if (!first || !second || first == second
6985 || second->focusPolicy() == Qt::NoFocus)
6986 return;
6987
6988 if (Q_UNLIKELY(first->window() != second->window())) {
6989 qWarning("QWidget::setTabOrder: 'first' and 'second' must be in the same window");
6990 return;
6991 }
6992
6993 const auto determineLastFocusChild = [](QWidget *target, QWidget *noFurtherThan)
6994 {
6995 // Since we need to repeat the same logic for both 'first' and 'second', we add a function that
6996 // determines the last focus child for a widget, taking proxies and compound widgets into account.
6997 // If the target is not a compound widget (it doesn't have a focus proxy that points to a child),
6998 // 'lastFocusChild' will be set to the target itself.
6999 QWidget *lastFocusChild = target;
7000
7001 QWidget *focusProxy = target->d_func()->deepestFocusProxy();
7002 if (!focusProxy) {
7003 // QTBUG-81097: Another case is possible here. We can have a child
7004 // widget, that sets its focusProxy() to the parent (target).
7005 // An example of such widget is a QLineEdit, nested into
7006 // a QAbstractSpinBox. In this case such widget should be considered
7007 // the last focus child.
7008 for (auto *object : target->children()) {
7009 QWidget *w = qobject_cast<QWidget*>(object);
7010 if (w && w->focusProxy() == target) {
7011 lastFocusChild = w;
7012 break;
7013 }
7014 }
7015 } else if (target->isAncestorOf(focusProxy)) {
7016 lastFocusChild = focusProxy;
7017 for (QWidget *focusNext = lastFocusChild->nextInFocusChain();
7018 focusNext != focusProxy && target->isAncestorOf(focusNext) && focusNext->window() == focusProxy->window();
7019 focusNext = focusNext->nextInFocusChain()) {
7020 if (focusNext == noFurtherThan)
7021 break;
7022 if (focusNext->focusPolicy() != Qt::NoFocus)
7023 lastFocusChild = focusNext;
7024 }
7025 }
7026 return lastFocusChild;
7027 };
7028 // detect inflection in case we have compound widgets
7029 QWidget *lastFocusChildOfFirst = determineLastFocusChild(first, second);
7030 if (lastFocusChildOfFirst == second)
7031 lastFocusChildOfFirst = first;
7032 QWidget *lastFocusChildOfSecond = determineLastFocusChild(second, first);
7033 if (lastFocusChildOfSecond == first)
7034 lastFocusChildOfSecond = second;
7035
7036 // Return if only NoFocus widgets are between first and second
7037 QWidget *oldPrev = second->previousInFocusChain();
7038 QWidget *prevWithFocus = oldPrev;
7039 while (prevWithFocus->focusPolicy() == Qt::NoFocus)
7040 prevWithFocus = prevWithFocus->previousInFocusChain();
7041 if (prevWithFocus == first)
7042 return;
7043 const QWidgetList chain = QWidgetPrivate::takeFromFocusChain(second, lastFocusChildOfSecond);
7045}
7046
7047void QWidget::setTabOrder(std::initializer_list<QWidget *> widgets)
7048{
7049 QWidget *prev = nullptr;
7050 for (const auto &widget : widgets) {
7051 if (!prev) {
7052 prev = widget;
7053 } else {
7055 prev = widget;
7056 }
7057 }
7058}
7059
7060
7074{
7075 Q_Q(QWidget);
7076 if (oldtlw == q->window())
7077 return; // nothing to do
7078
7079 if (focus_child)
7081
7084}
7085
7094{
7095 Q_D(const QWidget);
7096 if (isWindow() && !(windowType() == Qt::Popup)) {
7097 QRect fs = d->frameStrut();
7098 return QSize(data->crect.width() + fs.left() + fs.right(),
7099 data->crect.height() + fs.top() + fs.bottom());
7100 }
7101 return data->crect.size();
7102}
7103
7112{
7113 Q_D(QWidget);
7116 if (isWindow())
7117 d->topData()->posIncludesFrame = false;
7118 d->setGeometry_sys(p.x() + geometry().x() - QWidget::x(),
7119 p.y() + geometry().y() - QWidget::y(),
7120 width(), height(), true);
7121 d->setDirtyOpaqueRegion();
7122 } else {
7123 // no frame yet: see also QWidgetPrivate::fixPosIncludesFrame(), QWindowPrivate::PositionPolicy.
7124 if (isWindow())
7125 d->topData()->posIncludesFrame = true;
7126 data->crect.moveTopLeft(p); // no frame yet
7128 }
7129
7130 if (d->extra && d->extra->hasWindowContainer)
7132}
7133
7134// move() was invoked with Qt::WA_WState_Created not set (frame geometry
7135// unknown), that is, crect has a position including the frame.
7136// If we can determine the frame strut, fix that and clear the flag.
7137// FIXME: This does not play well with window states other than
7138// Qt::WindowNoState, as we depend on calling setGeometry() on the
7139// platform window after fixing up the position so that the new
7140// geometry is reflected in the platform window, but when the frame
7141// comes in after the window has been shown (e.g. maximized), we're
7142// not in a position to do that kind of fixup.
7144{
7145 Q_Q(QWidget);
7146 if (QTLWExtra *te = maybeTopData()) {
7147 if (te->posIncludesFrame) {
7148 // For Qt::WA_DontShowOnScreen, assume a frame of 0 (for
7149 // example, in QGraphicsProxyWidget).
7150 if (q->testAttribute(Qt::WA_DontShowOnScreen)) {
7151 te->posIncludesFrame = 0;
7152 } else {
7153 if (q->windowHandle() && q->windowHandle()->handle()) {
7155 if (!q->data->fstrut_dirty) {
7156 data.crect.translate(te->frameStrut.x(), te->frameStrut.y());
7157 te->posIncludesFrame = 0;
7158 }
7159 } // windowHandle()
7160 } // !WA_DontShowOnScreen
7161 } // posIncludesFrame
7162 } // QTLWExtra
7163}
7164
7172{
7173 Q_D(QWidget);
7176 d->fixPosIncludesFrame();
7177 d->setGeometry_sys(geometry().x(), geometry().y(), s.width(), s.height(), false);
7178 d->setDirtyOpaqueRegion();
7179 } else {
7180 const auto oldRect = data->crect;
7181 data->crect.setSize(s.boundedTo(maximumSize()).expandedTo(minimumSize()));
7182 if (oldRect != data->crect)
7184 }
7185}
7186
7188{
7189 Q_D(QWidget);
7192 if (isWindow())
7193 d->topData()->posIncludesFrame = 0;
7195 d->setGeometry_sys(r.x(), r.y(), r.width(), r.height(), true);
7196 d->setDirtyOpaqueRegion();
7197 } else {
7198 const auto oldRect = data->crect;
7199 data->crect.setTopLeft(r.topLeft());
7200 data->crect.setSize(r.size().boundedTo(maximumSize()).expandedTo(minimumSize()));
7201 if (oldRect != data->crect) {
7204 }
7205 }
7206
7207 if (d->extra && d->extra->hasWindowContainer)
7209}
7210
7211void QWidgetPrivate::setGeometry_sys(int x, int y, int w, int h, bool isMove)
7212{
7213 Q_Q(QWidget);
7214 if (extra) { // any size restrictions?
7215 w = qMin(w,extra->maxw);
7216 h = qMin(h,extra->maxh);
7217 w = qMax(w,extra->minw);
7218 h = qMax(h,extra->minh);
7219 }
7220
7221 if (q->isWindow() && q->windowHandle()) {
7224 x = 0;
7225 y = 0;
7226 w = q->windowHandle()->width();
7227 h = q->windowHandle()->height();
7228 }
7229 }
7230
7231 QPoint oldp = q->geometry().topLeft();
7232 QSize olds = q->size();
7233 QRect r(x, y, w, h);
7234
7235 bool isResize = olds != r.size();
7236 if (!isMove)
7237 isMove = oldp != r.topLeft();
7238
7239
7240 // We only care about stuff that changes the geometry, or may
7241 // cause the window manager to change its state
7242 if (r.size() == olds && oldp == r.topLeft())
7243 return;
7244
7245 if (!data.in_set_window_state) {
7246 q->data->window_state &= ~Qt::WindowMaximized;
7247 q->data->window_state &= ~Qt::WindowFullScreen;
7248 if (q->isWindow())
7249 topData()->normalGeometry = QRect(0, 0, -1, -1);
7250 }
7251
7252 QPoint oldPos = q->pos();
7253 data.crect = r;
7254
7255 bool needsShow = false;
7256
7257 if (q->isWindow() || q->windowHandle()) {
7258 if (!(data.window_state & Qt::WindowFullScreen) && (w == 0 || h == 0)) {
7259 q->setAttribute(Qt::WA_OutsideWSRange, true);
7260 if (q->isVisible())
7261 hide_sys();
7262 data.crect = QRect(x, y, w, h);
7263 } else if (q->testAttribute(Qt::WA_OutsideWSRange)) {
7264 q->setAttribute(Qt::WA_OutsideWSRange, false);
7265 needsShow = true;
7266 }
7267 }
7268
7269 if (q->isVisible()) {
7270 if (!q->testAttribute(Qt::WA_DontShowOnScreen) && !q->testAttribute(Qt::WA_OutsideWSRange)) {
7271 if (QWindow *win = q->windowHandle()) {
7272 if (q->isWindow()) {
7273 if (isResize && !isMove)
7274 win->resize(w, h);
7275 else if (isMove && !isResize)
7276 win->setPosition(x, y);
7277 else
7278 win->setGeometry(q->geometry());
7279 } else {
7280 QPoint posInNativeParent = q->mapTo(q->nativeParentWidget(),QPoint());
7281 win->setGeometry(QRect(posInNativeParent,r.size()));
7282 }
7283
7284 if (needsShow)
7285 show_sys();
7286 }
7287
7288 if (!q->isWindow()) {
7289 if (renderToTexture) {
7290 QRegion updateRegion(q->geometry());
7291 updateRegion += QRect(oldPos, olds);
7292 q->parentWidget()->d_func()->invalidateBackingStore(updateRegion);
7293 } else if (isMove && !isResize) {
7294 moveRect(QRect(oldPos, olds), x - oldPos.x(), y - oldPos.y());
7295 } else {
7297 }
7298 }
7299 }
7300
7301 if (isMove) {
7302 QMoveEvent e(q->pos(), oldPos);
7304 }
7305 if (isResize) {
7306 QResizeEvent e(r.size(), olds);
7308 if (q->windowHandle())
7309 q->update();
7310 }
7311 } else { // not visible
7312 if (isMove && q->pos() != oldPos)
7313 q->setAttribute(Qt::WA_PendingMoveEvent, true);
7314 if (isResize)
7315 q->setAttribute(Qt::WA_PendingResizeEvent, true);
7316 }
7317
7318}
7319
7338{
7341 stream.setVersion(QDataStream::Qt_4_0);
7342 const quint32 magicNumber = 0x1D9D0CB;
7343 // Version history:
7344 // - Qt 4.2 - 4.8.6, 5.0 - 5.3 : Version 1.0
7345 // - Qt 4.8.6 - today, 5.4 - today: Version 2.0, save screen width in addition to check for high DPI scaling.
7346 // - Qt 5.12 - today : Version 3.0, save QWidget::geometry()
7347 quint16 majorVersion = 3;
7348 quint16 minorVersion = 0;
7349 const int screenNumber = QGuiApplication::screens().indexOf(screen());
7350 stream << magicNumber
7351 << majorVersion
7352 << minorVersion
7353 << frameGeometry()
7354 << normalGeometry()
7355 << qint32(screenNumber)
7358 << qint32(screen()->geometry().width()) // added in 2.0
7359 << geometry(); // added in 3.0
7360 return array;
7361}
7362
7386void QWidgetPrivate::checkRestoredGeometry(const QRect &availableGeometry, QRect *restoredGeometry,
7387 int frameHeight)
7388{
7389 // compare with restored geometry's height increased by frameHeight
7390 const int height = restoredGeometry->height() + frameHeight;
7391
7392 // Step 1: Resize if necessary:
7393 // make height / width 2px smaller than screen, because an exact match would be fullscreen
7394 if (availableGeometry.height() <= height)
7395 restoredGeometry->setHeight(availableGeometry.height() - 2 - frameHeight);
7396 if (availableGeometry.width() <= restoredGeometry->width())
7397 restoredGeometry->setWidth(availableGeometry.width() - 2);
7398
7399 // Step 2: Move if necessary:
7400 // Construct a rectangle from restored Geometry adjusted by frameHeight
7401 const QRect restored = restoredGeometry->adjusted(0, -frameHeight, 0, 0);
7402
7403 // Return if restoredGeometry (including frame) fits into screen
7404 if (availableGeometry.contains(restored))
7405 return;
7406
7407 // (size is correct, but at least one edge is off screen)
7408
7409 // Top out of bounds => move down
7410 if (restored.top() <= availableGeometry.top()) {
7411 restoredGeometry->moveTop(availableGeometry.top() + 1 + frameHeight);
7412 } else if (restored.bottom() >= availableGeometry.bottom()) {
7413 // Bottom out of bounds => move up
7414 restoredGeometry->moveBottom(availableGeometry.bottom() - 1);
7415 }
7416
7417 // Left edge out of bounds => move right
7418 if (restored.left() <= availableGeometry.left()) {
7419 restoredGeometry->moveLeft(availableGeometry.left() + 1);
7420 } else if (restored.right() >= availableGeometry.right()) {
7421 // Right edge out of bounds => move left
7422 restoredGeometry->moveRight(availableGeometry.right() - 1);
7423 }
7424}
7425
7450{
7451 if (geometry.size() < 4)
7452 return false;
7454 stream.setVersion(QDataStream::Qt_4_0);
7455
7456 const quint32 magicNumber = 0x1D9D0CB;
7457 quint32 storedMagicNumber;
7458 stream >> storedMagicNumber;
7459 if (storedMagicNumber != magicNumber)
7460 return false;
7461
7462 const quint16 currentMajorVersion = 3;
7463 quint16 majorVersion = 0;
7464 quint16 minorVersion = 0;
7465
7466 stream >> majorVersion >> minorVersion;
7467
7468 if (majorVersion > currentMajorVersion)
7469 return false;
7470 // (Allow all minor versions.)
7471
7472 QRect restoredFrameGeometry;
7473 QRect restoredGeometry;
7474 QRect restoredNormalGeometry;
7475 qint32 restoredScreenNumber;
7478 qint32 restoredScreenWidth = 0;
7479
7480 stream >> restoredFrameGeometry // Only used for sanity checks in version 0
7481 >> restoredNormalGeometry
7482 >> restoredScreenNumber
7483 >> maximized
7484 >> fullScreen;
7485
7486 if (majorVersion > 1)
7487 stream >> restoredScreenWidth;
7488 if (majorVersion > 2)
7489 stream >> restoredGeometry;
7490
7491 // ### Qt 6 - Perhaps it makes sense to dumb down the restoreGeometry() logic, see QTBUG-69104
7492
7493 if (restoredScreenNumber >= qMax(QGuiApplication::screens().size(), 1))
7494 restoredScreenNumber = 0;
7495 const QScreen *restoredScreen = QGuiApplication::screens().value(restoredScreenNumber, nullptr);
7496 const qreal screenWidthF = restoredScreen ? qreal(restoredScreen->geometry().width()) : 0;
7497 // Sanity check bailing out when large variations of screen sizes occur due to
7498 // high DPI scaling or different levels of DPI awareness.
7499 if (restoredScreenWidth) {
7500 const qreal factor = qreal(restoredScreenWidth) / screenWidthF;
7501 if (factor < 0.8 || factor > 1.25)
7502 return false;
7503 } else {
7504 // Saved by Qt 5.3 and earlier, try to prevent too large windows
7505 // unless the size will be adapted by maximized or fullscreen.
7506 if (!maximized && !fullScreen && qreal(restoredFrameGeometry.width()) / screenWidthF > 1.5)
7507 return false;
7508 }
7509
7510 const int frameHeight = QApplication::style()
7511 ? QApplication::style()->pixelMetric(QStyle::PM_TitleBarHeight, nullptr, this)
7512 : 20;
7513
7514 if (!restoredNormalGeometry.isValid())
7515 restoredNormalGeometry = QRect(QPoint(0, frameHeight), sizeHint());
7516 if (!restoredNormalGeometry.isValid()) {
7517 // use the widget's adjustedSize if the sizeHint() doesn't help
7518 restoredNormalGeometry.setSize(restoredNormalGeometry
7519 .size()
7520 .expandedTo(d_func()->adjustedSize()));
7521 }
7522
7523 const QRect availableGeometry = restoredScreen ? restoredScreen->availableGeometry()
7524 : QRect();
7525
7526 // Modify the restored geometry if we are about to restore to coordinates
7527 // that would make the window "lost". This happens if:
7528 // - The restored geometry is completely or partly oustside the available geometry
7529 // - The title bar is outside the available geometry.
7530
7531 QWidgetPrivate::checkRestoredGeometry(availableGeometry, &restoredGeometry, frameHeight);
7532 QWidgetPrivate::checkRestoredGeometry(availableGeometry, &restoredNormalGeometry, frameHeight);
7533
7534 if (maximized || fullScreen) {
7535 // set geometry before setting the window state to make
7536 // sure the window is maximized to the right screen.
7537 Qt::WindowStates ws = windowState();
7538#ifndef Q_OS_WIN
7539 setGeometry(restoredNormalGeometry);
7540#else
7541 if (ws & Qt::WindowFullScreen) {
7542 // Full screen is not a real window state on Windows.
7543 move(availableGeometry.topLeft());
7544 } else if (ws & Qt::WindowMaximized) {
7545 // Setting a geometry on an already maximized window causes this to be
7546 // restored into a broken, half-maximized state, non-resizable state (QTBUG-4397).
7547 // Move the window in normal state if needed.
7548 if (restoredScreen != screen()) {
7550 setGeometry(restoredNormalGeometry);
7551 }
7552 } else {
7553 setGeometry(restoredNormalGeometry);
7554 }
7555#endif // Q_OS_WIN
7556 if (maximized)
7557 ws |= Qt::WindowMaximized;
7558 if (fullScreen)
7560 setWindowState(ws);
7561 d_func()->topData()->normalGeometry = restoredNormalGeometry;
7562 } else {
7564
7565 // FIXME: Why fall back to restoredNormalGeometry if majorVersion <= 2?
7566 if (majorVersion > 2)
7567 setGeometry(restoredGeometry);
7568 else
7569 setGeometry(restoredNormalGeometry);
7570 }
7571 return true;
7572}
7573
7591{
7592 Q_D(QWidget);
7593 if (left == d->leftmargin && top == d->topmargin
7594 && right == d->rightmargin && bottom == d->bottommargin)
7595 return;
7596 d->leftmargin = left;
7597 d->topmargin = top;
7598 d->rightmargin = right;
7599 d->bottommargin = bottom;
7600
7601 d->updateContentsRect();
7602}
7603
7621{
7622 setContentsMargins(margins.left(), margins.top(),
7623 margins.right(), margins.bottom());
7624}
7625
7627{
7628 Q_Q(QWidget);
7629
7630 if (layout)
7631 layout->update(); //force activate; will do updateGeometry
7632 else
7633 q->updateGeometry();
7634
7635 if (q->isVisible()) {
7636 q->update();
7637 QResizeEvent e(q->data->crect.size(), q->data->crect.size());
7639 } else {
7640 q->setAttribute(Qt::WA_PendingResizeEvent, true);
7641 }
7642
7645}
7646
7655{
7656 Q_D(const QWidget);
7657 QMargins userMargins(d->leftmargin, d->topmargin, d->rightmargin, d->bottommargin);
7659 userMargins | d->safeAreaMargins() : userMargins;
7660}
7661
7668{
7669 return rect() - contentsMargins();
7670}
7671
7673{
7674 Q_Q(const QWidget);
7675 QWidget *nativeWidget = q->window();
7676 if (!nativeWidget->windowHandle())
7677 return QMargins();
7678
7679 QPlatformWindow *platformWindow = nativeWidget->windowHandle()->handle();
7680 if (!platformWindow)
7681 return QMargins();
7682
7683 QMargins safeAreaMargins = platformWindow->safeAreaMargins();
7684
7685 if (!q->isWindow()) {
7686 // In theory the native parent widget already has a contents rect reflecting
7687 // the safe area of that widget, but we can't be sure that the widget or child
7688 // widgets of that widget have respected the contents rect when setting their
7689 // geometry, so we need to manually compute the safe area.
7690
7691 // Unless the native widget doesn't have any margins, in which case there's
7692 // nothing for us to compute.
7693 if (safeAreaMargins.isNull())
7694 return QMargins();
7695
7696 // Or, if one of our ancestors are in a layout that does not have WA_LayoutOnEntireRect
7697 // set, and the widget respects the safe area, then we know that the layout has already
7698 // taken care of placing us inside the safe area, by taking the contents rect of its
7699 // parent widget into account.
7700 const QWidget *assumedSafeWidget = nullptr;
7701 for (const QWidget *w = q; w != nativeWidget; w = w->parentWidget()) {
7702 QWidget *parentWidget = w->parentWidget();
7704 continue; // Layout can't help us
7705
7706 if (parentWidget->testAttribute(Qt::WA_LayoutOnEntireRect))
7707 continue; // Layout not going to help us
7708
7709 QLayout *layout = parentWidget->layout();
7710 if (!layout)
7711 continue;
7712
7713 if (layout->geometry().isNull())
7714 continue; // Layout hasn't been activated yet
7715
7716 if (layout->indexOf(w) < 0)
7717 continue; // Widget is not in layout
7718
7719 assumedSafeWidget = w;
7720 break;
7721 }
7722
7723#if !defined(QT_DEBUG)
7724 if (assumedSafeWidget) {
7725 // We found a layout that we assume will take care of keeping us within the safe area
7726 // For debug builds we still map the safe area using the fallback logic, so that we
7727 // can detect any misbehaving layouts.
7728 return QMargins();
7729 }
7730#endif
7731
7732 // In all other cases we need to map the safe area of the native parent to the widget.
7733 // This depends on the widget being positioned and sized already, which means the initial
7734 // layout will be wrong, but the layout will then adjust itself.
7735 QPoint topLeftMargins = q->mapFrom(nativeWidget, QPoint(safeAreaMargins.left(), safeAreaMargins.top()));
7736 QRect widgetRect = q->isVisible() ? q->visibleRegion().boundingRect() : q->rect();
7737 QPoint bottomRightMargins = widgetRect.bottomRight() - q->mapFrom(nativeWidget,
7738 nativeWidget->rect().bottomRight() - QPoint(safeAreaMargins.right(), safeAreaMargins.bottom()));
7739
7740 // Margins should never be negative
7741 safeAreaMargins = QMargins(qMax(0, topLeftMargins.x()), qMax(0, topLeftMargins.y()),
7742 qMax(0, bottomRightMargins.x()), qMax(0, bottomRightMargins.y()));
7743
7744 if (!safeAreaMargins.isNull() && assumedSafeWidget) {
7745 QLayout *layout = assumedSafeWidget->parentWidget()->layout();
7746 qWarning() << layout << "is laying out" << assumedSafeWidget
7747 << "outside of the contents rect of" << layout->parentWidget();
7748 return QMargins(); // Return empty margin to visually highlight the error
7749 }
7750 }
7751
7752 return safeAreaMargins;
7753}
7754
7786{
7787 return (Qt::ContextMenuPolicy)data->context_menu_policy;
7788}
7789
7791{
7792 data->context_menu_policy = (uint) policy;
7793}
7794
7818{
7819 return (Qt::FocusPolicy)data->focus_policy;
7820}
7821
7823{
7824 data->focus_policy = (uint) policy;
7825 Q_D(QWidget);
7826 if (d->extra && d->extra->focus_proxy)
7827 d->extra->focus_proxy->setFocusPolicy(policy);
7828}
7829
7859{
7860 Q_D(QWidget);
7862 d->setUpdatesEnabled_helper(enable);
7863}
7864
7876{
7877 // Note: We don't call showNormal() as not to clobber Qt::Window(Max/Min)imized
7878
7879 if (!isWindow()) {
7880 setVisible(true);
7881 } else {
7882 const auto *platformIntegration = QGuiApplicationPrivate::platformIntegration();
7883 Qt::WindowState defaultState = platformIntegration->defaultWindowState(data->window_flags);
7884 if (defaultState == Qt::WindowFullScreen)
7886 else if (defaultState == Qt::WindowMaximized)
7887 showMaximized();
7888 else
7889 setVisible(true);
7890 }
7891}
7892
7899{
7900 Q_Q(QWidget);
7901 // polish if necessary
7902
7903 if (!q->testAttribute(Qt::WA_WState_Created))
7905 q->ensurePolished();
7906
7907 if (!q->isWindow() && q->parentWidget()->d_func()->layout && !q->parentWidget()->data->in_show)
7908 q->parentWidget()->d_func()->layout->activate();
7909 // activate our layout before we and our children become visible
7910 if (layout)
7911 layout->activate();
7912
7913 show_helper();
7914}
7915
7916void QWidgetPrivate::sendPendingMoveAndResizeEvents(bool recursive, bool disableUpdates)
7917{
7918 Q_Q(QWidget);
7919
7920 disableUpdates = disableUpdates && q->updatesEnabled();
7921 if (disableUpdates)
7922 q->setAttribute(Qt::WA_UpdatesDisabled);
7923
7924 if (q->testAttribute(Qt::WA_PendingMoveEvent)) {
7925 QMoveEvent e(data.crect.topLeft(), data.crect.topLeft());
7927 q->setAttribute(Qt::WA_PendingMoveEvent, false);
7928 }
7929
7930 if (q->testAttribute(Qt::WA_PendingResizeEvent)) {
7931 QResizeEvent e(data.crect.size(), QSize());
7933 q->setAttribute(Qt::WA_PendingResizeEvent, false);
7934 }
7935
7936 if (disableUpdates)
7937 q->setAttribute(Qt::WA_UpdatesDisabled, false);
7938
7939 if (!recursive)
7940 return;
7941
7942 for (int i = 0; i < children.size(); ++i) {
7943 if (QWidget *child = qobject_cast<QWidget *>(children.at(i)))
7944 child->d_func()->sendPendingMoveAndResizeEvents(recursive, disableUpdates);
7945 }
7946}
7947
7949{
7950 sendPendingMoveAndResizeEvents(false, true);
7951
7952 for (int i = 0; i < children.size(); ++i) {
7954 if (!child || child->isHidden() || child->isWindow())
7955 continue;
7956
7957 child->ensurePolished();
7958
7959 // Activate child's layout
7960 QWidgetPrivate *childPrivate = child->d_func();
7961 if (childPrivate->layout)
7962 childPrivate->layout->activate();
7963
7964 // Pretend we're visible.
7965 const bool wasVisible = child->isVisible();
7966 if (!wasVisible)
7967 child->setAttribute(Qt::WA_WState_Visible);
7968
7969 // Do the same for all my children.
7970 childPrivate->activateChildLayoutsRecursively();
7971
7972 // We're not cheating anymore.
7973 if (!wasVisible)
7974 child->setAttribute(Qt::WA_WState_Visible, false);
7975 }
7976}
7977
7979{
7980 Q_Q(QWidget);
7981 data.in_show = true; // qws optimization
7982 // make sure we receive pending move and resize events
7984
7985 // become visible before showing all children
7986 q->setAttribute(Qt::WA_WState_Visible);
7987
7988 // finally show all children recursively
7989 showChildren(false);
7990
7991
7992
7993 const bool isWindow = q->isWindow();
7994#if QT_CONFIG(graphicsview)
7995 bool isEmbedded = isWindow && q->graphicsProxyWidget() != nullptr;
7996#else
7997 bool isEmbedded = false;
7998#endif
7999
8000 // popup handling: new popups and tools need to be raised, and
8001 // existing popups must be closed. Also propagate the current
8002 // windows's KeyboardFocusChange status.
8003 if (isWindow && !isEmbedded) {
8004 if ((q->windowType() == Qt::Tool) || (q->windowType() == Qt::Popup) || q->windowType() == Qt::ToolTip) {
8005 q->raise();
8006 if (q->parentWidget() && q->parentWidget()->window()->testAttribute(Qt::WA_KeyboardFocusChange))
8007 q->setAttribute(Qt::WA_KeyboardFocusChange);
8008 } else {
8011 break;
8012 }
8013 }
8014 }
8015
8016 // Automatic embedding of child windows of widgets already embedded into
8017 // QGraphicsProxyWidget when they are shown the first time.
8018#if QT_CONFIG(graphicsview)
8019 if (isWindow) {
8021 QGraphicsProxyWidget *ancestorProxy = nearestGraphicsProxyWidget(q->parentWidget());
8022 if (ancestorProxy) {
8023 isEmbedded = true;
8024 ancestorProxy->d_func()->embedSubWindow(q);
8025 }
8026 }
8027 }
8028#else
8030#endif
8031
8032 // send the show event before showing the window
8033 QShowEvent showEvent;
8034 QCoreApplication::sendEvent(q, &showEvent);
8035
8036 show_sys();
8037
8038 if (!isEmbedded && q->windowType() == Qt::Popup)
8039 qApp->d_func()->openPopup(q);
8040
8041#if QT_CONFIG(accessibility)
8042 if (q->windowType() != Qt::ToolTip) { // Tooltips are read aloud twice in MS narrator.
8043 QAccessibleEvent event(q, QAccessible::ObjectShow);
8044 QAccessible::updateAccessibility(&event);
8045 }
8046#endif
8047
8050 q->setFocus(Qt::OtherFocusReason);
8051 }
8052
8053 // Process events when showing a Qt::SplashScreen widget before the event loop
8054 // is spinnning; otherwise it might not show up on particular platforms.
8055 // This makes QSplashScreen behave the same on all platforms.
8056 if (!qApp->d_func()->in_exec && q->windowType() == Qt::SplashScreen)
8058
8059 data.in_show = false; // reset qws optimization
8060}
8061
8063{
8064 Q_Q(QWidget);
8065
8066 auto window = qobject_cast<QWidgetWindow *>(windowHandle());
8067
8068 if (q->testAttribute(Qt::WA_DontShowOnScreen)) {
8069 invalidateBackingStore(q->rect());
8070 q->setAttribute(Qt::WA_Mapped);
8071 // add our window the modal window list (native dialogs)
8072 if (window && q->isWindow()
8073#if QT_CONFIG(graphicsview)
8074 && (!extra || !extra->proxyWidget)
8075#endif
8076 && q->windowModality() != Qt::NonModal) {
8078 }
8079 return;
8080 }
8081
8082 if (renderToTexture && !q->isWindow())
8083 QCoreApplication::postEvent(q->parentWidget(), new QUpdateLaterEvent(q->geometry()));
8084 else
8086
8087 if ((!q->isWindow() && !q->testAttribute(Qt::WA_NativeWindow))
8088 || q->testAttribute(Qt::WA_OutsideWSRange)) {
8089 return;
8090 }
8091
8092 if (window) {
8093 if (q->isWindow())
8095 QRect geomRect = q->geometry();
8096 if (!q->isWindow()) {
8097 QPoint topLeftOfWindow = q->mapTo(q->nativeParentWidget(),QPoint());
8098 geomRect.moveTopLeft(topLeftOfWindow);
8099 }
8100 const QRect windowRect = window->geometry();
8101 if (windowRect != geomRect) {
8102 if (q->testAttribute(Qt::WA_Moved)
8104 window->setGeometry(geomRect);
8105 else
8106 window->resize(geomRect.size());
8107 }
8108
8109#ifndef QT_NO_CURSOR
8110 qt_qpa_set_cursor(q, false); // Needed in case cursor was set before show
8111#endif
8112 invalidateBackingStore(q->rect());
8113 window->setNativeWindowVisibility(true);
8114 // Was the window moved by the Window system or QPlatformWindow::initialGeometry() ?
8115 if (window->isTopLevel()) {
8116 const QPoint crectTopLeft = q->data->crect.topLeft();
8117 const QPoint windowTopLeft = window->geometry().topLeft();
8118 if (crectTopLeft == QPoint(0, 0) && windowTopLeft != crectTopLeft)
8119 q->data->crect.moveTopLeft(windowTopLeft);
8120 }
8121 }
8122}
8123
8136{
8137 setVisible(false);
8138}
8139
8143{
8144 Q_Q(QWidget);
8145
8146 bool isEmbedded = false;
8147#if QT_CONFIG(graphicsview)
8148 isEmbedded = q->isWindow() && !bypassGraphicsProxyWidget(q) && nearestGraphicsProxyWidget(q->parentWidget()) != nullptr;
8149#else
8151#endif
8152
8153 if (!isEmbedded && (q->windowType() == Qt::Popup))
8154 qApp->d_func()->closePopup(q);
8155
8156 q->setAttribute(Qt::WA_Mapped, false);
8157 hide_sys();
8158
8159 bool wasVisible = q->testAttribute(Qt::WA_WState_Visible);
8160
8161 if (wasVisible) {
8162 q->setAttribute(Qt::WA_WState_Visible, false);
8163
8164 }
8165
8166 QHideEvent hideEvent;
8167 QCoreApplication::sendEvent(q, &hideEvent);
8168 hideChildren(false);
8169
8170 // next bit tries to move the focus if the focus widget is now
8171 // hidden.
8172 if (wasVisible) {
8173 qApp->d_func()->sendSyntheticEnterLeave(q);
8175 while (fw && !fw->isWindow()) {
8176 if (fw == q) {
8177 q->focusNextPrevChild(true);
8178 break;
8179 }
8180 fw = fw->parentWidget();
8181 }
8182 }
8183
8184 if (QWidgetRepaintManager *repaintManager = maybeRepaintManager())
8185 repaintManager->removeDirtyWidget(q);
8186
8187#if QT_CONFIG(accessibility)
8188 if (wasVisible) {
8189 QAccessibleEvent event(q, QAccessible::ObjectHide);
8190 QAccessible::updateAccessibility(&event);
8191 }
8192#endif
8193}
8194
8196{
8197 Q_Q(QWidget);
8198
8199 auto window = qobject_cast<QWidgetWindow *>(windowHandle());
8200
8201 if (q->testAttribute(Qt::WA_DontShowOnScreen)) {
8202 q->setAttribute(Qt::WA_Mapped, false);
8203 // remove our window from the modal window list (native dialogs)
8204 if (window && q->isWindow()
8205#if QT_CONFIG(graphicsview)
8206 && (!extra || !extra->proxyWidget)
8207#endif
8208 && q->windowModality() != Qt::NonModal) {
8210 }
8211 // do not return here, if window non-zero, we must hide it
8212 }
8213
8215
8216 if (!q->isWindow()) {
8217 QWidget *p = q->parentWidget();
8218 if (p &&p->isVisible()) {
8219 if (renderToTexture)
8220 p->d_func()->invalidateBackingStore(q->geometry());
8221 else
8222 invalidateBackingStore(q->rect());
8223 }
8224 } else {
8225 invalidateBackingStore(q->rect());
8226 }
8227
8228 if (window)
8229 window->setNativeWindowVisibility(false);
8230}
8231
8255void QWidget::setVisible(bool visible)
8256{
8257 Q_D(QWidget);
8258 qCDebug(lcWidgetShowHide) << "Setting visibility of" << this
8259 << "with attributes" << WidgetAttributes{this}
8260 << "to" << visible << "via QWidget";
8261
8263 return;
8264
8265 // Remember that setVisible was called explicitly
8267
8268 d->setVisible(visible);
8269}
8270
8271// This method is called from QWidgetWindow in response to QWindow::setVisible,
8272// and should match the semantics of QWindow::setVisible. QWidget::setVisible on
8273// the other hand keeps track of WA_WState_ExplicitShowHide in addition.
8275{
8276 Q_Q(QWidget);
8277 qCDebug(lcWidgetShowHide) << "Setting visibility of" << q
8278 << "with attributes" << WidgetAttributes{q}
8279 << "to" << visible << "via QWidgetPrivate";
8280
8281 if (visible) { // show
8282 // Designer uses a trick to make grabWidget work without showing
8283 if (!q->isWindow() && q->parentWidget() && q->parentWidget()->isVisible()
8284 && !q->parentWidget()->testAttribute(Qt::WA_WState_Created))
8285 q->parentWidget()->window()->d_func()->createRecursively();
8286
8287 //create toplevels but not children of non-visible parents
8288 QWidget *pw = q->parentWidget();
8289 if (!q->testAttribute(Qt::WA_WState_Created)
8290 && (q->isWindow() || pw->testAttribute(Qt::WA_WState_Created))) {
8291 q->create();
8292 }
8293
8294 bool wasResized = q->testAttribute(Qt::WA_Resized);
8295 Qt::WindowStates initialWindowState = q->windowState();
8296
8297 // polish if necessary
8298 q->ensurePolished();
8299
8300 // whether we need to inform the parent widget immediately
8301 bool needUpdateGeometry = !q->isWindow() && q->testAttribute(Qt::WA_WState_Hidden);
8302 // we are no longer hidden
8303 q->setAttribute(Qt::WA_WState_Hidden, false);
8304
8305 if (needUpdateGeometry)
8307
8308 // activate our layout before we and our children become visible
8309 if (layout)
8310 layout->activate();
8311
8312 if (!q->isWindow()) {
8313 QWidget *parent = q->parentWidget();
8314 while (parent && parent->isVisible() && parent->d_func()->layout && !parent->data->in_show) {
8315 parent->d_func()->layout->activate();
8316 if (parent->isWindow())
8317 break;
8318 parent = parent->parentWidget();
8319 }
8320 if (parent)
8321 parent->d_func()->setDirtyOpaqueRegion();
8322 }
8323
8324 // adjust size if necessary
8325 if (!wasResized
8326 && (q->isWindow() || !q->parentWidget()->d_func()->layout)) {
8327 if (q->isWindow()) {
8328 q->adjustSize();
8329 if (q->windowState() != initialWindowState)
8330 q->setWindowState(initialWindowState);
8331 } else {
8332 q->adjustSize();
8333 }
8334 q->setAttribute(Qt::WA_Resized, false);
8335 }
8336
8337 q->setAttribute(Qt::WA_KeyboardFocusChange, false);
8338
8339 if (q->isWindow() || q->parentWidget()->isVisible()) {
8340 show_helper();
8341
8342 qApp->d_func()->sendSyntheticEnterLeave(q);
8343 }
8344
8345 QEvent showToParentEvent(QEvent::ShowToParent);
8346 QCoreApplication::sendEvent(q, &showToParentEvent);
8347 } else { // hide
8350
8351 // hw: The test on getOpaqueRegion() needs to be more intelligent
8352 // currently it doesn't work if the widget is hidden (the region will
8353 // be clipped). The real check should be testing the cached region
8354 // (and dirty flag) directly.
8355 if (!q->isWindow() && q->parentWidget()) // && !d->getOpaqueRegion().isEmpty())
8356 q->parentWidget()->d_func()->setDirtyOpaqueRegion();
8357
8358 if (!q->testAttribute(Qt::WA_WState_Hidden)) {
8359 q->setAttribute(Qt::WA_WState_Hidden);
8360 hide_helper();
8361 }
8362
8363 // invalidate layout similar to updateGeometry()
8364 if (!q->isWindow() && q->parentWidget()) {
8365 if (q->parentWidget()->d_func()->layout)
8366 q->parentWidget()->d_func()->layout->invalidate();
8367 else if (q->parentWidget()->isVisible())
8369 }
8370
8371 QEvent hideToParentEvent(QEvent::HideToParent);
8372 QCoreApplication::sendEvent(q, &hideToParentEvent);
8373 }
8374}
8375
8379void QWidget::setHidden(bool hidden)
8380{
8381 setVisible(!hidden);
8382}
8383
8385{
8386 Q_Q(const QWidget);
8387 return q->isHidden() && q->testAttribute(Qt::WA_WState_ExplicitShowHide);
8388}
8389
8391{
8392 Q_Q(QWidget);
8393 if (!isExplicitlyHidden())
8394 q->setVisible(true);
8395}
8396
8397void QWidgetPrivate::showChildren(bool spontaneous)
8398{
8399 Q_Q(QWidget);
8400 qCDebug(lcWidgetShowHide) << "Showing children of" << q
8401 << "spontaneously" << spontaneous;
8402
8403 QList<QObject*> childList = children;
8404 for (int i = 0; i < childList.size(); ++i) {
8405 QWidget *widget = qobject_cast<QWidget*>(childList.at(i));
8406 if (!widget)
8407 continue;
8408 qCDebug(lcWidgetShowHide) << "Considering" << widget
8409 << "with attributes" << WidgetAttributes{widget};
8413 continue;
8414 if (spontaneous) {
8416 widget->d_func()->showChildren(true);
8417 QShowEvent e;
8418 QApplication::sendSpontaneousEvent(widget, &e);
8419 } else {
8421 widget->d_func()->show_recursive();
8422 else
8423 widget->d_func()->setVisible(true);
8424 }
8425 }
8426}
8427
8428void QWidgetPrivate::hideChildren(bool spontaneous)
8429{
8430 Q_Q(QWidget);
8431 qCDebug(lcWidgetShowHide) << "Hiding children of" << q
8432 << "spontaneously" << spontaneous;
8433
8434 QList<QObject*> childList = children;
8435 for (int i = 0; i < childList.size(); ++i) {
8436 QWidget *widget = qobject_cast<QWidget*>(childList.at(i));
8437 if (!widget)
8438 continue;
8439 qCDebug(lcWidgetShowHide) << "Considering" << widget
8440 << "with attributes" << WidgetAttributes{widget};
8442 continue;
8443
8444 if (spontaneous)
8446 else
8448 widget->d_func()->hideChildren(spontaneous);
8449 QHideEvent e;
8450 if (spontaneous) {
8451 QApplication::sendSpontaneousEvent(widget, &e);
8452 } else {
8454 if (widget->internalWinId()
8456 // hide_sys() on an ancestor won't have any affect on this
8457 // widget, so it needs an explicit hide_sys() of its own
8458 widget->d_func()->hide_sys();
8459 }
8460 }
8461 qApp->d_func()->sendSyntheticEnterLeave(widget);
8462#if QT_CONFIG(accessibility)
8463 if (!spontaneous) {
8464 QAccessibleEvent event(widget, QAccessible::ObjectHide);
8465 QAccessible::updateAccessibility(&event);
8466 }
8467#endif
8468 }
8469
8470 // If the window of this widget is not closed, then the leave event
8471 // will eventually handle the widget under mouse use case.
8472 // Otherwise, we need to explicitly handle it here.
8473 if (QWidget* widgetWindow = q->window();
8474 widgetWindow && widgetWindow->data->is_closing) {
8475 q->setAttribute(Qt::WA_UnderMouse, false);
8476 }
8477}
8478
8498{
8499 Q_Q(QWidget);
8500 qCDebug(lcWidgetShowHide) << "Handling close event for" << q;
8501
8502 if (data.is_closing)
8503 return true;
8504
8505 // We might not have initiated the close, so update the state now that we know
8506 data.is_closing = true;
8507
8508 QPointer<QWidget> that = q;
8509
8510 if (data.in_destructor)
8512
8513 if (mode != CloseNoEvent) {
8514 QCloseEvent e;
8516 QApplication::sendSpontaneousEvent(q, &e);
8517 else
8519 if (!that.isNull() && !e.isAccepted()) {
8520 data.is_closing = false;
8521 return false;
8522 }
8523 }
8524
8525 // even for windows, make sure we deliver a hide event and that all children get hidden
8526 if (!that.isNull() && !q->isHidden())
8527 q->hide();
8528
8529 if (!that.isNull()) {
8530 data.is_closing = false;
8531 if (q->testAttribute(Qt::WA_DeleteOnClose)) {
8532 q->setAttribute(Qt::WA_DeleteOnClose, false);
8533 q->deleteLater();
8534 }
8535 }
8536 return true;
8537}
8538
8539
8563{
8564 return d_func()->close();
8565}
8566
8568{
8569 // FIXME: We're not setting is_closing here, even though that would
8570 // make sense, as the code below will not end up in handleClose to
8571 // reset is_closing when there's a QWindow, but no QPlatformWindow,
8572 // and we can't assume close is synchronous so we can't reset it here.
8573
8574 // Close native widgets via QWindow::close() in order to run QWindow
8575 // close code. The QWidget-specific close code in handleClose() will
8576 // in this case be called from the Close event handler in QWidgetWindow.
8577 if (QWindow *widgetWindow = windowHandle()) {
8578 if (widgetWindow->isTopLevel())
8579 return widgetWindow->close();
8580 }
8581
8583}
8584
8643bool QWidget::isVisibleTo(const QWidget *ancestor) const
8644{
8645 if (!ancestor)
8646 return isVisible();
8647 const QWidget * w = this;
8648 while (!w->isHidden()
8649 && !w->isWindow()
8650 && w->parentWidget()
8651 && w->parentWidget() != ancestor)
8652 w = w->parentWidget();
8653 return !w->isHidden();
8654}
8655
8656
8668{
8669 Q_D(const QWidget);
8670
8671 QRect clipRect = d->clipRect();
8672 if (clipRect.isEmpty())
8673 return QRegion();
8674 QRegion r(clipRect);
8675 d->subtractOpaqueChildren(r, clipRect);
8676 d->subtractOpaqueSiblings(r);
8677 return r;
8678}
8679
8680
8682{
8683 Q_Q(const QWidget);
8684
8685 QSize s = q->sizeHint();
8686
8687 if (q->isWindow()) {
8688 Qt::Orientations exp;
8689 if (layout) {
8692 exp = layout->expandingDirections();
8693 } else
8694 {
8695 if (q->sizePolicy().hasHeightForWidth())
8696 s.setHeight(q->heightForWidth(s.width()));
8697 exp = q->sizePolicy().expandingDirections();
8698 }
8699 if (exp & Qt::Horizontal)
8700 s.setWidth(qMax(s.width(), 200));
8701 if (exp & Qt::Vertical)
8702 s.setHeight(qMax(s.height(), 100));
8703
8704 QRect screen;
8705 if (const QScreen *screenAtPoint = QGuiApplication::screenAt(q->pos()))
8706 screen = screenAtPoint->geometry();
8707 else
8709
8710 s.setWidth(qMin(s.width(), screen.width()*2/3));
8711 s.setHeight(qMin(s.height(), screen.height()*2/3));
8712
8713 if (QTLWExtra *extra = maybeTopData())
8714 extra->sizeAdjusted = true;
8715 }
8716
8717 if (!s.isValid()) {
8718 QRect r = q->childrenRect(); // get children rectangle
8719 if (r.isNull())
8720 return s;
8721 s = r.size() + QSize(2 * r.x(), 2 * r.y());
8722 }
8723
8724 return s;
8725}
8726
8744{
8745 Q_D(QWidget);
8747 QSize s = d->adjustedSize();
8748
8749 if (d->layout)
8750 d->layout->activate();
8751
8752 if (s.isValid())
8753 resize(s);
8754}
8755
8756
8773{
8774 Q_D(const QWidget);
8775 if (d->layout)
8776 return d->layout->totalSizeHint();
8777 return QSize(-1, -1);
8778}
8779
8800{
8801 Q_D(const QWidget);
8802 if (d->layout)
8803 return d->layout->totalMinimumSize();
8804 return QSize(-1, -1);
8805}
8806
8807
8823{
8824 while (child) {
8825 if (child == this)
8826 return true;
8827 if (child->isWindow())
8828 return false;
8829 child = child->parentWidget();
8830 }
8831 return false;
8832}
8833
8834/*****************************************************************************
8835 QWidget event handling
8836 *****************************************************************************/
8837
8867{
8868 Q_D(QWidget);
8869
8870 // ignore mouse and key events when disabled
8871 if (!isEnabled()) {
8872 switch(event->type()) {
8875 case QEvent::TabletMove:
8879 case QEvent::MouseMove:
8880 case QEvent::TouchBegin:
8882 case QEvent::TouchEnd:
8885 case QEvent::KeyPress:
8886 case QEvent::KeyRelease:
8887#if QT_CONFIG(wheelevent)
8888 case QEvent::Wheel:
8889#endif
8890 return false;
8891 default:
8892 break;
8893 }
8894 }
8895 switch (event->type()) {
8897 // Sync up QWidget's view of whether or not the widget has been created
8898 switch (static_cast<QPlatformSurfaceEvent*>(event)->surfaceEventType()) {
8901 create();
8902 break;
8905 // Child windows have already been destroyed by QWindow,
8906 // so we skip them here.
8907 destroy(false, false);
8908 }
8909 break;
8910 }
8911 break;
8912 }
8913 case QEvent::MouseMove:
8915 break;
8916
8919 break;
8920
8923 break;
8924
8927 break;
8928#if QT_CONFIG(wheelevent)
8929 case QEvent::Wheel:
8930 wheelEvent((QWheelEvent*)event);
8931 break;
8932#endif
8933#if QT_CONFIG(tabletevent)
8934 case QEvent::TabletMove:
8935 if (static_cast<QTabletEvent *>(event)->buttons() == Qt::NoButton && !testAttribute(Qt::WA_TabletTracking))
8936 break;
8937 Q_FALLTHROUGH();
8940 tabletEvent((QTabletEvent*)event);
8941 break;
8942#endif
8943 case QEvent::KeyPress: {
8944 QKeyEvent *k = static_cast<QKeyEvent *>(event);
8945 bool res = false;
8946 if (!(k->modifiers() & (Qt::ControlModifier | Qt::AltModifier))) { //### Add MetaModifier?
8947 if (k->key() == Qt::Key_Backtab
8948 || (k->key() == Qt::Key_Tab && (k->modifiers() & Qt::ShiftModifier)))
8949 res = focusNextPrevChild(false);
8950 else if (k->key() == Qt::Key_Tab)
8951 res = focusNextPrevChild(true);
8952 if (res)
8953 break;
8954 }
8955 keyPressEvent(k);
8956#ifdef QT_KEYPAD_NAVIGATION
8957 if (!k->isAccepted() && QApplication::keypadNavigationEnabled()
8959 if (QApplication::navigationMode() == Qt::NavigationModeKeypadTabOrder) {
8960 if (k->key() == Qt::Key_Up)
8961 res = focusNextPrevChild(false);
8962 else if (k->key() == Qt::Key_Down)
8963 res = focusNextPrevChild(true);
8964 } else if (QApplication::navigationMode() == Qt::NavigationModeKeypadDirectional) {
8965 if (k->key() == Qt::Key_Up)
8966 res = QWidgetPrivate::navigateToDirection(QWidgetPrivate::DirectionNorth);
8967 else if (k->key() == Qt::Key_Right)
8968 res = QWidgetPrivate::navigateToDirection(QWidgetPrivate::DirectionEast);
8969 else if (k->key() == Qt::Key_Down)
8970 res = QWidgetPrivate::navigateToDirection(QWidgetPrivate::DirectionSouth);
8971 else if (k->key() == Qt::Key_Left)
8972 res = QWidgetPrivate::navigateToDirection(QWidgetPrivate::DirectionWest);
8973 }
8974 if (res) {
8975 k->accept();
8976 break;
8977 }
8978 }
8979#endif
8980#if QT_CONFIG(whatsthis)
8981 if (!k->isAccepted()
8982 && k->modifiers() & Qt::ShiftModifier && k->key() == Qt::Key_F1
8983 && d->whatsThis.size()) {
8984 QWhatsThis::showText(mapToGlobal(inputMethodQuery(Qt::ImCursorRectangle).toRect().center()), d->whatsThis, this);
8985 k->accept();
8986 }
8987#endif
8988 }
8989 break;
8990
8991 case QEvent::KeyRelease:
8993 Q_FALLTHROUGH();
8995 break;
8996
8999 break;
9000
9003 Qt::InputMethodQueries queries = query->queries();
9004 for (uint i = 0; i < 32; ++i) {
9005 Qt::InputMethodQuery q = (Qt::InputMethodQuery)(int)(queries & (1<<i));
9006 if (q) {
9008 if (q == Qt::ImEnabled && !v.isValid() && isEnabled()) {
9009 // Qt:ImEnabled was added in Qt 5.3. So not all widgets support it, even
9010 // if they implement IM otherwise (by overriding inputMethodQuery()). Instead
9011 // they set the widget attribute Qt::WA_InputMethodEnabled. But this attribute
9012 // will only be set if the widget supports IM _and_ is not read-only. So for
9013 // read-only widgets, not all IM features will be supported when ImEnabled is
9014 // not implemented explicitly (e.g selection handles for read-only widgets on iOS).
9016 }
9017 query->setValue(q, v);
9018 }
9019 }
9020 query->accept();
9021 }
9022 break;
9023
9026 break;
9027
9028 case QEvent::Polish: {
9029 style()->polish(this);
9031 if (!QApplication::font(this).isCopyOf(QApplication::font()))
9032 d->resolveFont();
9033 if (!QApplication::palette(this).isCopyOf(QGuiApplication::palette()))
9034 d->resolvePalette();
9035 }
9036 break;
9037
9040 d->setWindowIcon_sys();
9041 d->setWindowIcon_helper();
9042 }
9043 break;
9044 case QEvent::FocusIn:
9046 d->updateWidgetTransform(event);
9047 break;
9048
9049 case QEvent::FocusOut:
9051 break;
9052
9053 case QEvent::Enter:
9054#if QT_CONFIG(statustip)
9055 if (d->statusTip.size()) {
9056 QStatusTipEvent tip(d->statusTip);
9057 QCoreApplication::sendEvent(const_cast<QWidget *>(this), &tip);
9058 }
9059#endif
9060 enterEvent(static_cast<QEnterEvent*>(event));
9061 break;
9062
9063 case QEvent::Leave:
9064#if QT_CONFIG(statustip)
9065 if (d->statusTip.size()) {
9066 QString empty;
9067 QStatusTipEvent tip(empty);
9068 QCoreApplication::sendEvent(const_cast<QWidget *>(this), &tip);
9069 }
9070#endif
9072 break;
9073
9074 case QEvent::HoverEnter:
9075 case QEvent::HoverLeave:
9076 update();
9077 break;
9078
9079 case QEvent::Paint:
9080 // At this point the event has to be delivered, regardless
9081 // whether the widget isVisible() or not because it
9082 // already went through the filters
9084 break;
9085
9086 case QEvent::Move:
9088 d->updateWidgetTransform(event);
9089 break;
9090
9091 case QEvent::Resize:
9093 d->updateWidgetTransform(event);
9094 break;
9095
9096 case QEvent::Close:
9098 break;
9099
9100#ifndef QT_NO_CONTEXTMENU
9102 switch (data->context_menu_policy) {
9104 break;
9106 contextMenuEvent(static_cast<QContextMenuEvent *>(event));
9107 break;
9110 break;
9111#if QT_CONFIG(menu)
9113 if (d->actions.size()) {
9114 QMenu::exec(d->actions, static_cast<QContextMenuEvent *>(event)->globalPos(),
9115 nullptr, this);
9116 break;
9117 }
9118 Q_FALLTHROUGH();
9119#endif
9120 default:
9121 event->ignore();
9122 break;
9123 }
9124 break;
9125#endif // QT_NO_CONTEXTMENU
9126
9127#if QT_CONFIG(draganddrop)
9128 case QEvent::Drop:
9129 dropEvent((QDropEvent*) event);
9130 break;
9131
9132 case QEvent::DragEnter:
9133 dragEnterEvent((QDragEnterEvent*) event);
9134 break;
9135
9136 case QEvent::DragMove:
9137 dragMoveEvent((QDragMoveEvent*) event);
9138 break;
9139
9140 case QEvent::DragLeave:
9141 dragLeaveEvent((QDragLeaveEvent*) event);
9142 break;
9143#endif
9144
9145 case QEvent::Show:
9147 break;
9148
9149 case QEvent::Hide:
9151 break;
9152
9154 if (!isHidden())
9155 d->show_sys();
9156 break;
9157
9159 d->resolveFont();
9160 break;
9162 if (!(windowType() == Qt::Desktop))
9163 d->resolvePalette();
9164 break;
9165
9169 case QEvent::FontChange:
9184 break;
9185
9187 const bool wasMinimized = static_cast<const QWindowStateChangeEvent *>(event)->oldState() & Qt::WindowMinimized;
9188 if (wasMinimized != isMinimized()) {
9189 QWidget *widget = const_cast<QWidget *>(this);
9190 if (wasMinimized) {
9191 // Always send the spontaneous events here, otherwise it can break the application!
9192 if (!d->childrenShownByExpose) {
9193 // Show widgets only when they are not yet shown by the expose event
9194 d->showChildren(true);
9196 QCoreApplication::sendSpontaneousEvent(widget, &showEvent);
9197 }
9198 d->childrenHiddenByWState = false; // Set it always to "false" when window is restored
9199 } else {
9201 QCoreApplication::sendSpontaneousEvent(widget, &hideEvent);
9202 d->hideChildren(true);
9203 d->childrenHiddenByWState = true;
9204 }
9205 d->childrenShownByExpose = false; // Set it always to "false" when window state changes
9206 }
9208 }
9209 break;
9210
9214 update();
9215 QList<QObject*> childList = d->children;
9216 for (int i = 0; i < childList.size(); ++i) {
9217 QWidget *w = qobject_cast<QWidget *>(childList.at(i));
9218 if (w && w->isVisible() && !w->isWindow())
9220 }
9221 break; }
9222
9225 {
9226 QList<QObject*> childList = d->children;
9227 for (int i = 0; i < childList.size(); ++i) {
9228 QObject *o = childList.at(i);
9229 if (o)
9231 }
9232 }
9233 update();
9234 break;
9235
9237 d->resolveLayoutDirection();
9238 break;
9239
9241 if (d->layout)
9242 d->layout->invalidate();
9243 update();
9245 break;
9247 d->syncBackingStore();
9248 break;
9250 update(static_cast<QUpdateLaterEvent*>(event)->region());
9251 break;
9253 if (isVisible() && !window()->isMinimized()) {
9254 event->accept();
9255 update();
9256 }
9257 break;
9258
9261 if (!d->children.isEmpty()) {
9263 for (int i = 0; i < d->children.size(); ++i) {
9264 QObject *o = d->children.at(i);
9265 if (o && o != modalWidget && o->isWidgetType()) {
9266 QWidget *w = static_cast<QWidget *>(o);
9267 // do not forward the event to child windows; QApplication does this for us
9268 if (!w->isWindow())
9270 }
9271 }
9272 }
9273 break;
9274#if QT_CONFIG(tooltip)
9275 case QEvent::ToolTip:
9276 if (!d->toolTip.isEmpty())
9277 QToolTip::showText(static_cast<QHelpEvent*>(event)->globalPos(), d->toolTip, this, QRect(), d->toolTipDuration);
9278 else
9279 event->ignore();
9280 break;
9281#endif
9282#if QT_CONFIG(whatsthis)
9283 case QEvent::WhatsThis:
9284 if (d->whatsThis.size())
9285 QWhatsThis::showText(static_cast<QHelpEvent *>(event)->globalPos(), d->whatsThis, this);
9286 else
9287 event->ignore();
9288 break;
9290 if (d->whatsThis.isEmpty())
9291 event->ignore();
9292 break;
9293#endif
9295 d->topData()->frameStrut.setCoords(0 ,0, 0, 0);
9296 data->fstrut_dirty = false;
9297 break;
9298#ifndef QT_NO_ACTION
9303 break;
9304#endif
9305
9307 {
9309
9310 // inform children of the change
9311 QList<QObject*> childList = d->children;
9312 for (int i = 0; i < childList.size(); ++i) {
9313 QWidget *w = qobject_cast<QWidget *>(childList.at(i));
9314 if (w && w->isVisible() && !w->isWindow())
9316 }
9317 break;
9318 }
9319 case QEvent::TouchBegin:
9321 case QEvent::TouchEnd:
9323 {
9324 event->ignore();
9325 break;
9326 }
9327#ifndef QT_NO_GESTURES
9328 case QEvent::Gesture:
9329 event->ignore();
9330 break;
9331#endif
9333 if (const QTLWExtra *te = d->maybeTopData()) {
9334 const QWindow *win = te->window;
9335 d->setWinId((win && win->handle()) ? win->handle()->winId() : 0);
9336 }
9337 break;
9339 if (d->data.fnt.d->dpi != logicalDpiY())
9340 d->updateFont(d->data.fnt);
9341 d->renderToTextureReallyDirty = 1;
9342 break;
9344 const QByteArray &propName = static_cast<QDynamicPropertyChangeEvent *>(event)->propertyName();
9345 if (propName.size() == 13 && !qstrncmp(propName, "_q_customDpi", 12)) {
9346 uint value = property(propName.constData()).toUInt();
9347 if (!d->extra)
9348 d->createExtra();
9349 const char axis = propName.at(12);
9350 if (axis == 'X')
9351 d->extra->customDpiX = value;
9352 else if (axis == 'Y')
9353 d->extra->customDpiY = value;
9354 d->updateFont(d->data.fnt);
9355 }
9356 if (windowHandle() && !qstrncmp(propName, "_q_platform_", 12))
9357 windowHandle()->setProperty(propName, property(propName));
9358 Q_FALLTHROUGH();
9359 }
9360 default:
9361 return QObject::event(event);
9362 }
9363 return true;
9364}
9365
9383{
9384 switch(event->type()) {
9385 case QEvent::EnabledChange: {
9386 update();
9387#if QT_CONFIG(accessibility)
9389 s.disabled = true;
9390 QAccessibleStateChangeEvent event(this, s);
9391 QAccessible::updateAccessibility(&event);
9392#endif
9393 break;
9394 }
9395
9396 case QEvent::FontChange:
9397 case QEvent::StyleChange: {
9398 Q_D(QWidget);
9399 update();
9401 if (d->layout)
9402 d->layout->invalidate();
9403 break;
9404 }
9405
9407 update();
9408 break;
9409
9414 QApplication::style()->unpolish(this);
9416 QApplication::style()->polish(this);
9417 QEvent styleChangedEvent(QEvent::StyleChange);
9418 QCoreApplication::sendEvent(this, &styleChangedEvent);
9419 if (isVisible())
9420 update();
9421 }
9422 break;
9423
9424#ifdef Q_OS_MAC
9427 break;
9428#endif
9429
9430 default:
9431 break;
9432 }
9433}
9434
9462{
9463 event->ignore();
9464}
9465
9484{
9485 event->ignore();
9486 if ((windowType() == Qt::Popup)) {
9487 event->accept();
9488 QWidget* w;
9489 while ((w = QApplication::activePopupWidget()) && w != this){
9490 w->close();
9491 if (QApplication::activePopupWidget() == w) // widget does not want to disappear
9492 w->hide(); // hide at least
9493 }
9494 if (!rect().contains(event->position().toPoint())){
9495 close();
9496 }
9497 }
9498}
9499
9509{
9510 event->ignore();
9511}
9512
9534
9535#if QT_CONFIG(wheelevent)
9550void QWidget::wheelEvent(QWheelEvent *event)
9551{
9552 event->ignore();
9553}
9554#endif // QT_CONFIG(wheelevent)
9555
9556#if QT_CONFIG(tabletevent)
9577void QWidget::tabletEvent(QTabletEvent *event)
9578{
9579 event->ignore();
9580}
9581#endif // QT_CONFIG(tabletevent)
9582
9607{
9608#ifndef QT_NO_SHORTCUT
9609 if ((windowType() == Qt::Popup) && event->matches(QKeySequence::Cancel)) {
9610 event->accept();
9611 close();
9612 } else
9613#endif
9614 {
9615 event->ignore();
9616 }
9617}
9618
9642{
9643 event->ignore();
9644}
9645
9666{
9667 if (focusPolicy() != Qt::NoFocus || !isWindow()) {
9668 update();
9669 }
9670}
9671
9692{
9693 if (focusPolicy() != Qt::NoFocus || !isWindow())
9694 update();
9695
9696#if !defined(QT_PLATFORM_UIKIT)
9697 // FIXME: revisit autoSIP logic, QTBUG-42906
9698 if (qApp->autoSipEnabled() && testAttribute(Qt::WA_InputMethodEnabled))
9700#endif
9701}
9702
9718
9732{
9733}
9734
9786
9787
9802{
9803}
9804
9805
9823{
9824}
9825
9826#ifndef QT_NO_ACTION
9836{
9837
9838}
9839#endif
9840
9857{
9858 event->accept();
9859}
9860
9861#ifndef QT_NO_CONTEXTMENU
9876{
9877 event->ignore();
9878}
9879#endif // QT_NO_CONTEXTMENU
9880
9881
9899{
9900 event->ignore();
9901}
9902
9914{
9915 switch(query) {
9917 return QRect(width()/2, 0, 1, height());
9918 case Qt::ImFont:
9919 return font();
9921 // Fallback.
9923 case Qt::ImHints:
9924 return (int)inputMethodHints();
9926 return d_func()->clipRect();
9927 default:
9928 return QVariant();
9929 }
9930}
9931
9957Qt::InputMethodHints QWidget::inputMethodHints() const
9958{
9959#if QT_CONFIG(im)
9960 const QWidgetPrivate *priv = d_func();
9961 while (priv->inheritsInputMethodHints) {
9962 priv = priv->q_func()->parentWidget()->d_func();
9963 Q_ASSERT(priv);
9964 }
9965 return priv->imHints;
9966#else
9967 return Qt::ImhNone;
9968#endif
9969}
9970
9971void QWidget::setInputMethodHints(Qt::InputMethodHints hints)
9972{
9973#ifndef QT_NO_IM
9974 Q_D(QWidget);
9975 if (d->imHints == hints)
9976 return;
9977 d->imHints = hints;
9978 if (this == QGuiApplication::focusObject())
9980#else
9981 Q_UNUSED(hints);
9982#endif //QT_NO_IM
9983}
9984
9985
9986#if QT_CONFIG(draganddrop)
9987
10002void QWidget::dragEnterEvent(QDragEnterEvent *)
10003{
10004}
10005
10020void QWidget::dragMoveEvent(QDragMoveEvent *)
10021{
10022}
10023
10036void QWidget::dragLeaveEvent(QDragLeaveEvent *)
10037{
10038}
10039
10051void QWidget::dropEvent(QDropEvent *)
10052{
10053}
10054
10055#endif // QT_CONFIG(draganddrop)
10056
10077{
10078}
10079
10099{
10100}
10101
10130{
10131 Q_UNUSED(eventType);
10134 return false;
10135}
10136
10161{
10162 Q_D(const QWidget);
10163
10164 const QMetaObject *m = metaObject();
10165 if (m == d->polished)
10166 return;
10167 d->polished = m;
10168
10170 QCoreApplication::sendEvent(const_cast<QWidget *>(this), &e);
10171
10172 // polish children after 'this'
10173 QList<QObject*> children = d->children;
10174 for (int i = 0; i < children.size(); ++i) {
10175 QObject *o = children.at(i);
10176 if (!o->isWidgetType())
10177 continue;
10178 if (QWidget *w = qobject_cast<QWidget *>(o))
10179 w->ensurePolished();
10180 }
10181
10182 if (d->parent && d->sendChildEvents) {
10183 QChildEvent e(QEvent::ChildPolished, const_cast<QWidget *>(this));
10184 QCoreApplication::sendEvent(d->parent, &e);
10185 }
10186}
10187
10195{
10196 Q_D(const QWidget);
10197 return d->extra ? d->extra->mask : QRegion();
10198}
10199
10210{
10211 return d_func()->layout;
10212}
10213
10214
10241{
10242 if (Q_UNLIKELY(!l)) {
10243 qWarning("QWidget::setLayout: Cannot set layout to 0");
10244 return;
10245 }
10246 if (layout()) {
10247 if (Q_UNLIKELY(layout() != l))
10248 qWarning("QWidget::setLayout: Attempting to set QLayout \"%s\" on %s \"%s\", which already has a"
10249 " layout", l->objectName().toLocal8Bit().data(), metaObject()->className(),
10251 return;
10252 }
10253
10254 QObject *oldParent = l->parent();
10255 if (oldParent && oldParent != this) {
10256 if (oldParent->isWidgetType()) {
10257 // Steal the layout off a widget parent. Takes effect when
10258 // morphing laid-out container widgets in Designer.
10259 QWidget *oldParentWidget = static_cast<QWidget *>(oldParent);
10260 oldParentWidget->takeLayout();
10261 } else {
10262 qWarning("QWidget::setLayout: Attempting to set QLayout \"%s\" on %s \"%s\", when the QLayout already has a parent",
10265 return;
10266 }
10267 }
10268
10269 Q_D(QWidget);
10270 l->d_func()->topLevel = true;
10271 d->layout = l;
10272 if (oldParent != this) {
10273 l->setParent(this);
10274 l->d_func()->reparentChildWidgets(this);
10275 l->invalidate();
10276 }
10277
10278 if (isWindow() && d->maybeTopData())
10279 d->topData()->sizeAdjusted = false;
10280}
10281
10289QLayout *QWidget::takeLayout()
10290{
10291 Q_D(QWidget);
10292 QLayout *l = layout();
10293 if (!l)
10294 return nullptr;
10295 d->layout = nullptr;
10296 l->setParent(nullptr);
10297 return l;
10298}
10299
10326{
10327 Q_D(const QWidget);
10328 return d->size_policy;
10329}
10330
10332{
10333 Q_D(QWidget);
10335 if (policy == d->size_policy)
10336 return;
10337
10338 if (d->size_policy.retainSizeWhenHidden() != policy.retainSizeWhenHidden())
10339 d->retainSizeWhenHiddenChanged = 1;
10340
10341 d->size_policy = policy;
10342
10343#if QT_CONFIG(graphicsview)
10344 if (const auto &extra = d->extra) {
10345 if (extra->proxyWidget)
10346 extra->proxyWidget->setSizePolicy(policy);
10347 }
10348#endif
10349
10351 d->retainSizeWhenHiddenChanged = 0;
10352
10353 if (isWindow() && d->maybeTopData())
10354 d->topData()->sizeAdjusted = false;
10355}
10356
10377{
10378 if (layout() && layout()->hasHeightForWidth())
10379 return layout()->totalHeightForWidth(w);
10380 return -1;
10381}
10382
10383
10390{
10391 Q_D(const QWidget);
10392 return d->layout ? d->layout->hasHeightForWidth() : d->size_policy.hasHeightForWidth();
10393}
10394
10411{
10412 return d_func()->childAt_helper(p, false);
10413}
10414
10415QWidget *QWidgetPrivate::childAt_helper(const QPoint &p, bool ignoreChildrenInDestructor) const
10416{
10417 if (children.isEmpty())
10418 return nullptr;
10419
10421 return nullptr;
10422 return childAtRecursiveHelper(p, ignoreChildrenInDestructor);
10423}
10424
10425QWidget *QWidgetPrivate::childAtRecursiveHelper(const QPoint &p, bool ignoreChildrenInDestructor) const
10426{
10427 for (int i = children.size() - 1; i >= 0; --i) {
10429 if (!child || child->isWindow() || child->isHidden() || child->testAttribute(Qt::WA_TransparentForMouseEvents)
10430 || (ignoreChildrenInDestructor && child->data->in_destructor)) {
10431 continue;
10432 }
10433
10434 // Map the point 'p' from parent coordinates to child coordinates.
10435 QPoint childPoint = p;
10436 childPoint -= child->data->crect.topLeft();
10437
10438 // Check if the point hits the child.
10439 if (!child->d_func()->pointInsideRectAndMask(childPoint))
10440 continue;
10441
10442 // Do the same for the child's descendants.
10443 if (QWidget *w = child->d_func()->childAtRecursiveHelper(childPoint, ignoreChildrenInDestructor))
10444 return w;
10445
10446 // We have found our target; namely the child at position 'p'.
10447 return child;
10448 }
10449 return nullptr;
10450}
10451
10453{
10454 Q_Q(QWidget);
10455 if (widgetItem)
10456 widgetItem->invalidateSizeCache();
10457 QWidget *parent;
10458 if (forceUpdate || !extra || extra->minw != extra->maxw || extra->minh != extra->maxh) {
10459 const int isHidden = q->isHidden() && !size_policy.retainSizeWhenHidden() && !retainSizeWhenHiddenChanged;
10460
10461 if (!q->isWindow() && !isHidden && (parent = q->parentWidget())) {
10462 if (parent->d_func()->layout)
10463 parent->d_func()->layout->invalidate();
10464 else if (parent->isVisible())
10466 }
10467 }
10468}
10469
10481{
10482 Q_D(QWidget);
10483 d->updateGeometry_helper(false);
10484}
10485
10504void QWidget::setWindowFlags(Qt::WindowFlags flags)
10505{
10506 Q_D(QWidget);
10507 d->setWindowFlags(flags);
10508}
10509
10519{
10520 Q_D(QWidget);
10521 if (on)
10522 d->setWindowFlags(data->window_flags | flag);
10523 else
10524 d->setWindowFlags(data->window_flags & ~flag);
10525}
10526
10532{
10533 Q_Q(QWidget);
10534 if (q->data->window_flags == flags)
10535 return;
10536
10537 if ((q->data->window_flags | flags) & Qt::Window) {
10538 // the old type was a window and/or the new type is a window
10539 QPoint oldPos = q->pos();
10540 bool visible = q->isVisible();
10541 const bool windowFlagChanged = (q->data->window_flags ^ flags) & Qt::Window;
10542 q->setParent(q->parentWidget(), flags);
10543
10544 // if both types are windows or neither of them are, we restore
10545 // the old position
10546 if (!windowFlagChanged && (visible || q->testAttribute(Qt::WA_Moved)))
10547 q->move(oldPos);
10548 // for backward-compatibility we change Qt::WA_QuitOnClose attribute value only when the window was recreated.
10550 } else {
10551 q->data->window_flags = flags;
10552 }
10553}
10554
10565{
10566 data->window_flags = flags;
10567}
10568
10607{
10608 if (parent == parentWidget())
10609 return;
10611}
10612
10614{
10616 if (d->renderToTexture) {
10617 QEvent e(eventType);
10619 }
10620
10621 for (int i = 0; i < d->children.size(); ++i) {
10622 QWidget *w = qobject_cast<QWidget *>(d->children.at(i));
10623 if (w && !w->isWindow())
10625 }
10626
10627 // Notify QWidgetWindow after we've notified all child QWidgets
10628 if (auto *window = d->windowHandle(QWidgetPrivate::WindowHandleMode::Direct)) {
10629 QEvent e(eventType);
10631 }
10632}
10633
10640void QWidget::setParent(QWidget *parent, Qt::WindowFlags f)
10641{
10642 Q_D(QWidget);
10643 Q_ASSERT_X(this != parent, Q_FUNC_INFO, "Cannot parent a QWidget to itself");
10644#ifdef QT_DEBUG
10645 const auto checkForParentChildLoops = qScopeGuard([&](){
10646 int depth = 0;
10647 auto p = parentWidget();
10648 while (p) {
10649 if (++depth == QObjectPrivate::CheckForParentChildLoopsWarnDepth) {
10650 qWarning("QWidget %p (class: '%s', object name: '%s') may have a loop in its parent-child chain; "
10651 "this is undefined behavior",
10652 this, metaObject()->className(), qPrintable(objectName()));
10653 }
10654 p = p->parentWidget();
10655 }
10656 });
10657#endif
10658
10659 const bool resized = testAttribute(Qt::WA_Resized);
10660 const bool wasCreated = testAttribute(Qt::WA_WState_Created);
10661 QWidget *oldtlw = window();
10662 Q_ASSERT(oldtlw);
10663
10664 if (f & Qt::Window) // Frame geometry likely changes, refresh.
10665 d->data.fstrut_dirty = true;
10666
10667 QWidget *desktopWidget = nullptr;
10668 if (parent && parent->windowType() == Qt::Desktop)
10669 desktopWidget = parent;
10670 bool newParent = (parent != parentWidget()) || desktopWidget;
10671
10672 if (newParent && parent && !desktopWidget) {
10674 parent->d_func()->enforceNativeChildren();
10675 else if (parent->d_func()->nativeChildrenForced() || parent->testAttribute(Qt::WA_PaintOnScreen))
10677 }
10678
10679 if (wasCreated) {
10681 // Hiding the widget will set WA_WState_Hidden as well, which would
10682 // normally require the widget to be explicitly shown again to become
10683 // visible, even as a child widget. But we refine this value later in
10684 // setParent_sys(), applying WA_WState_Hidden based on whether the
10685 // widget is a top level or not.
10686 hide();
10687
10688 // We reset WA_WState_ExplicitShowHide here, likely as a remnant of
10689 // when we only had QWidget::setVisible(), which is treated as an
10690 // explicit show/hide. Nowadays we have QWidgetPrivate::setVisible(),
10691 // that allows us to hide a widget without affecting ExplicitShowHide.
10692 // Though it can be argued that ExplicitShowHide should reflect the
10693 // last update of the widget's state, so if we hide the widget as a
10694 // side effect of changing parent, perhaps we _should_ reset it?
10696 }
10697 if (newParent) {
10700 }
10701 }
10702
10703 // texture-based widgets need a pre-notification when their associated top-level window changes
10704 // This is not under the wasCreated/newParent conditions above in order to also play nice with QDockWidget.
10705 if (oldtlw->d_func()->usesRhiFlush && ((!parent && parentWidget()) || (parent && parent->window() != oldtlw)))
10707
10708 // If we get parented into another window, children will be folded
10709 // into the new parent's focus chain, so clear focus now.
10710 if (newParent && isAncestorOf(focusWidget()) && !(f & Qt::Window))
10712
10713 d->setParent_sys(parent, f);
10714
10715 if (desktopWidget)
10716 parent = nullptr;
10717
10718 if (d->textureChildSeen && parent) {
10719 // set the textureChildSeen flag up the whole parent chain
10720 QWidgetPrivate::get(parent)->setTextureChildSeen();
10721 }
10722
10723 if (QWidgetRepaintManager *oldPaintManager = oldtlw->d_func()->maybeRepaintManager()) {
10724 if (newParent)
10725 oldPaintManager->removeDirtyWidget(this);
10726 // Move the widget and all its static children from
10727 // the old backing store to the new one.
10728 oldPaintManager->moveStaticWidgets(this);
10729 }
10730
10731 d->reparentFocusWidgets(oldtlw);
10732 setAttribute(Qt::WA_Resized, resized);
10733
10734 const bool useStyleSheetPropagationInWidgetStyles =
10736
10737 if (!useStyleSheetPropagationInWidgetStyles && !testAttribute(Qt::WA_StyleSheet)
10738 && (!parent || !parent->testAttribute(Qt::WA_StyleSheet))) {
10739 // if the parent has a font set or inherited, then propagate the mask to the new child
10740 if (parent) {
10741 const auto pd = parent->d_func();
10742 d->inheritedFontResolveMask = pd->directFontResolveMask | pd->inheritedFontResolveMask;
10743 d->inheritedPaletteResolveMask = pd->directPaletteResolveMask | pd->inheritedPaletteResolveMask;
10744 }
10745 d->resolveFont();
10746 d->resolvePalette();
10747 }
10748 d->resolveLayoutDirection();
10749 d->resolveLocale();
10750
10751 // Note: GL widgets under WGL or EGL will always need a ParentChange
10752 // event to handle recreation/rebinding of the GL context, hence the
10753 // (f & Qt::MSWindowsOwnDC) clause (which is set on QGLWidgets on all
10754 // platforms).
10755 if (newParent || !wasCreated
10756#if QT_CONFIG(opengles2)
10757 || (f & Qt::MSWindowsOwnDC)
10758#endif
10759 ) {
10760 // propagate enabled updates enabled state to non-windows
10761 if (!isWindow()) {
10763 d->setEnabled_helper(parent ? parent->isEnabled() : true);
10765 d->setUpdatesEnabled_helper(parent ? parent->updatesEnabled() : true);
10766 }
10767 d->inheritStyle();
10768
10769 // send and post remaining QObject events
10770 if (parent && d->sendChildEvents) {
10773 }
10774
10775 if (parent && d->sendChildEvents && d->polished) {
10778 }
10779
10782 }
10783
10784 // texture-based widgets need another event when their top-level window
10785 // changes (more precisely, has already changed at this point)
10786 if (oldtlw->d_func()->usesRhiFlush && oldtlw != window())
10788
10789 if (!wasCreated) {
10790 if (isWindow() || parentWidget()->isVisible())
10794 }
10795
10796 d->updateIsOpaque();
10797
10798#if QT_CONFIG(graphicsview)
10799 // Embed the widget into a proxy if the parent is embedded.
10800 // ### Doesn't handle reparenting out of an embedded widget.
10801 if (oldtlw->graphicsProxyWidget()) {
10802 if (QGraphicsProxyWidget *ancestorProxy = d->nearestGraphicsProxyWidget(oldtlw))
10803 ancestorProxy->d_func()->unembedSubWindow(this);
10804 }
10805 if (isWindow() && parent && !graphicsProxyWidget() && !bypassGraphicsProxyWidget(this)) {
10806 if (QGraphicsProxyWidget *ancestorProxy = d->nearestGraphicsProxyWidget(parent))
10807 ancestorProxy->d_func()->embedSubWindow(this);
10808 }
10809#endif
10810
10811 if (d->extra && d->extra->hasWindowContainer)
10813
10814 QWidget *newtlw = window();
10815 if (oldtlw != newtlw) {
10817 // Only evaluate the reparented subtree. While it might be tempting to
10818 // do it on newtlw instead, the performance implications of that are
10819 // problematic when it comes to large widget trees.
10820 if (q_evaluateRhiConfig(this, nullptr, &surfaceType)) {
10821 const bool wasUsingRhiFlush = newtlw->d_func()->usesRhiFlush;
10822 newtlw->d_func()->usesRhiFlush = true;
10823 bool recreate = false;
10824 if (QWindow *w = newtlw->windowHandle()) {
10825 if (w->surfaceType() != surfaceType || !wasUsingRhiFlush)
10826 recreate = true;
10827 }
10828 // QTBUG-115652: Besides the toplevel the nativeParentWidget()'s QWindow must be checked as well.
10829 if (QWindow *w = d->windowHandle(QWidgetPrivate::WindowHandleMode::Closest)) {
10830 if (w->surfaceType() != surfaceType)
10831 recreate = true;
10832 }
10833 if (recreate) {
10834 const auto windowStateBeforeDestroy = newtlw->windowState();
10835 const auto visibilityBeforeDestroy = newtlw->isVisible();
10836 newtlw->destroy();
10837 newtlw->create();
10838 Q_ASSERT(newtlw->windowHandle());
10839 newtlw->windowHandle()->setWindowStates(windowStateBeforeDestroy);
10840 QWidgetPrivate::get(newtlw)->setVisible(visibilityBeforeDestroy);
10841 }
10842 }
10843 }
10844}
10845
10846void QWidgetPrivate::setParent_sys(QWidget *newparent, Qt::WindowFlags f)
10847{
10848 Q_Q(QWidget);
10849
10850 Qt::WindowFlags oldFlags = data.window_flags;
10851 bool wasCreated = q->testAttribute(Qt::WA_WState_Created);
10852
10853 QScreen *targetScreen = nullptr;
10854 // Handle a request to move the widget to a particular screen
10855 if (newparent && newparent->windowType() == Qt::Desktop) {
10856 // make sure the widget is created on the same screen as the
10857 // programmer specified desktop widget
10858 targetScreen = newparent->screen();
10859 newparent = nullptr;
10860 }
10861
10862 setWinId(0);
10863
10864 if (!newparent) {
10865 f |= Qt::Window;
10866 if (parent)
10867 targetScreen = q->parentWidget()->window()->screen();
10868 }
10869
10870 const bool destroyWindow = (
10871 // Reparenting top level to child
10872 (oldFlags & Qt::Window) && !(f & Qt::Window)
10873 // And we can dispose of the window
10874 && wasCreated && !q->testAttribute(Qt::WA_NativeWindow)
10875 );
10876
10877 if (parent != newparent) {
10878 // Update object parent now, so we can resolve new parent window below
10880
10881 if (q->windowHandle())
10882 q->windowHandle()->setFlags(f);
10883
10884 // If the widget itself or any of its children have been created,
10885 // we need to reparent their QWindows as well.
10886 QWidget *parentWithWindow = closestParentWidgetWithWindowHandle();
10887 // But if the widget is about to be destroyed we must skip the
10888 // widget itself, and only reparent children.
10889 if (destroyWindow)
10890 reparentWidgetWindowChildren(parentWithWindow);
10891 else
10892 reparentWidgetWindows(parentWithWindow, f);
10893 }
10894
10895 bool explicitlyHidden = isExplicitlyHidden();
10896
10897 if (destroyWindow) {
10898 if (extra && extra->hasWindowContainer)
10900
10901 // There shouldn't be any QWindow children left, but if there
10902 // are, re-parent them now, before we destroy.
10903 if (!q->windowHandle()->children().isEmpty()) {
10904 QWidget *parentWithWindow = closestParentWidgetWithWindowHandle();
10905 QWindow *newParentWindow = parentWithWindow ? parentWithWindow->windowHandle() : nullptr;
10906 for (QObject *child : q->windowHandle()->children()) {
10907 if (QWindow *childWindow = qobject_cast<QWindow *>(child)) {
10908 qCWarning(lcWidgetWindow) << "Reparenting" << childWindow
10909 << "before destroying" << this;
10910 childWindow->setParent(newParentWindow);
10911 }
10912 }
10913 }
10914
10915 // We have reparented any child windows of the widget we are
10916 // about to destroy to the new parent window handle, so we can
10917 // safely destroy this widget without destroying sub windows.
10918 q->destroy(true, false);
10919 }
10920
10921 adjustFlags(f, q);
10922 data.window_flags = f;
10923 q->setAttribute(Qt::WA_WState_Created, false);
10924 q->setAttribute(Qt::WA_WState_Visible, false);
10925 q->setAttribute(Qt::WA_WState_Hidden, false);
10926
10927 if (newparent && wasCreated && (q->testAttribute(Qt::WA_NativeWindow) || (f & Qt::Window)))
10928 q->createWinId();
10929
10930 if (q->isWindow() || (!newparent || newparent->isVisible()) || explicitlyHidden)
10931 q->setAttribute(Qt::WA_WState_Hidden);
10932 q->setAttribute(Qt::WA_WState_ExplicitShowHide, explicitlyHidden);
10933
10934 // move the window to the selected screen
10935 if (!newparent && targetScreen) {
10936 // only if it is already created
10937 if (q->testAttribute(Qt::WA_WState_Created))
10938 q->windowHandle()->setScreen(targetScreen);
10939 else
10940 topData()->initialScreen = targetScreen;
10941 }
10942}
10943
10944void QWidgetPrivate::reparentWidgetWindows(QWidget *parentWithWindow, Qt::WindowFlags windowFlags)
10945{
10946 if (QWindow *window = windowHandle()) {
10947 // Reparent this QWindow, and all QWindow children will follow
10948 if (parentWithWindow) {
10949 // The reparented widget has not updated its window flags yet,
10950 // so we can't ask the widget directly. And we can't use the
10951 // QWindow flags, as unlike QWidgets the QWindow flags always
10952 // reflect Qt::Window, even for child windows. And we can't use
10953 // QWindow::isTopLevel() either, as that depends on the parent,
10954 // which we are in the process of updating. So we propagate the
10955 // new flags of the reparented window from setParent_sys().
10956 if (windowFlags & Qt::Window) {
10957 // Top level windows can only have transient parents,
10958 // and the transient parent must be another top level.
10959 QWidget *topLevel = parentWithWindow->window();
10960 auto *transientParent = topLevel->windowHandle();
10961 Q_ASSERT(transientParent);
10962 qCDebug(lcWidgetWindow) << "Setting" << window << "transient parent to" << transientParent;
10963 window->setTransientParent(transientParent);
10964 window->setParent(nullptr);
10965 } else {
10966 auto *parentWindow = parentWithWindow->windowHandle();
10967 qCDebug(lcWidgetWindow) << "Reparenting" << window << "into" << parentWindow;
10968 window->setTransientParent(nullptr);
10969 window->setParent(parentWindow);
10970 }
10971 } else {
10972 qCDebug(lcWidgetWindow) << "Making" << window << "top level window";
10973 window->setTransientParent(nullptr);
10974 window->setParent(nullptr);
10975 }
10976 } else {
10977 reparentWidgetWindowChildren(parentWithWindow);
10978 }
10979}
10980
10982{
10983 for (auto *child : std::as_const(children)) {
10984 if (auto *childWidget = qobject_cast<QWidget*>(child)) {
10985 auto *childPrivate = QWidgetPrivate::get(childWidget);
10986 childPrivate->reparentWidgetWindows(parentWithWindow);
10987 }
10988 }
10989}
10990
11012void QWidget::scroll(int dx, int dy)
11013{
11014 if ((!updatesEnabled() && children().size() == 0) || !isVisible())
11015 return;
11016 if (dx == 0 && dy == 0)
11017 return;
11018 Q_D(QWidget);
11019#if QT_CONFIG(graphicsview)
11020 if (QGraphicsProxyWidget *proxy = QWidgetPrivate::nearestGraphicsProxyWidget(this)) {
11021 // Graphics View maintains its own dirty region as a list of rects;
11022 // until we can connect item updates directly to the view, we must
11023 // separately add a translated dirty region.
11024 for (const QRect &rect : d->dirty)
11025 proxy->update(rect.translated(dx, dy));
11026 proxy->scroll(dx, dy, proxy->subWidgetRect(this));
11027 return;
11028 }
11029#endif
11030 d->setDirtyOpaqueRegion();
11031 d->scroll_sys(dx, dy);
11032}
11033
11034void QWidgetPrivate::scroll_sys(int dx, int dy)
11035{
11036 Q_Q(QWidget);
11037 scrollChildren(dx, dy);
11038 scrollRect(q->rect(), dx, dy);
11039}
11040
11051void QWidget::scroll(int dx, int dy, const QRect &r)
11052{
11053
11054 if ((!updatesEnabled() && children().size() == 0) || !isVisible())
11055 return;
11056 if (dx == 0 && dy == 0)
11057 return;
11058 Q_D(QWidget);
11059#if QT_CONFIG(graphicsview)
11060 if (QGraphicsProxyWidget *proxy = QWidgetPrivate::nearestGraphicsProxyWidget(this)) {
11061 // Graphics View maintains its own dirty region as a list of rects;
11062 // until we can connect item updates directly to the view, we must
11063 // separately add a translated dirty region.
11064 if (!d->dirty.isEmpty()) {
11065 for (const QRect &rect : d->dirty.translated(dx, dy) & r)
11066 proxy->update(rect);
11067 }
11068 proxy->scroll(dx, dy, r.translated(proxy->subWidgetRect(this).topLeft().toPoint()));
11069 return;
11070 }
11071#endif
11072 d->scroll_sys(dx, dy, r);
11073}
11074
11075void QWidgetPrivate::scroll_sys(int dx, int dy, const QRect &r)
11076{
11077 scrollRect(r, dx, dy);
11078}
11079
11097{
11098 repaint(rect());
11099}
11100
11109void QWidget::repaint(int x, int y, int w, int h)
11110{
11111 if (x > data->crect.width() || y > data->crect.height())
11112 return;
11113
11114 if (w < 0)
11115 w = data->crect.width() - x;
11116 if (h < 0)
11117 h = data->crect.height() - y;
11118
11119 repaint(QRect(x, y, w, h));
11120}
11121
11127{
11128 Q_D(QWidget);
11129 d->repaint(rect);
11130}
11131
11138{
11139 Q_D(QWidget);
11140 d->repaint(rgn);
11141}
11142
11143template <typename T>
11145{
11146 Q_Q(QWidget);
11147
11148 if (!q->isVisible() || !q->updatesEnabled() || r.isEmpty())
11149 return;
11150
11151 QTLWExtra *tlwExtra = q->window()->d_func()->maybeTopData();
11152 if (tlwExtra && tlwExtra->backingStore && tlwExtra->repaintManager)
11153 tlwExtra->repaintManager->markDirty(r, q, QWidgetRepaintManager::UpdateNow);
11154}
11155
11175{
11176 update(rect());
11177}
11178
11192{
11193 Q_D(QWidget);
11194 d->update(rect);
11195}
11196
11202void QWidget::update(const QRegion &rgn)
11203{
11204 Q_D(QWidget);
11205 d->update(rgn);
11206}
11207
11208template <typename T>
11210{
11211 Q_Q(QWidget);
11212
11213 if (renderToTexture && !q->isVisible()) {
11215 return;
11216 }
11217
11218 if (!q->isVisible() || !q->updatesEnabled())
11219 return;
11220
11221 T clipped = r & q->rect();
11222
11223 if (clipped.isEmpty())
11224 return;
11225
11226 if (q->testAttribute(Qt::WA_WState_InPaintEvent)) {
11228 return;
11229 }
11230
11231 QTLWExtra *tlwExtra = q->window()->d_func()->maybeTopData();
11232 if (tlwExtra && tlwExtra->backingStore && tlwExtra->repaintManager)
11233 tlwExtra->repaintManager->markDirty(clipped, q);
11234}
11235
11243{
11244 if (attribute < int(8*sizeof(uint))) {
11245 if (on)
11246 data->widget_attributes |= (1<<attribute);
11247 else
11248 data->widget_attributes &= ~(1<<attribute);
11249 } else {
11250 const int x = attribute - 8*sizeof(uint);
11251 const int int_off = x / (8*sizeof(uint));
11252 if (on)
11253 d->high_attributes[int_off] |= (1<<(x-(int_off*8*sizeof(uint))));
11254 else
11255 d->high_attributes[int_off] &= ~(1<<(x-(int_off*8*sizeof(uint))));
11256 }
11257}
11258
11259#ifdef Q_OS_MAC
11260void QWidgetPrivate::macUpdateSizeAttribute()
11261{
11262 Q_Q(QWidget);
11265 for (int i = 0; i < children.size(); ++i) {
11267 if (w && (!w->isWindow() || w->testAttribute(Qt::WA_WindowPropagation))
11268 && !w->testAttribute(Qt::WA_MacMiniSize) // no attribute set? inherit from parent
11269 && !w->testAttribute(Qt::WA_MacSmallSize)
11270 && !w->testAttribute(Qt::WA_MacNormalSize))
11271 w->d_func()->macUpdateSizeAttribute();
11272 }
11273 resolveFont();
11274}
11275#endif
11276
11284{
11285 if (testAttribute(attribute) == on)
11286 return;
11287
11288 Q_D(QWidget);
11289 static_assert(sizeof(d->high_attributes)*8 >= (Qt::WA_AttributeCount - sizeof(uint)*8),
11290 "QWidget::setAttribute(WidgetAttribute, bool): "
11291 "QWidgetPrivate::high_attributes[] too small to contain all attributes in WidgetAttribute");
11292#ifdef Q_OS_WIN
11293 // ### Don't use PaintOnScreen+paintEngine() to do native painting in some future release
11294 if (attribute == Qt::WA_PaintOnScreen && on && windowType() != Qt::Desktop && !inherits("QGLWidget")) {
11295 // see ::paintEngine for details
11296 paintEngine();
11297 if (d->noPaintOnScreen)
11298 return;
11299 }
11300#endif
11301
11302 // Don't set WA_NativeWindow on platforms that don't support it -- except for QGLWidget, which depends on it
11303 if (attribute == Qt::WA_NativeWindow && !d->mustHaveWindowHandle) {
11305 if (!platformIntegration->hasCapability(QPlatformIntegration::NativeWidgets))
11306 return;
11307 }
11308
11310
11311 switch (attribute) {
11312
11313#if QT_CONFIG(draganddrop)
11314 case Qt::WA_AcceptDrops: {
11321 break;
11322 }
11324 for (int i = 0; i < d->children.size(); ++i) {
11325 QWidget *w = qobject_cast<QWidget *>(d->children.at(i));
11326 if (w && !w->isWindow() && !w->testAttribute(Qt::WA_AcceptDrops) && w->testAttribute(Qt::WA_DropSiteRegistered) != on)
11327 w->setAttribute(Qt::WA_DropSiteRegistered, on);
11328 }
11329 break;
11330 }
11331#endif
11332
11334 d->sendChildEvents = !on;
11335 break;
11337 d->receiveChildEvents = !on;
11338 break;
11341 case Qt::WA_MacMiniSize:
11342#ifdef Q_OS_MAC
11343 {
11344 // We can only have one of these set at a time
11347 for (int i = 0; i < 3; ++i) {
11348 if (MacSizes[i] != attribute)
11349 setAttribute_internal(MacSizes[i], false, data, d);
11350 }
11351 d->macUpdateSizeAttribute();
11352 }
11353#endif
11354 break;
11355 case Qt::WA_ShowModal:
11356 if (!on) {
11357 // reset modality type to NonModal when clearing WA_ShowModal
11358 data->window_modality = Qt::NonModal;
11359 } else if (data->window_modality == Qt::NonModal) {
11360 // If modality hasn't been set prior to setting WA_ShowModal, use
11361 // ApplicationModal.
11362 data->window_modality = Qt::ApplicationModal;
11363 // Some window managers do not allow us to enter modality after the
11364 // window is visible.The window must be hidden before changing the
11365 // windowModality property and then reshown.
11366 }
11368 // don't call setModal_sys() before create()
11369 d->setModal_sys();
11370 }
11371 break;
11372 case Qt::WA_MouseTracking: {
11375 break; }
11376 case Qt::WA_TabletTracking: {
11379 break; }
11380 case Qt::WA_NativeWindow: {
11381 d->createTLExtra();
11382 if (on)
11383 d->createTLSysExtra();
11384#ifndef QT_NO_IM
11385 QWidget *focusWidget = d->effectiveFocusWidget();
11386 if (on && !internalWinId() && this == QGuiApplication::focusObject()
11388 QGuiApplication::inputMethod()->commit();
11390 }
11392 parentWidget()->d_func()->enforceNativeChildren();
11394 d->createWinId();
11398 }
11399#endif //QT_NO_IM
11400 break;
11401 }
11403 d->updateIsOpaque();
11404 Q_FALLTHROUGH();
11406 d->updateIsOpaque();
11407 break;
11409 d->updateIsOpaque();
11410 Q_FALLTHROUGH();
11412 d->updateSystemBackground();
11413 break;
11415 break;
11417#ifndef QT_NO_IM
11418 if (QGuiApplication::focusObject() == this) {
11419 if (!on)
11420 QGuiApplication::inputMethod()->commit();
11422 }
11423#endif //QT_NO_IM
11424 break;
11425 }
11427 d->resolvePalette();
11428 d->resolveFont();
11429 d->resolveLocale();
11430 break;
11432 if (on && isVisible()) {
11433 // Make sure we keep the current state and only hide the widget
11434 // from the desktop. show_sys will only update platform specific
11435 // attributes at this point.
11436 d->hide_sys();
11437 d->show_sys();
11438 }
11439 break;
11440 }
11441
11455 d->setNetWmWindowTypes();
11456 break;
11457
11459 if (QWidgetRepaintManager *repaintManager = d->maybeRepaintManager()) {
11460 if (on)
11461 repaintManager->addStaticWidget(this);
11462 else
11463 repaintManager->removeStaticWidget(this);
11464 }
11465 break;
11467 if (on)
11469 d->updateIsTranslucent();
11470
11471 break;
11473 break;
11474 default:
11475 break;
11476 }
11477}
11478
11486bool QWidget::testAttribute_helper(Qt::WidgetAttribute attribute) const
11487{
11488 Q_D(const QWidget);
11489 const int x = attribute - 8*sizeof(uint);
11490 const int int_off = x / (8*sizeof(uint));
11491 return (d->high_attributes[int_off] & (1<<(x-(int_off*8*sizeof(uint)))));
11492}
11493
11520{
11521 Q_D(const QWidget);
11522 return (isWindow() && d->maybeTopData()) ? d->maybeTopData()->opacity / 255. : 1.0;
11523}
11524
11526{
11527 Q_D(QWidget);
11528 if (!isWindow())
11529 return;
11530
11531 opacity = qBound(qreal(0.0), opacity, qreal(1.0));
11532 QTLWExtra *extra = d->topData();
11533 extra->opacity = uint(opacity * 255);
11535 d->setWindowOpacity_sys(opacity);
11536
11538 return;
11539
11540#if QT_CONFIG(graphicsview)
11541 if (QGraphicsProxyWidget *proxy = graphicsProxyWidget()) {
11542 // Avoid invalidating the cache if set.
11543 if (proxy->cacheMode() == QGraphicsItem::NoCache)
11544 proxy->update();
11545 else if (QGraphicsScene *scene = proxy->scene())
11546 scene->update(proxy->sceneBoundingRect());
11547 return;
11548 }
11549#endif
11550}
11551
11553{
11554 Q_Q(QWidget);
11555 if (q->windowHandle())
11556 q->windowHandle()->setOpacity(level);
11557}
11558
11584{
11586}
11587
11589{
11590 Q_D(QWidget);
11592
11593 d->setWindowModified_helper();
11594
11597}
11598
11600{
11601 Q_Q(QWidget);
11602 QWindow *window = q->windowHandle();
11603 if (!window)
11604 return;
11605 QPlatformWindow *platformWindow = window->handle();
11606 if (!platformWindow)
11607 return;
11608 bool on = q->testAttribute(Qt::WA_WindowModified);
11609 if (!platformWindow->setWindowModified(on)) {
11610 if (Q_UNLIKELY(on && !q->windowTitle().contains("[*]"_L1)))
11611 qWarning("QWidget::setWindowModified: The window title does not contain a '[*]' placeholder");
11612 setWindowTitle_helper(q->windowTitle());
11613 setWindowIconText_helper(q->windowIconText());
11614 }
11615}
11616
11617#if QT_CONFIG(tooltip)
11636void QWidget::setToolTip(const QString &s)
11637{
11638 Q_D(QWidget);
11639 d->toolTip = s;
11640
11643}
11644
11645QString QWidget::toolTip() const
11646{
11647 Q_D(const QWidget);
11648 return d->toolTip;
11649}
11650
11662void QWidget::setToolTipDuration(int msec)
11663{
11664 Q_D(QWidget);
11665 d->toolTipDuration = msec;
11666}
11667
11668int QWidget::toolTipDuration() const
11669{
11670 Q_D(const QWidget);
11671 return d->toolTipDuration;
11672}
11673
11674#endif // QT_CONFIG(tooltip)
11675
11676
11677#if QT_CONFIG(statustip)
11686void QWidget::setStatusTip(const QString &s)
11687{
11688 Q_D(QWidget);
11689 d->statusTip = s;
11690}
11691
11692QString QWidget::statusTip() const
11693{
11694 Q_D(const QWidget);
11695 return d->statusTip;
11696}
11697#endif // QT_CONFIG(statustip)
11698
11699#if QT_CONFIG(whatsthis)
11709void QWidget::setWhatsThis(const QString &s)
11710{
11711 Q_D(QWidget);
11712 d->whatsThis = s;
11713}
11714
11715QString QWidget::whatsThis() const
11716{
11717 Q_D(const QWidget);
11718 return d->whatsThis;
11719}
11720#endif // QT_CONFIG(whatsthis)
11721
11722#if QT_CONFIG(accessibility)
11744void QWidget::setAccessibleName(const QString &name)
11745{
11746 Q_D(QWidget);
11747 d->accessibleName = name;
11748 QAccessibleEvent event(this, QAccessible::NameChanged);
11749 QAccessible::updateAccessibility(&event);
11750}
11751
11752QString QWidget::accessibleName() const
11753{
11754 Q_D(const QWidget);
11755 return d->accessibleName;
11756}
11757
11774void QWidget::setAccessibleDescription(const QString &description)
11775{
11776 Q_D(QWidget);
11777 d->accessibleDescription = description;
11778 QAccessibleEvent event(this, QAccessible::DescriptionChanged);
11779 QAccessible::updateAccessibility(&event);
11780}
11781
11782QString QWidget::accessibleDescription() const
11783{
11784 Q_D(const QWidget);
11785 return d->accessibleDescription;
11786}
11787#endif // QT_CONFIG(accessibility)
11788
11789#ifndef QT_NO_SHORTCUT
11814{
11815 Q_ASSERT(qApp);
11816 if (key.isEmpty())
11817 return 0;
11819 return QGuiApplicationPrivate::instance()->shortcutMap.addShortcut(this, key, context, qWidgetShortcutContextMatcher);
11820}
11821
11838{
11839 Q_ASSERT(qApp);
11840 if (id)
11841 QGuiApplicationPrivate::instance()->shortcutMap.removeShortcut(id, this, 0);
11842}
11843
11857{
11858 Q_ASSERT(qApp);
11859 if (id)
11860 QGuiApplicationPrivate::instance()->shortcutMap.setShortcutEnabled(enable, id, this, 0);
11861}
11862
11872{
11873 Q_ASSERT(qApp);
11874 if (id)
11875 QGuiApplicationPrivate::instance()->shortcutMap.setShortcutAutoRepeat(enable, id, this, 0);
11876}
11877#endif // QT_NO_SHORTCUT
11878
11888
11902{
11903 Q_D(QWidget);
11904 if (!isWindow()) {
11905 QWidget *p = parentWidget();
11906 const int parentChildCount = p->d_func()->children.size();
11907 if (parentChildCount < 2)
11908 return;
11909 const int from = p->d_func()->children.indexOf(this);
11910 Q_ASSERT(from >= 0);
11911 // Do nothing if the widget is already in correct stacking order _and_ created.
11912 if (from != parentChildCount -1)
11913 p->d_func()->children.move(from, parentChildCount - 1);
11915 create();
11916 else if (from == parentChildCount - 1)
11917 return;
11918
11919 QRegion region(rect());
11920 d->subtractOpaqueSiblings(region);
11921 d->invalidateBackingStore(region);
11922 }
11924 d->raise_sys();
11925
11926 if (d->extra && d->extra->hasWindowContainer)
11928
11931}
11932
11934{
11935 Q_Q(QWidget);
11936 if (q->isWindow() || q->testAttribute(Qt::WA_NativeWindow)) {
11937 q->windowHandle()->raise();
11938 } else if (renderToTexture) {
11939 if (QWidget *p = q->parentWidget()) {
11941 p->d_func()->invalidateBackingStore(effectiveRectFor(q->geometry()));
11942 }
11943 }
11944}
11945
11956{
11957 Q_D(QWidget);
11958 if (!isWindow()) {
11959 QWidget *p = parentWidget();
11960 const int parentChildCount = p->d_func()->children.size();
11961 if (parentChildCount < 2)
11962 return;
11963 const int from = p->d_func()->children.indexOf(this);
11964 Q_ASSERT(from >= 0);
11965 // Do nothing if the widget is already in correct stacking order _and_ created.
11966 if (from != 0)
11967 p->d_func()->children.move(from, 0);
11969 create();
11970 else if (from == 0)
11971 return;
11972 }
11974 d->lower_sys();
11975
11976 if (d->extra && d->extra->hasWindowContainer)
11978
11981}
11982
11984{
11985 Q_Q(QWidget);
11986 if (q->isWindow() || q->testAttribute(Qt::WA_NativeWindow)) {
11987 Q_ASSERT(q->testAttribute(Qt::WA_WState_Created));
11988 q->windowHandle()->lower();
11989 } else if (QWidget *p = q->parentWidget()) {
11991 p->d_func()->invalidateBackingStore(effectiveRectFor(q->geometry()));
11992 }
11993}
11994
12003{
12004 Q_D(QWidget);
12005 QWidget *p = parentWidget();
12006 if (!w || isWindow() || p != w->parentWidget() || this == w)
12007 return;
12008 if (p) {
12009 int from = p->d_func()->children.indexOf(this);
12010 int to = p->d_func()->children.indexOf(w);
12011 Q_ASSERT(from >= 0);
12012 Q_ASSERT(to >= 0);
12013 if (from < to)
12014 --to;
12015 // Do nothing if the widget is already in correct stacking order _and_ created.
12016 if (from != to)
12017 p->d_func()->children.move(from, to);
12019 create();
12020 else if (from == to)
12021 return;
12022 }
12024 d->stackUnder_sys(w);
12025
12028}
12029
12031{
12032 Q_Q(QWidget);
12033 if (QWidget *p = q->parentWidget()) {
12035 p->d_func()->invalidateBackingStore(effectiveRectFor(q->geometry()));
12036 }
12037}
12038
12080{
12081 Q_Q(const QWidget);
12082 if (!q->isWindow() || (q->windowType() == Qt::Desktop) || q->testAttribute(Qt::WA_DontShowOnScreen)) {
12083 // x2 = x1 + w - 1, so w/h = 1
12084 return QRect(0, 0, 1, 1);
12085 }
12086
12087 if (data.fstrut_dirty
12088 // ### Fix properly for 4.3
12089 && q->isVisible()
12090 && q->testAttribute(Qt::WA_WState_Created))
12091 const_cast<QWidgetPrivate *>(this)->updateFrameStrut();
12092
12093 return maybeTopData() ? maybeTopData()->frameStrut : QRect();
12094}
12095
12097{
12098 Q_Q(QWidget);
12099 if (q->data->fstrut_dirty) {
12100 if (QTLWExtra *te = maybeTopData()) {
12101 if (te->window && te->window->handle()) {
12102 const QMargins margins = te->window->frameMargins();
12103 if (!margins.isNull()) {
12104 te->frameStrut.setCoords(margins.left(), margins.top(), margins.right(), margins.bottom());
12105 q->data->fstrut_dirty = false;
12106 }
12107 }
12108 }
12109 }
12110}
12111
12112#ifdef QT_KEYPAD_NAVIGATION
12121bool QWidgetPrivate::navigateToDirection(Direction direction)
12122{
12123 QWidget *targetWidget = widgetInNavigationDirection(direction);
12124 if (targetWidget)
12125 targetWidget->setFocus();
12126 return (targetWidget != 0);
12127}
12128
12138QWidget *QWidgetPrivate::widgetInNavigationDirection(Direction direction)
12139{
12140 const QWidget *sourceWidget = QApplication::focusWidget();
12141 if (!sourceWidget)
12142 return nullptr;
12143 const QRect sourceRect = sourceWidget->rect().translated(sourceWidget->mapToGlobal(QPoint()));
12144 const int sourceX =
12146 (sourceRect.left() + (sourceRect.right() - sourceRect.left()) / 2)
12147 :(direction == DirectionEast ? sourceRect.right() : sourceRect.left());
12148 const int sourceY =
12150 (sourceRect.top() + (sourceRect.bottom() - sourceRect.top()) / 2)
12151 :(direction == DirectionSouth ? sourceRect.bottom() : sourceRect.top());
12152 const QPoint sourcePoint(sourceX, sourceY);
12153 const QPoint sourceCenter = sourceRect.center();
12154 const QWidget *sourceWindow = sourceWidget->window();
12155
12156 QWidget *targetWidget = nullptr;
12157 int shortestDistance = INT_MAX;
12158
12159 const auto targetCandidates = QApplication::allWidgets();
12160 for (QWidget *targetCandidate : targetCandidates) {
12161
12162 const QRect targetCandidateRect = targetCandidate->rect().translated(targetCandidate->mapToGlobal(QPoint()));
12163
12164 // For focus proxies, the child widget handling the focus can have keypad navigation focus,
12165 // but the owner of the proxy cannot.
12166 // Additionally, empty widgets should be ignored.
12167 if (targetCandidate->focusProxy() || targetCandidateRect.isEmpty())
12168 continue;
12169
12170 // Only navigate to a target widget that...
12171 if ( targetCandidate != sourceWidget
12172 // ...takes the focus,
12173 && targetCandidate->focusPolicy() & Qt::TabFocus
12174 // ...is above if DirectionNorth,
12175 && !(direction == DirectionNorth && targetCandidateRect.bottom() > sourceRect.top())
12176 // ...is on the right if DirectionEast,
12177 && !(direction == DirectionEast && targetCandidateRect.left() < sourceRect.right())
12178 // ...is below if DirectionSouth,
12179 && !(direction == DirectionSouth && targetCandidateRect.top() < sourceRect.bottom())
12180 // ...is on the left if DirectionWest,
12181 && !(direction == DirectionWest && targetCandidateRect.right() > sourceRect.left())
12182 // ...is enabled,
12183 && targetCandidate->isEnabled()
12184 // ...is visible,
12185 && targetCandidate->isVisible()
12186 // ...is in the same window,
12187 && targetCandidate->window() == sourceWindow) {
12188 const int targetCandidateDistance = [](const QPoint &sourcePoint,
12189 const QRect &targetCandidateRect) {
12190 int dx = 0;
12191 int dy = 0;
12192 if (p.x() < r.left())
12193 dx = r.left() - p.x();
12194 else if (p.x() > r.right())
12195 dx = p.x() - r.right();
12196 if (p.y() < r.top())
12197 dy = r.top() - p.y();
12198 else if (p.y() > r.bottom())
12199 dy = p.y() - r.bottom();
12200 return dx + dy;
12201 }();
12202 if (targetCandidateDistance < shortestDistance) {
12203 shortestDistance = targetCandidateDistance;
12204 targetWidget = targetCandidate;
12205 }
12206 }
12207 }
12208 return targetWidget;
12209}
12210
12222bool QWidgetPrivate::canKeypadNavigate(Qt::Orientation orientation)
12223{
12224 return orientation == Qt::Horizontal?
12225 (QWidgetPrivate::widgetInNavigationDirection(QWidgetPrivate::DirectionEast)
12226 || QWidgetPrivate::widgetInNavigationDirection(QWidgetPrivate::DirectionWest))
12227 :(QWidgetPrivate::widgetInNavigationDirection(QWidgetPrivate::DirectionNorth)
12228 || QWidgetPrivate::widgetInNavigationDirection(QWidgetPrivate::DirectionSouth));
12229}
12242bool QWidgetPrivate::inTabWidget(QWidget *widget)
12243{
12244 for (QWidget *tabWidget = widget; tabWidget; tabWidget = tabWidget->parentWidget())
12245 if (qobject_cast<const QTabWidget*>(tabWidget))
12246 return true;
12247 return false;
12248}
12249#endif
12250
12258void QWidget::setBackingStore(QBackingStore *store)
12259{
12260 // ### createWinId() ??
12261
12262 if (!isWindow())
12263 return;
12264
12265 Q_D(QWidget);
12266
12267 QTLWExtra *topData = d->topData();
12268 if (topData->backingStore == store)
12269 return;
12270
12271 QBackingStore *oldStore = topData->backingStore;
12272 delete topData->backingStore;
12273 topData->backingStore = store;
12274
12275 QWidgetRepaintManager *repaintManager = d->maybeRepaintManager();
12276 if (!repaintManager)
12277 return;
12278
12279 if (isWindow()) {
12280 if (repaintManager->backingStore() != oldStore && repaintManager->backingStore() != store)
12281 delete repaintManager->backingStore();
12282 repaintManager->setBackingStore(store);
12283 }
12284}
12285
12292{
12293 Q_D(const QWidget);
12294 QTLWExtra *extra = d->maybeTopData();
12295 if (extra && extra->backingStore)
12296 return extra->backingStore;
12297
12298 QWidgetRepaintManager *repaintManager = d->maybeRepaintManager();
12299 return repaintManager ? repaintManager->backingStore() : nullptr;
12300}
12301
12303{
12304 if (left)
12305 *left = (int)leftLayoutItemMargin;
12306 if (top)
12307 *top = (int)topLayoutItemMargin;
12308 if (right)
12310 if (bottom)
12312}
12313
12315{
12320 return;
12321
12322 Q_Q(QWidget);
12323 leftLayoutItemMargin = (signed char)left;
12324 topLayoutItemMargin = (signed char)top;
12325 rightLayoutItemMargin = (signed char)right;
12326 bottomLayoutItemMargin = (signed char)bottom;
12327 q->updateGeometry();
12328}
12329
12331{
12332 Q_Q(QWidget);
12333 QStyleOption myOpt;
12334 if (!opt) {
12335 myOpt.initFrom(q);
12336 myOpt.rect.setRect(0, 0, 32768, 32768); // arbitrary
12337 opt = &myOpt;
12338 }
12339
12340 QRect liRect = q->style()->subElementRect(element, opt, q);
12341 if (liRect.isValid()) {
12342 leftLayoutItemMargin = (signed char)(opt->rect.left() - liRect.left());
12343 topLayoutItemMargin = (signed char)(opt->rect.top() - liRect.top());
12344 rightLayoutItemMargin = (signed char)(liRect.right() - opt->rect.right());
12345 bottomLayoutItemMargin = (signed char)(liRect.bottom() - opt->rect.bottom());
12346 } else {
12351 }
12352}
12353// resets the Qt::WA_QuitOnClose attribute to the default value for transient widgets.
12355{
12356 Q_Q(QWidget);
12357
12358 if (!q->parentWidget()) {
12359 Qt::WindowType type = q->windowType();
12360 if (type == Qt::Widget || type == Qt::SubWindow)
12361 type = Qt::Window;
12362 if (type != Qt::Widget && type != Qt::Window && type != Qt::Dialog)
12363 q->setAttribute(Qt::WA_QuitOnClose, false);
12364 }
12365}
12366
12368{
12370 if (!wd->textureChildSeen)
12371 return;
12372 if (end)
12373 wd->endCompose();
12374 else
12375 wd->beginCompose();
12376 for (int i = 0; i < wd->children.size(); ++i) {
12378 if (w && !w->isWindow() && !w->isHidden() && QWidgetPrivate::get(w)->textureChildSeen)
12380 }
12381}
12382
12384{
12385 return widget->data;
12386}
12387
12389{
12390 return widget->d_func();
12391}
12392
12393
12394#if QT_CONFIG(graphicsview)
12404QGraphicsProxyWidget *QWidget::graphicsProxyWidget() const
12405{
12406 Q_D(const QWidget);
12407 if (d->extra) {
12408 return d->extra->proxyWidget;
12409 }
12410 return nullptr;
12411}
12412#endif
12413
12414#ifndef QT_NO_GESTURES
12421void QWidget::grabGesture(Qt::GestureType gesture, Qt::GestureFlags flags)
12422{
12423 Q_D(QWidget);
12424 d->gestureContext.insert(gesture, flags);
12425 (void)QGestureManager::instance(); // create a gesture manager
12426}
12427
12435{
12436 // if you modify this function, check the inlined version in ~QWidget, too
12437 Q_D(QWidget);
12438 if (d->gestureContext.remove(gesture)) {
12440 manager->cleanupCachedGestures(this, gesture);
12441 }
12442}
12443#endif // QT_NO_GESTURES
12444
12458void QWidget::destroy(bool destroyWindow, bool destroySubWindows)
12459{
12460 Q_D(QWidget);
12461
12462 d->aboutToDestroy();
12463 if (!isWindow() && parentWidget())
12464 parentWidget()->d_func()->invalidateBackingStore(d->effectiveRectFor(geometry()));
12465 d->deactivateWidgetCleanup();
12466
12467 if ((windowType() == Qt::Popup) && qApp)
12468 qApp->d_func()->closePopup(this);
12469
12470 if (this == qApp->activeWindow())
12472 if (QWidget::mouseGrabber() == this)
12473 releaseMouse();
12474 if (QWidget::keyboardGrabber() == this)
12476
12478
12479 if (windowType() != Qt::Desktop) {
12480 if (destroySubWindows) {
12481 QObjectList childList(children());
12482 for (int i = 0; i < childList.size(); i++) {
12483 QWidget *widget = qobject_cast<QWidget *>(childList.at(i));
12485 if (widget->windowHandle()) {
12486 widget->destroy();
12487 }
12488 }
12489 }
12490 }
12491 if (destroyWindow) {
12492 d->deleteTLSysExtra();
12493 } else {
12495 d->hide_sys();
12496 }
12497 }
12498
12499 d->setWinId(0);
12500 }
12501}
12502
12514{
12515 qWarning("QWidget::paintEngine: Should no longer be called");
12516
12517#ifdef Q_OS_WIN
12518 // We set this bit which is checked in setAttribute for
12519 // Qt::WA_PaintOnScreen. We do this to allow these two scenarios:
12520 //
12521 // 1. Users accidentally set Qt::WA_PaintOnScreen on X and port to
12522 // Windows which would mean suddenly their widgets stop working.
12523 //
12524 // 2. Users set paint on screen and subclass paintEngine() to
12525 // return 0, in which case we have a "hole" in the backingstore
12526 // allowing use of GDI or DirectX directly.
12527 //
12528 // 1 is WRONG, but to minimize silent failures, we have set this
12529 // bit to ignore the setAttribute call. 2. needs to be
12530 // supported because its our only means of embedding native
12531 // graphics stuff.
12532 const_cast<QWidgetPrivate *>(d_func())->noPaintOnScreen = 1;
12533#endif
12534
12535 return nullptr; //##### @@@
12536}
12537
12538// Do not call QWindow::mapToGlobal() until QPlatformWindow is properly showing.
12539static inline bool canMapPosition(QWindow *window)
12540{
12541 return window->handle() && !qt_window_private(window)->resizeEventPending;
12542}
12543
12544#if QT_CONFIG(graphicsview)
12545static inline QGraphicsProxyWidget *graphicsProxyWidget(const QWidget *w)
12546{
12547 QGraphicsProxyWidget *result = nullptr;
12548 const QWidgetPrivate *d = qt_widget_private(const_cast<QWidget *>(w));
12549 if (d->extra)
12550 result = d->extra->proxyWidget;
12551 return result;
12552}
12553#endif // QT_CONFIG(graphicsview)
12554
12559
12561{
12563 result.window = nullptr;
12564 for ( ; w ; w = w->parentWidget()) {
12565#if QT_CONFIG(graphicsview)
12566 if (QGraphicsProxyWidget *qgpw = graphicsProxyWidget(w)) {
12567 if (const QGraphicsScene *scene = qgpw->scene()) {
12568 const QList <QGraphicsView *> views = scene->views();
12569 if (!views.isEmpty()) {
12570 result.transform *= qgpw->sceneTransform();
12571 result.transform *= views.first()->viewportTransform();
12572 w = views.first()->viewport();
12573 }
12574 }
12575 }
12576#endif // QT_CONFIG(graphicsview)
12577 QWindow *window = w->windowHandle();
12578 if (window && canMapPosition(window)) {
12579 result.window = window;
12580 break;
12581 }
12582
12583 const QPoint topLeft = w->geometry().topLeft();
12584 result.transform.translate(topLeft.x(), topLeft.y());
12585 if (w->isWindow())
12586 break;
12587 }
12588 return result;
12589}
12590
12602{
12604 const QPointF g = t.transform.map(pos);
12605 return t.window ? t.window->mapToGlobal(g) : g;
12606}
12607
12612{
12613 return mapToGlobal(QPointF(pos)).toPoint();
12614}
12615
12626{
12628 const QPointF windowLocal = t.window ? t.window->mapFromGlobal(pos) : pos;
12629 return t.transform.inverted().map(windowLocal);
12630}
12631
12636{
12637 return mapFromGlobal(QPointF(pos)).toPoint();
12638}
12639
12642static bool mouseGrabWithCursor = false;
12643static QWidget *keyboardGrb = nullptr;
12644
12645static inline QWindow *grabberWindow(const QWidget *w)
12646{
12647 QWindow *window = w->windowHandle();
12648 if (!window)
12649 if (const QWidget *nativeParent = w->nativeParentWidget())
12650 window = nativeParent->windowHandle();
12651 return window;
12652}
12653
12654#ifndef QT_NO_CURSOR
12655static void grabMouseForWidget(QWidget *widget, const QCursor *cursor = nullptr)
12656#else
12657static void grabMouseForWidget(QWidget *widget)
12658#endif
12659{
12660 if (qt_mouseGrb)
12662
12663 mouseGrabWithCursor = false;
12665#ifndef QT_NO_CURSOR
12666 if (cursor) {
12667 mouseGrabWithCursor = true;
12669 }
12670#endif // !QT_NO_CURSOR
12671 window->setMouseGrabEnabled(true);
12672 }
12673
12675 qt_pressGrab = nullptr;
12676}
12677
12679{
12680 if (qt_mouseGrb == widget) {
12682#ifndef QT_NO_CURSOR
12683 if (mouseGrabWithCursor) {
12685 mouseGrabWithCursor = false;
12686 }
12687#endif // !QT_NO_CURSOR
12688 window->setMouseGrabEnabled(false);
12689 }
12690 }
12691 qt_mouseGrb = nullptr;
12692}
12693
12723{
12724 grabMouseForWidget(this);
12725}
12726
12743#ifndef QT_NO_CURSOR
12745{
12746 grabMouseForWidget(this, &cursor);
12747}
12748#endif
12749
12751{
12752 // This is like a combination of grab/releaseMouse() but with error checking
12753 // and it has no effect on the result of mouseGrabber().
12754 Q_Q(QWidget);
12756 return window ? window->setMouseGrabEnabled(grab) : false;
12757}
12758
12767{
12769}
12770
12791{
12792 if (keyboardGrb)
12793 keyboardGrb->releaseKeyboard();
12794 if (QWindow *window = grabberWindow(this))
12795 window->setKeyboardGrabEnabled(true);
12796 keyboardGrb = this;
12797}
12798
12800{
12801 // This is like a combination of grab/releaseKeyboard() but with error
12802 // checking and it has no effect on the result of keyboardGrabber().
12803 Q_Q(QWidget);
12805 return window ? window->setKeyboardGrabEnabled(grab) : false;
12806}
12807
12816{
12817 if (keyboardGrb == this) {
12818 if (QWindow *window = grabberWindow(this))
12819 window->setKeyboardGrabEnabled(false);
12820 keyboardGrb = nullptr;
12821 }
12822}
12823
12835{
12836 if (qt_mouseGrb)
12837 return qt_mouseGrb;
12838 return qt_pressGrab;
12839}
12840
12852{
12853 return keyboardGrb;
12854}
12855
12881{
12882 QWindow *const wnd = window()->windowHandle();
12883
12884 if (wnd)
12885 wnd->requestActivate();
12886}
12887
12896{
12897 QScreen *screen = this->screen();
12898
12899 if (!screen) {
12900 if (m == PdmDpiX || m == PdmDpiY)
12901 return 72;
12902 return QPaintDevice::metric(m);
12903 }
12904
12905 auto resolveDevicePixelRatio = [this, screen]() -> qreal {
12906
12907 // Note: keep in sync with QBackingStorePrivate::backingStoreDevicePixelRatio()!
12908 static bool downscale = qEnvironmentVariableIntValue("QT_WIDGETS_HIGHDPI_DOWNSCALE") > 0;
12909 QWindow *window = this->window()->windowHandle();
12910 if (window)
12911 return downscale ? std::ceil(window->devicePixelRatio()) : window->devicePixelRatio();
12912 return screen->devicePixelRatio();
12913 };
12914
12915 switch (m) {
12916 case PdmWidth:
12917 return data->crect.width();
12918 case PdmWidthMM:
12919 return data->crect.width() * screen->physicalSize().width() / screen->geometry().width();
12920 case PdmHeight:
12921 return data->crect.height();
12922 case PdmHeightMM:
12923 return data->crect.height() * screen->physicalSize().height() / screen->geometry().height();
12924 case PdmDepth:
12925 return screen->depth();
12926 case PdmDpiX:
12927 for (const QWidget *p = this; p; p = p->parentWidget()) {
12928 if (p->d_func()->extra && p->d_func()->extra->customDpiX)
12929 return p->d_func()->extra->customDpiX;
12930 }
12932 case PdmDpiY:
12933 for (const QWidget *p = this; p; p = p->parentWidget()) {
12934 if (p->d_func()->extra && p->d_func()->extra->customDpiY)
12935 return p->d_func()->extra->customDpiY;
12936 }
12938 case PdmPhysicalDpiX:
12940 case PdmPhysicalDpiY:
12943 return resolveDevicePixelRatio();
12945 return QPaintDevice::devicePixelRatioFScale() * resolveDevicePixelRatio();
12946 default:
12947 break;
12948 }
12949 return QPaintDevice::metric(m);
12950}
12951
12958{
12959 const QPalette &pal = palette();
12960 painter->d_func()->state->pen = QPen(pal.brush(foregroundRole()), 1);
12961 painter->d_func()->state->bgBrush = pal.brush(backgroundRole());
12962 QFont f(font(), const_cast<QWidget *>(this));
12963 painter->d_func()->state->deviceFont = f;
12964 painter->d_func()->state->font = f;
12965}
12966
12973{
12974 return d_func()->redirected(offset);
12975}
12976
12983{
12984 // Someone sent a paint event directly to the widget
12985 if (!d_func()->redirectDev)
12986 return nullptr;
12987
12988 QPainter *sp = d_func()->sharedPainter();
12989 if (!sp || !sp->isActive())
12990 return nullptr;
12991
12992 if (sp->paintEngine()->paintDevice() != d_func()->redirectDev)
12993 return nullptr;
12994
12995 return sp;
12996}
12997
13020void QWidget::setMask(const QRegion &newMask)
13021{
13022 Q_D(QWidget);
13023
13024 d->createExtra();
13025 if (newMask == d->extra->mask)
13026 return;
13027
13028#ifndef QT_NO_BACKINGSTORE
13029 const QRegion oldMask(d->extra->mask);
13030#endif
13031
13032 d->extra->mask = newMask;
13033 d->extra->hasMask = !newMask.isEmpty();
13034
13036 return;
13037
13038 d->setMask_sys(newMask);
13039
13040#ifndef QT_NO_BACKINGSTORE
13041 if (!isVisible())
13042 return;
13043
13044 if (!d->extra->hasMask) {
13045 // Mask was cleared; update newly exposed area.
13046 QRegion expose(rect());
13047 expose -= oldMask;
13048 if (!expose.isEmpty()) {
13049 d->setDirtyOpaqueRegion();
13050 update(expose);
13051 }
13052 return;
13053 }
13054
13055 if (!isWindow()) {
13056 // Update newly exposed area on the parent widget.
13057 QRegion parentExpose(rect());
13058 parentExpose -= newMask;
13059 if (!parentExpose.isEmpty()) {
13060 d->setDirtyOpaqueRegion();
13061 parentExpose.translate(data->crect.topLeft());
13062 parentWidget()->update(parentExpose);
13063 }
13064
13065 // Update newly exposed area on this widget
13066 if (!oldMask.isEmpty())
13067 update(newMask - oldMask);
13068 }
13069#endif
13070}
13071
13073{
13074 Q_Q(QWidget);
13075 if (QWindow *window = q->windowHandle())
13076 window->setMask(region);
13077}
13078
13105{
13107}
13108
13117{
13118 Q_D(QWidget);
13119 if (!d->extra || !d->extra->hasMask)
13120 return;
13121 setMask(QRegion());
13122}
13123
13125{
13126 Q_ASSERT(widgetAsObject->isWidgetType());
13127 Q_ASSERT(!newParent || newParent->isWidgetType());
13128 QWidget *widget = static_cast<QWidget*>(widgetAsObject);
13129 widget->setParent(static_cast<QWidget*>(newParent));
13130}
13131
13133{
13134 Q_Q(const QWidget);
13135 std::string flags = QObjectPrivate::flagsForDumping();
13137 flags += 'F';
13138 if (q->isVisible()) {
13139 std::stringstream s;
13140 s << '<'
13141 << q->width() << 'x' << q->height()
13142 << std::showpos << q->x() << q->y()
13143 << '>';
13144 flags += s.str();
13145 } else {
13146 flags += 'I';
13147 }
13148 return flags;
13149}
13150
13152{
13153#if QT_CONFIG(xcb)
13154 Q_Q(QWidget);
13155
13156 if (!q->windowHandle())
13157 return;
13158
13159 QXcbWindow::WindowTypes wmWindowType = QXcbWindow::None;
13160 if (q->testAttribute(Qt::WA_X11NetWmWindowTypeDesktop))
13161 wmWindowType |= QXcbWindow::Desktop;
13162 if (q->testAttribute(Qt::WA_X11NetWmWindowTypeDock))
13163 wmWindowType |= QXcbWindow::Dock;
13164 if (q->testAttribute(Qt::WA_X11NetWmWindowTypeToolBar))
13165 wmWindowType |= QXcbWindow::Toolbar;
13166 if (q->testAttribute(Qt::WA_X11NetWmWindowTypeMenu))
13167 wmWindowType |= QXcbWindow::Menu;
13168 if (q->testAttribute(Qt::WA_X11NetWmWindowTypeUtility))
13169 wmWindowType |= QXcbWindow::Utility;
13170 if (q->testAttribute(Qt::WA_X11NetWmWindowTypeSplash))
13171 wmWindowType |= QXcbWindow::Splash;
13172 if (q->testAttribute(Qt::WA_X11NetWmWindowTypeDialog))
13173 wmWindowType |= QXcbWindow::Dialog;
13174 if (q->testAttribute(Qt::WA_X11NetWmWindowTypeDropDownMenu))
13175 wmWindowType |= QXcbWindow::DropDownMenu;
13176 if (q->testAttribute(Qt::WA_X11NetWmWindowTypePopupMenu))
13177 wmWindowType |= QXcbWindow::PopupMenu;
13178 if (q->testAttribute(Qt::WA_X11NetWmWindowTypeToolTip))
13179 wmWindowType |= QXcbWindow::Tooltip;
13180 if (q->testAttribute(Qt::WA_X11NetWmWindowTypeNotification))
13181 wmWindowType |= QXcbWindow::Notification;
13182 if (q->testAttribute(Qt::WA_X11NetWmWindowTypeCombo))
13183 wmWindowType |= QXcbWindow::Combo;
13184 if (q->testAttribute(Qt::WA_X11NetWmWindowTypeDND))
13185 wmWindowType |= QXcbWindow::Dnd;
13186
13187 if (wmWindowType == QXcbWindow::None && skipIfMissing)
13188 return;
13189
13190 if (auto *xcbWindow = dynamic_cast<QXcbWindow*>(q->windowHandle()->handle()))
13191 xcbWindow->setWindowType(wmWindowType);
13192#else
13193 Q_UNUSED(skipIfMissing);
13194#endif
13195}
13196
13203{
13204 Q_Q(const QWidget);
13205 const QWidgetList &children = q->findChildren<QWidget *>(Qt::FindChildrenRecursively);
13206 for (const auto *child : children) {
13207 if (child->focusPolicy() == policy && child->isEnabled()
13208 && (!excludeChildrenOf || !excludeChildrenOf->isAncestorOf(child))) {
13209 return true;
13210 }
13211 }
13212 return false;
13213}
13214
13215#ifndef QT_NO_DEBUG_STREAM
13216
13217namespace {
13218QDebug operator<<(QDebug debug, const WidgetAttributes &attributes)
13219{
13220 const QDebugStateSaver saver(debug);
13221 debug.nospace();
13222 debug << '[';
13223 if (const QWidget *widget = attributes.widget) {
13224 const QMetaObject *qtMo = qt_getEnumMetaObject(Qt::WA_AttributeCount);
13225 const QMetaEnum me = qtMo->enumerator(qtMo->indexOfEnumerator("WidgetAttribute"));
13226 int count = 0;
13227 for (int a = 0; a < Qt::WA_AttributeCount; ++a) {
13228 if (widget->testAttribute(static_cast<Qt::WidgetAttribute>(a))) {
13229 if (count++)
13230 debug << ',';
13231 debug << me.valueToKey(a);
13232 }
13233 }
13234 }
13235 debug << ']';
13236 return debug;
13237}
13238}
13239
13241{
13242 const QDebugStateSaver saver(debug);
13243 debug.nospace();
13244 if (widget) {
13245 debug << widget->metaObject()->className() << '(' << (const void *)widget;
13246 if (!widget->objectName().isEmpty())
13247 debug << ", name=" << widget->objectName();
13248 if (debug.verbosity() > 2) {
13249 const QRect geometry = widget->geometry();
13251 if (widget->isVisible())
13252 debug << ", visible";
13253 if (!widget->isEnabled())
13254 debug << ", disabled";
13255 debug << ", states=" << widget->windowState()
13256 << ", type=" << widget->windowType() << ", flags=" << widget->windowFlags();
13257 debug << ", attributes=" << WidgetAttributes{widget};
13258 if (widget->isWindow())
13259 debug << ", window";
13260 debug << ", " << geometry.width() << 'x' << geometry.height()
13261 << Qt::forcesign << geometry.x() << geometry.y() << Qt::noforcesign;
13262 if (frameGeometry != geometry) {
13263 const QMargins margins(geometry.x() - frameGeometry.x(),
13264 geometry.y() - frameGeometry.y(),
13265 frameGeometry.right() - geometry.right(),
13266 frameGeometry.bottom() - geometry.bottom());
13267 debug << ", margins=" << margins;
13268 }
13269 debug << ", devicePixelRatio=" << widget->devicePixelRatio();
13270 if (const WId wid = widget->internalWinId())
13271 debug << ", winId=0x" << Qt::hex << wid << Qt::dec;
13272 }
13273 debug << ')';
13274 } else {
13275 debug << "QWidget(0x0)";
13276 }
13277 return debug;
13278}
13279#endif // !QT_NO_DEBUG_STREAM
13280
13281
13282// *************************** Focus abstraction ************************************
13283
13284#define FOCUS_NEXT(w) w->d_func()->focus_next
13285#define FOCUS_PREV(w) w->d_func()->focus_prev
13286
13297
13310{
13311 Q_Q(QWidget);
13312 if (!isFocusChainConsistent()) {
13313#ifdef QT_DEBUG
13314 if (rules.testFlag(FocusChainRemovalRule::AssertConsistency))
13315 qFatal() << q << "has inconsistent focus chain.";
13316#endif
13317 qCDebug(lcWidgetFocus) << q << "wasn't removed, because of inconsistent focus chain.";
13318 return false;
13319 }
13320
13321 if (!isInFocusChain()) {
13322 qCDebug(lcWidgetFocus) << q << "wasn't removed, because it is not part of a focus chain.";
13323 return false;
13324 }
13325
13326 if (rules.testFlag(FocusChainRemovalRule::EnsureFocusOut))
13327 q->focusNextPrevChild(direction == FocusDirection::Next);
13328
13332 qCDebug(lcWidgetFocus) << q << "removed from focus chain.";
13333 return true;
13334}
13335
13341{
13342 Q_Q(QWidget);
13343 qCDebug(lcWidgetFocus) << "Initializing focus chain of" << q;
13344 FOCUS_PREV(q) = q;
13345 FOCUS_NEXT(q) = q;
13346}
13347
13356{
13357 Q_Q(QWidget);
13358 QWidgetList focusChildrenInsideChain;
13359 QDuplicateTracker<QWidget *> seen;
13361 while (q->isAncestorOf(widget)
13362 && !seen.hasSeen(widget)
13363 && widget != q->window()) {
13364 if (widget->focusPolicy() != Qt::NoFocus)
13365 focusChildrenInsideChain << widget;
13366
13369 }
13370
13371 const QWidgetList children = q->findChildren<QWidget *>(Qt::FindDirectChildrenOnly);
13372 QWidgetList focusChildrenOutsideChain;
13373 for (auto *child : children) {
13374 if (!focusChildrenInsideChain.contains(child))
13375 focusChildrenOutsideChain << child;
13376 }
13377 if (focusChildrenOutsideChain.isEmpty())
13378 return;
13379
13380 QWidget *previous = q;
13381 for (auto *child : focusChildrenOutsideChain) {
13382 child->d_func()->insertIntoFocusChain(direction, previous);
13383 previous = child;
13384 }
13385}
13386
13394{
13395 Q_Q(QWidget);
13398 QWidget *previous = FOCUS_PREV(q);
13399
13400 switch (direction) {
13402 if (previous == position) {
13403 qCDebug(lcWidgetFocus) << "No-op insertion." << q << "is already before" << position;
13404 return false;
13405 }
13406
13408
13413 qCDebug(lcWidgetFocus) << q << "inserted after" << position;
13414 break;
13415
13417 if (next == position) {
13418 qCDebug(lcWidgetFocus) << "No-op insertion." << q << "is already after" << position;
13419 return false;
13420 }
13421
13423
13428 qCDebug(lcWidgetFocus) << q << "inserted before" << position;
13429 break;
13430 }
13431
13433 return true;
13434}
13435
13446{
13447 if (toBeInserted.isEmpty()) {
13448 qCDebug(lcWidgetFocus) << "No-op insertion of an empty list";
13449 return false;
13450 }
13451
13452 Q_ASSERT_X(!toBeInserted.contains(position),
13454 "Coding error: toBeInserted contains position");
13455
13456 QWidget *first = toBeInserted.constFirst();
13457 QWidget *last = toBeInserted.constLast();
13458
13459 // Call QWidget override to log accordingly
13460 if (toBeInserted.count() == 1)
13461 return first->d_func()->insertIntoFocusChain(direction, position);
13462
13463 Q_ASSERT(first != last);
13464 switch (direction) {
13466 if (FOCUS_PREV(position) == last) {
13467 qCDebug(lcWidgetFocus) << "No-op insertion." << toBeInserted << "is already before"
13468 << position;
13469 return false;
13470 }
13473 FOCUS_NEXT(last) = position;
13474 FOCUS_PREV(position) = last;
13475 qCDebug(lcWidgetFocus) << toBeInserted << "inserted before" << position;
13476 break;
13478 if (FOCUS_PREV(position) == last) {
13479 qCDebug(lcWidgetFocus) << "No-op insertion." << toBeInserted << "is already after"
13480 << position;
13481 return false;
13482 }
13487 qCDebug(lcWidgetFocus) << toBeInserted << "inserted after" << position;
13488 break;
13489 }
13490
13491 Q_ASSERT(position->d_func()->isFocusChainConsistent());
13492 return true;
13493}
13494
13501{
13502 QWidgetList path({from});
13503 if (from == to)
13504 return path;
13505
13506 QWidget *current = from;
13507 do {
13508 switch (direction) {
13510 current = current->previousInFocusChain();
13511 break;
13513 current = current->nextInFocusChain();
13514 break;
13515 }
13516 if (path.contains(current))
13517 return QWidgetList();
13518 path << current;
13519 } while (current != to);
13520
13521 return path;
13522}
13523
13531 QWidget *to,
13533{
13534 // Check if there is a path from->to in direction
13535 const QWidgetList path = focusPath(from, to , direction);
13536 if (path.isEmpty()) {
13537 qCDebug(lcWidgetFocus) << "No-op removal. Focus chain from" << from << "doesn't lead to " << to;
13538 return QWidgetList();
13539 }
13540
13541 QWidget *first = path.constFirst();
13542 QWidget *last = path.constLast();
13543 if (first == last) {
13544 first->d_func()->removeFromFocusChain();
13545 return QWidgetList({first});
13546 }
13547
13550 FOCUS_PREV(first) = last;
13551 FOCUS_NEXT(last) = first;
13552 qCDebug(lcWidgetFocus) << path << "removed from focus chain";
13553 return path;
13554}
13555
13562{
13563 Q_Q(QWidget);
13564 // Since we need to repeat the same logic for both 'first' and 'second', we add a function
13565 // that determines the last focus child for a widget, taking proxies and compound widgets into
13566 // account. If the target is not a compound widget (it doesn't have a focus proxy that points
13567 // to a child), 'lastFocusChild' will be set to the target itself.
13568 QWidget *lastFocusChild = q;
13569
13570 QWidget *focusProxy = deepestFocusProxy();
13571 if (!focusProxy) {
13572 // QTBUG-81097: Another case is possible here. We can have a child
13573 // widget, that sets its focusProxy() to the parent (target).
13574 // An example of such widget is a QLineEdit, nested into
13575 // a QAbstractSpinBox. In this case such widget should be considered
13576 // the last focus child.
13577 for (auto *object : std::as_const(q->children())) {
13579 if (w && w->focusProxy() == q) {
13580 lastFocusChild = w;
13581 break;
13582 }
13583 }
13584 } else if (q->isAncestorOf(focusProxy)) {
13585 lastFocusChild = focusProxy;
13586 for (QWidget *focusNext = lastFocusChild->nextInFocusChain();
13587 focusNext != focusProxy && q->isAncestorOf(focusNext)
13588 && focusNext->window() == focusProxy->window();
13589 focusNext = focusNext->nextInFocusChain()) {
13590 if (focusNext == noFurtherThan)
13591 break;
13592 if (focusNext->focusPolicy() != Qt::NoFocus)
13593 lastFocusChild = focusNext;
13594 }
13595 }
13596 return lastFocusChild;
13597};
13598
13612{
13613 Q_Q(const QWidget);
13614 return !(FOCUS_NEXT(q) == q && FOCUS_PREV(q) == q);
13615}
13616
13640{
13641 Q_Q(const QWidget);
13642 const bool skip = !QLoggingCategory("qt.widgets.focus").isDebugEnabled();
13643 if (skip)
13644 return true;
13645
13646 if (!isInFocusChain())
13647 return true;
13648
13649 const QWidget *position = q;
13650
13651 for (int i = 0; i < QApplication::allWidgets().count(); ++i) {
13653 qCDebug(lcWidgetFocus) << "Nullptr found at:" << position
13654 << "Previous pointing to" << FOCUS_PREV(position)
13655 << "Next pointing to" << FOCUS_NEXT(position);
13656 return false;
13657 }
13660 qCDebug(lcWidgetFocus) << "Inconsistent focus chain at:" << position
13661 << "Previous pointing to" << FOCUS_PREV(FOCUS_NEXT(position))
13662 << "Next pointing to" << FOCUS_NEXT(FOCUS_PREV(position));
13663 return false;
13664 }
13666 if (position == q)
13667 return true;
13668
13669 }
13670
13671 qCDebug(lcWidgetFocus) << "Focus chain leading from" << q << "to" << position << "is not closed.";
13672 return false;
13673}
13674
13675#undef FOCUS_NEXT
13676#undef FOCUS_PREV
13677
13678
13680
13681#include "moc_qwidget.cpp"
13682#include "moc_qwidget_p.cpp"
static bool isEqual(const aiUVTransform &a, const aiUVTransform &b)
IOBluetoothDevice * device
static void(* destroyed)(QAbstractDeclarativeData *, QObject *)
Definition qobject_p.h:66
\inmodule QtGui
The QActionEvent class provides an event that is generated when a QAction is added,...
QObjectList associatedObjects
Definition qaction_p.h:67
The QAction class provides an abstraction for user commands that can be added to different user inter...
Definition qaction.h:30
QList< QObject * > associatedObjects() const
Definition qaction.cpp:505
static QWidget * focus_widget
static QWidget * hidden_focus_widget
static void setFocusWidget(QWidget *focus, Qt::FocusReason reason)
static QWidget * focusNextPrevChild_helper(QWidget *toplevel, bool next, bool *wrappingOccurred=nullptr)
internal Helper function that returns the new focus widget, but does not set the focus reason.
static bool isBlockedByModal(QWidget *widget)
static void setActiveWindow(QWidget *act)
static QStyle * style()
Returns the application's style object.
static QPalette palette()
Returns the current application palette.
static QWidget * activeModalWidget()
Returns the active modal widget.
static QWidget * focusWidget()
Returns the application widget that has the keyboard input focus, or \nullptr if no widget in this ap...
static QFont font()
Returns the default application font.
static QWidget * activePopupWidget()
Returns the active popup widget.
static QWidget * activeWindow()
Returns the application top-level window that has the keyboard input focus, or \nullptr if no applica...
static QWidgetList allWidgets()
Returns a list of all the widgets in the application.
static QSurface::SurfaceType surfaceTypeForConfig(const QPlatformBackingStoreRhiConfig &config)
static bool checkForceRhi(QPlatformBackingStoreRhiConfig *outConfig, QSurface::SurfaceType *outType)
The QBackingStore class provides a drawing area for QWindow.
QPlatformBackingStore * handle() const
Returns a pointer to the QPlatformBackingStore implementation.
\inmodule QtGui
Definition qbitmap.h:16
\inmodule QtGui
Definition qbrush.h:30
bool isOpaque() const
Returns true if the brush is fully opaque otherwise false.
Definition qbrush.cpp:830
QPixmap texture() const
Returns the custom brush pattern, or a null pixmap if no custom brush pattern has been set.
Definition qbrush.cpp:711
Qt::BrushStyle style() const
Returns the brush style.
Definition qbrush.h:120
\inmodule QtCore
Definition qbytearray.h:57
char * data()
\macro QT_NO_CAST_FROM_BYTEARRAY
Definition qbytearray.h:611
qsizetype size() const noexcept
Returns the number of bytes in this byte array.
Definition qbytearray.h:494
const char * constData() const noexcept
Returns a pointer to the const data stored in the byte array.
Definition qbytearray.h:124
char at(qsizetype i) const
Returns the byte at index position i in the byte array.
Definition qbytearray.h:600
\inmodule QtCore
Definition qcoreevent.h:379
The QCloseEvent class contains parameters that describe a close event.
Definition qevent.h:562
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition qcolor.h:31
void setAlphaF(float alpha)
Sets the alpha of this color to alpha.
Definition qcolor.cpp:1511
The QContextMenuEvent class contains parameters that describe a context menu event.
Definition qevent.h:594
const QPoint & globalPos() const
Returns the global position of the mouse pointer at the time of the event.
Definition qevent.h:612
static bool testAttribute(uint flag)
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
static void removePostedEvents(QObject *receiver, int eventType=0)
static void processEvents(QEventLoop::ProcessEventsFlags flags=QEventLoop::AllEvents)
Processes some pending events for the calling thread according to the specified flags.
static QCoreApplication * instance() noexcept
Returns a pointer to the application's QCoreApplication (or QGuiApplication/QApplication) instance.
static bool closingDown()
Returns true if the application objects are being destroyed; otherwise returns false.
static bool testAttribute(Qt::ApplicationAttribute attribute)
Returns true if attribute attribute is set; otherwise returns false.
static void postEvent(QObject *receiver, QEvent *event, int priority=Qt::NormalEventPriority)
The QCursor class provides a mouse cursor with an arbitrary shape.
Definition qcursor.h:45
Qt::CursorShape shape() const
Returns the cursor shape identifier.
Definition qcursor.cpp:498
\inmodule QtCore\reentrant
Definition qdatastream.h:46
\inmodule QtCore
\inmodule QtCore
\inmodule QtGui
Definition qevent.h:165
\inmodule QtCore
Definition qcoreevent.h:45
Type
This enum type defines the valid event types in Qt.
Definition qcoreevent.h:51
@ QueryWhatsThis
Definition qcoreevent.h:169
@ TabletMove
Definition qcoreevent.h:121
@ ApplicationPaletteChange
Definition qcoreevent.h:93
@ ActionRemoved
Definition qcoreevent.h:153
@ ContentsRectChange
Definition qcoreevent.h:219
@ WindowStateChange
Definition qcoreevent.h:143
@ DevicePixelRatioChange
Definition qcoreevent.h:287
@ ParentChange
Definition qcoreevent.h:80
@ FocusAboutToChange
Definition qcoreevent.h:68
@ ScreenChangeInternal
Definition qcoreevent.h:276
@ AcceptDropsChange
Definition qcoreevent.h:185
@ EnabledChange
Definition qcoreevent.h:134
@ ModifiedChange
Definition qcoreevent.h:138
@ PolishRequest
Definition qcoreevent.h:110
@ ActionAdded
Definition qcoreevent.h:152
@ WindowAboutToChangeInternal
Definition qcoreevent.h:285
@ LayoutDirectionChange
Definition qcoreevent.h:124
@ ChildPolished
Definition qcoreevent.h:107
@ ApplicationLayoutDirectionChange
Definition qcoreevent.h:92
@ WindowBlocked
Definition qcoreevent.h:141
@ WindowUnblocked
Definition qcoreevent.h:142
@ ReadOnlyChange
Definition qcoreevent.h:145
@ ApplicationWindowIconChange
Definition qcoreevent.h:90
@ ShortcutOverride
Definition qcoreevent.h:158
@ FocusOut
Definition qcoreevent.h:67
@ InputMethod
Definition qcoreevent.h:120
@ StyleChange
Definition qcoreevent.h:136
@ DragEnter
Definition qcoreevent.h:101
@ CursorChange
Definition qcoreevent.h:228
@ LocaleChange
Definition qcoreevent.h:122
@ InputMethodQuery
Definition qcoreevent.h:261
@ ActionChanged
Definition qcoreevent.h:151
@ LayoutRequest
Definition qcoreevent.h:112
@ FontChange
Definition qcoreevent.h:133
@ KeyRelease
Definition qcoreevent.h:65
@ MouseMove
Definition qcoreevent.h:63
@ ShowWindowRequest
Definition qcoreevent.h:109
@ KeyPress
Definition qcoreevent.h:64
@ ZOrderChange
Definition qcoreevent.h:173
@ StyleAnimationUpdate
Definition qcoreevent.h:272
@ FocusIn
Definition qcoreevent.h:66
@ ToolBarChange
Definition qcoreevent.h:162
@ TouchCancel
Definition qcoreevent.h:264
@ ActivationChange
Definition qcoreevent.h:135
@ ThemeChange
Definition qcoreevent.h:266
@ MouseButtonPress
Definition qcoreevent.h:60
@ TouchUpdate
Definition qcoreevent.h:242
@ TouchBegin
Definition qcoreevent.h:241
@ HoverLeave
Definition qcoreevent.h:176
@ ToolTipChange
Definition qcoreevent.h:229
@ HoverEnter
Definition qcoreevent.h:175
@ ParentAboutToChange
Definition qcoreevent.h:81
@ WindowActivate
Definition qcoreevent.h:83
@ LanguageChange
Definition qcoreevent.h:123
@ TabletRelease
Definition qcoreevent.h:127
@ DynamicPropertyChange
Definition qcoreevent.h:207
@ WindowIconChange
Definition qcoreevent.h:89
@ HideToParent
Definition qcoreevent.h:86
@ IconTextChange
Definition qcoreevent.h:137
@ UpdateRequest
Definition qcoreevent.h:113
@ DragLeave
Definition qcoreevent.h:103
@ UpdateLater
Definition qcoreevent.h:114
@ EmbeddingControl
Definition qcoreevent.h:116
@ PlatformSurface
Definition qcoreevent.h:278
@ PaletteChange
Definition qcoreevent.h:94
@ TabletPress
Definition qcoreevent.h:126
@ MouseButtonDblClick
Definition qcoreevent.h:62
@ Destroy
Definition qcoreevent.h:75
@ MacSizeChange
Definition qcoreevent.h:217
@ ApplicationFontChange
Definition qcoreevent.h:91
@ TabletTrackingChange
Definition qcoreevent.h:282
@ WindowTitleChange
Definition qcoreevent.h:88
@ WhatsThis
Definition qcoreevent.h:148
@ WinIdChange
Definition qcoreevent.h:251
@ ShowToParent
Definition qcoreevent.h:85
@ KeyboardLayoutChange
Definition qcoreevent.h:205
@ WindowDeactivate
Definition qcoreevent.h:84
@ ContextMenu
Definition qcoreevent.h:119
@ MouseButtonRelease
Definition qcoreevent.h:61
@ MouseTrackingChange
Definition qcoreevent.h:139
@ WindowChangeInternal
Definition qcoreevent.h:275
@ ChildAdded
Definition qcoreevent.h:106
bool isAccepted() const
Definition qcoreevent.h:308
void accept()
Sets the accept flag of the event object, the equivalent of calling setAccepted(true).
Definition qcoreevent.h:310
QString fileName() const
The QFocusEvent class contains event parameters for widget focus events.
Definition qevent.h:470
\reentrant
Definition qfont.h:22
QFont resolve(const QFont &) const
Returns a new QFont that has attributes copied from other that have not been previously set on this f...
Definition qfont.cpp:1893
void setResolveMask(uint mask)
Definition qfont.h:313
uint resolveMask() const
Definition qfont.h:312
static QGestureManager * instance(InstanceCreation ic=ForceCreation)
@ ObjectBoundingMode
Definition qbrush.h:156
@ ObjectMode
Definition qbrush.h:157
The QGraphicsEffectSource class represents the source on which a QGraphicsEffect is installed on.
The QGraphicsEffect class is the base class for all graphics effects.
PixmapPadMode
This enum describes how the pixmap returned from sourcePixmap should be padded.
QGraphicsEffectSource * source() const
virtual void draw(QPainter *painter)=0
This pure virtual function draws the effect and is called whenever the source needs to be drawn.
bool isEnabled() const
The QGraphicsProxyWidget class provides a proxy layer for embedding a QWidget in a QGraphicsScene.
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items.
QList< QGraphicsView * > views() const
Returns a list of all the views that display this scene.
void update(qreal x, qreal y, qreal w, qreal h)
This is an overloaded member function, provided for convenience. It differs from the above function o...
QPalette palette
the widget's palette
QFont font
the widgets' font
static void showModalWindow(QWindow *window)
static void hideModalWindow(QWindow *window)
static QPlatformIntegration * platformIntegration()
static QGuiApplicationPrivate * instance()
static Qt::ApplicationState applicationState()
QScreen * primaryScreen
the primary (or default) screen of the application.
static QPalette palette()
Returns the current application palette.
static QObject * focusObject()
Returns the QObject in currently active window that will be final receiver of events tied to focus,...
static QWindow * focusWindow()
Returns the QWindow that receives events tied to focus, such as key events.
static QInputMethod * inputMethod()
returns the input method.
static void setOverrideCursor(const QCursor &)
Sets the application override cursor to cursor.
static void restoreOverrideCursor()
Undoes the last setOverrideCursor().
static bool desktopSettingsAware()
Returns true if Qt is set to use the system's standard colors, fonts, etc.; otherwise returns false.
Qt::LayoutDirection layoutDirection
the default layout direction for this application
static QScreen * screenAt(const QPoint &point)
Returns the screen at point, or \nullptr if outside of any screen.
static QList< QScreen * > screens()
Returns a list of all the screens associated with the windowing system the application is connected t...
QIcon windowIcon
the default window icon
The QHelpEvent class provides an event that is used to request helpful information about a particular...
Definition qevent.h:788
const QPoint & globalPos() const
Returns the mouse cursor position when the event was generated in global coordinates.
Definition qevent.h:799
The QHideEvent class provides an event which is sent after a widget is hidden.
Definition qevent.h:586
The QIcon class provides scalable icons in different modes and states.
Definition qicon.h:20
bool isNull() const
Returns true if the icon is empty; otherwise returns false.
Definition qicon.cpp:1021
\inmodule QtGui
Definition qimage.h:37
@ Format_RGB32
Definition qimage.h:46
@ Format_ARGB32_Premultiplied
Definition qimage.h:48
The QInputMethodEvent class provides parameters for input method events.
Definition qevent.h:625
The QInputMethodQueryEvent class provides an event sent by the input context to input objects.
Definition qevent.h:679
Qt::InputMethodQueries queries() const
Returns the properties queried by the event.
Definition qevent.h:684
The QKeyEvent class describes a key event.
Definition qevent.h:424
Qt::KeyboardModifiers modifiers() const
Returns the keyboard modifier flags that existed immediately after the event occurred.
Definition qevent.cpp:1468
int key() const
Returns the code of the key that was pressed or released.
Definition qevent.h:434
The QKeySequence class encapsulates a key sequence as used by shortcuts.
virtual QRect geometry() const =0
Returns the rectangle covered by this layout item.
virtual bool hasHeightForWidth() const
Returns true if this layout's preferred height depends on its width; otherwise returns false.
virtual QLayout * layout()
If this item is a QLayout, it is returned as a QLayout; otherwise \nullptr is returned.
The QLayout class is the base class of geometry managers.
Definition qlayout.h:26
QRect geometry() const override
\reimp
Definition qlayout.cpp:460
int totalHeightForWidth(int w) const
Definition qlayout.cpp:599
void update()
Updates the layout for parentWidget().
Definition qlayout.cpp:971
bool activate()
Redoes the layout for parentWidget() if necessary.
Definition qlayout.cpp:995
Qt::Orientations expandingDirections() const override
Returns whether this layout can make use of more space than sizeHint().
Definition qlayout.cpp:944
void invalidate() override
\reimp
Definition qlayout.cpp:469
QWidget * parentWidget() const
Returns the parent widget of this layout, or \nullptr if this layout is not installed on any widget.
Definition qlayout.cpp:399
QLayout * layout() override
\reimp
virtual int indexOf(const QWidget *) const
Searches for widget widget in this layout (not including child layouts).
Definition qlayout.cpp:1177
qsizetype size() const noexcept
Definition qlist.h:397
bool isEmpty() const noexcept
Definition qlist.h:401
const_reference at(qsizetype i) const noexcept
Definition qlist.h:446
qsizetype removeAll(const AT &t)
Definition qlist.h:592
void append(parameter_type t)
Definition qlist.h:458
\inmodule QtCore
bool isDebugEnabled() const
Returns true if debug messages should be shown for this category; false otherwise.
\inmodule QtCore
Definition qmargins.h:24
constexpr int bottom() const noexcept
Returns the bottom margin.
Definition qmargins.h:115
constexpr bool isNull() const noexcept
Returns true if all margins are is 0; otherwise returns false.
Definition qmargins.h:103
constexpr int left() const noexcept
Returns the left margin.
Definition qmargins.h:106
constexpr int right() const noexcept
Returns the right margin.
Definition qmargins.h:112
constexpr int top() const noexcept
Returns the top margin.
Definition qmargins.h:109
QAction * exec()
Executes this menu synchronously.
Definition qmenu.cpp:2613
\inmodule QtCore
const char * valueToKey(int value) const
Returns the string that is used as the name of the given enumeration value, or \nullptr if value is n...
\inmodule QtGui
Definition qevent.h:196
The QMoveEvent class contains event parameters for move events.
Definition qevent.h:502
uint isWindow
Definition qobject.h:82
uint isWidget
Definition qobject.h:76
QObjectList children
Definition qobject.h:74
uint wasWidget
Definition qobject.h:86
uint willBeWidget
Definition qobject.h:85
QObject * parent
Definition qobject.h:73
void setParent_helper(QObject *)
Definition qobject.cpp:2219
virtual std::string flagsForDumping() const
Definition qobject.cpp:4364
\inmodule QtCore
Definition qobject.h:103
const QObjectList & children() const
Returns a list of child objects.
Definition qobject.h:201
QObject * parent() const
Returns a pointer to the parent object.
Definition qobject.h:346
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2960
QString objectName
the name of this object
Definition qobject.h:107
virtual bool event(QEvent *event)
This virtual function receives events to an object and should return true if the event e was recogniz...
Definition qobject.cpp:1389
void setParent(QObject *parent)
Makes the object a child of parent.
Definition qobject.cpp:2195
friend class QWidget
Definition qobject.h:382
QList< QByteArray > dynamicPropertyNames() const
Definition qobject.cpp:4352
bool setProperty(const char *name, const QVariant &value)
Sets the value of the object's name property to value.
bool inherits(const char *classname) const
Returns true if this object is an instance of a class that inherits className or a QObject subclass t...
Definition qobject.h:348
void destroyed(QObject *=nullptr)
This signal is emitted immediately before the object obj is destroyed, after any instances of QPointe...
bool isWidgetType() const
Returns true if the object is a widget; otherwise returns false.
Definition qobject.h:131
bool paintingActive() const
qreal devicePixelRatio() const
@ 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:486
The QPainter class performs low-level painting on widgets and other paint devices.
Definition qpainter.h:46
CompositionMode compositionMode() const
Returns the current composition mode.
const QPen & pen() const
Returns the painter's current pen.
Qt::LayoutDirection layoutDirection() const
Returns the layout direction used by the painter when drawing text.
RenderHints renderHints() const
Returns a flag that specifies the rendering hints that are set for this painter.
QPaintDevice * device() const
Returns the paint device on which this painter is currently painting, or \nullptr if the painter is n...
qreal opacity() const
QPaintEngine * paintEngine() const
Returns the paint engine that the painter is currently operating on if the painter is active; otherwi...
void setBrushOrigin(int x, int y)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qpainter.h:698
const QFont & font() const
Returns the currently set font used for drawing text.
void setLayoutDirection(Qt::LayoutDirection direction)
Sets the layout direction used by the painter when drawing text, to the specified direction.
void drawTiledPixmap(const QRectF &rect, const QPixmap &pm, const QPointF &offset=QPointF())
Draws a tiled pixmap, inside the given rectangle with its origin at the given position.
void restore()
Restores the current painter state (pops a saved state off the stack).
const QTransform & worldTransform() const
Returns the world transformation matrix.
void setCompositionMode(CompositionMode mode)
Sets the composition mode to the given mode.
void save()
Saves the current painter state (pushes the state onto a stack).
QRegion clipRegion() const
Returns the currently set clip region.
const QTransform & deviceTransform() const
Returns the matrix that transforms from logical coordinates to device coordinates of the platform dep...
void drawPixmap(const QRectF &targetRect, const QPixmap &pixmap, const QRectF &sourceRect)
Draws the rectangular portion source of the given pixmap into the given target in the paint device.
@ SmoothPixmapTransform
Definition qpainter.h:54
CompositionMode
Defines the modes supported for digital image compositing.
Definition qpainter.h:97
@ CompositionMode_Source
Definition qpainter.h:101
bool isActive() const
Returns true if begin() has been called and end() has not yet been called; otherwise returns false.
void translate(const QPointF &offset)
Translates the coordinate system by the given offset; i.e.
void setRenderHints(RenderHints hints, bool on=true)
void fillRect(const QRectF &, const QBrush &)
Fills the given rectangle with the brush specified.
bool hasClipping() const
Returns true if clipping has been set; otherwise returns false.
void setClipRegion(const QRegion &, Qt::ClipOperation op=Qt::ReplaceClip)
Sets the clip region to the given region using the specified clip operation.
void setTransform(const QTransform &transform, bool combine=false)
The QPalette class contains color groups for each widget state.
Definition qpalette.h:19
const QBrush & brush(ColorGroup cg, ColorRole cr) const
Returns the brush in the specified color group, used for the given color role.
Definition qpalette.cpp:748
quint64 ResolveMask
Definition qpalette.h:113
void setCurrentColorGroup(ColorGroup cg)
Set the palette's current color group to cg.
Definition qpalette.h:65
void setResolveMask(ResolveMask mask)
ResolveMask resolveMask() const
Definition qpalette.cpp:999
@ Inactive
Definition qpalette.h:49
@ Disabled
Definition qpalette.h:49
QPalette resolve(const QPalette &other) const
Returns a new QPalette that is a union of this instance and other.
Definition qpalette.cpp:963
@ HighlightedText
Definition qpalette.h:53
@ ToolTipBase
Definition qpalette.h:57
@ ButtonText
Definition qpalette.h:52
@ WindowText
Definition qpalette.h:51
@ Highlight
Definition qpalette.h:53
@ ToolTipText
Definition qpalette.h:57
\inmodule QtGui
Definition qpen.h:28
Returns a copy of the pixmap that is transformed using the given transformation transform and transfo...
Definition qpixmap.h:27
void setRhiConfig(const QPlatformBackingStoreRhiConfig &config)
The QPlatformIntegration class is the entry for WindowSystem specific functionality.
virtual bool hasCapability(Capability cap) const
The QPlatformSurfaceEvent class is used to notify about native platform surface events....
Definition qevent.h:531
The QPlatformWindow class provides an abstraction for top-level windows.
virtual bool setWindowModified(bool modified)
Reimplement to be able to let Qt indicate that the window has been modified.
virtual QMargins safeAreaMargins() const
The safe area margins of a window represent the area that is safe to place content within,...
\inmodule QtCore\reentrant
Definition qpoint.h:217
constexpr QPoint toPoint() const
Rounds the coordinates of this point to the nearest integer, and returns a QPoint object with the rou...
Definition qpoint.h:404
\inmodule QtCore\reentrant
Definition qpoint.h:25
constexpr int x() const noexcept
Returns the x coordinate of this point.
Definition qpoint.h:130
constexpr int y() const noexcept
Returns the y coordinate of this point.
Definition qpoint.h:135
\inmodule QtCore\reentrant
Definition qrect.h:484
QRect toAlignedRect() const noexcept
Definition qrect.cpp:2338
constexpr QRectF translated(qreal dx, qreal dy) const noexcept
Returns a copy of the rectangle that is translated dx along the x axis and dy along the y axis,...
Definition qrect.h:762
constexpr QRectF adjusted(qreal x1, qreal y1, qreal x2, qreal y2) const noexcept
Returns a new rectangle with dx1, dy1, dx2 and dy2 added respectively to the existing coordinates of ...
Definition qrect.h:813
\inmodule QtCore\reentrant
Definition qrect.h:30
constexpr bool isEmpty() const noexcept
Returns true if the rectangle is empty, otherwise returns false.
Definition qrect.h:167
constexpr int height() const noexcept
Returns the height of the rectangle.
Definition qrect.h:239
constexpr bool isNull() const noexcept
Returns true if the rectangle is a null rectangle, otherwise returns false.
Definition qrect.h:164
constexpr int bottom() const noexcept
Returns the y-coordinate of the rectangle's bottom edge.
Definition qrect.h:182
constexpr QPoint topLeft() const noexcept
Returns the position of the rectangle's top-left corner.
Definition qrect.h:221
constexpr QRect adjusted(int x1, int y1, int x2, int y2) const noexcept
Returns a new rectangle with dx1, dy1, dx2 and dy2 added respectively to the existing coordinates of ...
Definition qrect.h:370
constexpr int top() const noexcept
Returns the y-coordinate of the rectangle's top edge.
Definition qrect.h:176
bool contains(const QRect &r, bool proper=false) const noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qrect.cpp:855
constexpr int left() const noexcept
Returns the x-coordinate of the rectangle's left edge.
Definition qrect.h:173
constexpr int x() const noexcept
Returns the x-coordinate of the rectangle's left edge.
Definition qrect.h:185
constexpr void setWidth(int w) noexcept
Sets the width of the rectangle to the given width.
Definition qrect.h:381
constexpr QSize size() const noexcept
Returns the size of the rectangle.
Definition qrect.h:242
constexpr void translate(int dx, int dy) noexcept
Moves the rectangle dx along the x axis and dy along the y axis, relative to the current position.
Definition qrect.h:245
constexpr int width() const noexcept
Returns the width of the rectangle.
Definition qrect.h:236
constexpr QRect translated(int dx, int dy) const noexcept
Returns a copy of the rectangle that is translated dx along the x axis and dy along the y axis,...
Definition qrect.h:261
constexpr int y() const noexcept
Returns the y-coordinate of the rectangle's top edge.
Definition qrect.h:188
constexpr QPoint center() const noexcept
Returns the center point of the rectangle.
Definition qrect.h:233
constexpr int right() const noexcept
Returns the x-coordinate of the rectangle's right edge.
Definition qrect.h:179
The QRegion class specifies a clip region for a painter.
Definition qregion.h:27
QRect boundingRect() const noexcept
Returns the bounding rectangle of this region.
void translate(int dx, int dy)
Translates (moves) the region dx along the X axis and dy along the Y axis.
bool intersects(const QRegion &r) const
Definition qregion.cpp:613
bool isEmpty() const
Returns true if the region is empty; otherwise returns false.
QRegion translated(int dx, int dy) const
Definition qregion.cpp:593
The QResizeEvent class contains event parameters for resize events.
Definition qevent.h:548
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:1804
The QScreen class is used to query screen properties. \inmodule QtGui.
Definition qscreen.h:32
qreal logicalDotsPerInchY
the number of logical dots or pixels per inch in the vertical direction
Definition qscreen.h:57
qreal devicePixelRatio
the screen's ratio between physical pixels and device-independent pixels
Definition qscreen.h:59
qreal logicalDotsPerInchX
the number of logical dots or pixels per inch in the horizontal direction
Definition qscreen.h:56
QSizeF physicalSize
the screen's physical size (in millimeters)
Definition qscreen.h:50
QRect geometry
the screen's geometry in pixels
Definition qscreen.h:45
qreal physicalDotsPerInchY
the number of physical dots or pixels per inch in the vertical direction
Definition qscreen.h:54
int depth
the color depth of the screen
Definition qscreen.h:40
qreal physicalDotsPerInchX
the number of physical dots or pixels per inch in the horizontal direction
Definition qscreen.h:52
The QShowEvent class provides an event that is sent when a widget is shown.
Definition qevent.h:578
\inmodule QtCore
Definition qsize.h:208
constexpr qreal width() const noexcept
Returns the width.
Definition qsize.h:332
constexpr qreal height() const noexcept
Returns the height.
Definition qsize.h:335
The QSizePolicy class is a layout attribute describing horizontal and vertical resizing policy.
Definition qsizepolicy.h:18
constexpr bool retainSizeWhenHidden() const noexcept
Definition qsizepolicy.h:97
\inmodule QtCore
Definition qsize.h:25
constexpr void setHeight(int h) noexcept
Sets the height to the given height.
Definition qsize.h:139
The QStatusTipEvent class provides an event that is used to show messages in a status bar.
Definition qevent.h:808
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
qsizetype indexOf(QLatin1StringView s, qsizetype from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition qstring.cpp:4517
bool isEmpty() const noexcept
Returns true if the string has no characters; otherwise returns false.
Definition qstring.h:192
bool isNull() const
Returns true if this string is null; otherwise returns false.
Definition qstring.h:994
QByteArray toLocal8Bit() const &
Definition qstring.h:638
The QStyleOption class stores the parameters used by QStyle functions.
void initFrom(const QWidget *w)
The QStyle class is an abstract base class that encapsulates the look and feel of a GUI.
Definition qstyle.h:29
virtual void polish(QWidget *widget)
Initializes the appearance of the given widget.
Definition qstyle.cpp:436
@ SH_Widget_ShareActivation
Definition qstyle.h:608
@ SH_TitleBar_ModifyNotification
Definition qstyle.h:633
virtual int styleHint(StyleHint stylehint, const QStyleOption *opt=nullptr, const QWidget *widget=nullptr, QStyleHintReturn *returnData=nullptr) const =0
Returns an integer representing the specified style hint for the given widget described by the provid...
@ PM_TitleBarHeight
Definition qstyle.h:448
@ PE_Widget
Definition qstyle.h:148
SubElement
This enum represents a sub-area of a widget.
Definition qstyle.h:242
The QSurfaceFormat class represents the format of a QSurface. \inmodule QtGui.
SurfaceType
The SurfaceType enum describes what type of surface this is.
Definition qsurface.h:30
@ RasterSurface
Definition qsurface.h:31
@ OpenGLSurface
Definition qsurface.h:32
static void showText(const QPoint &pos, const QString &text, QWidget *w=nullptr, const QRect &rect={}, int msecShowTime=-1)
Shows text as a tool tip, with the global position pos as the point of interest.
Definition qtooltip.cpp:439
The QTransform class specifies 2D transformations of a coordinate system.
Definition qtransform.h:20
QTransform & scale(qreal sx, qreal sy)
Scales the coordinate system by sx horizontally and sy vertically, and returns a reference to the mat...
QPoint map(const QPoint &p) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
static QTransform fromTranslate(qreal dx, qreal dy)
Creates a matrix which corresponds to a translation of dx along the x axis and dy along the y axis.
bool isScaling() const
Returns true if the matrix represents a scaling transformation, otherwise returns false.
Definition qtransform.h:179
QTransform & translate(qreal dx, qreal dy)
Moves the coordinate system dx along the x axis and dy along the y axis, and returns a reference to t...
\inmodule QtCore
Definition qvariant.h:65
static void showText(const QPoint &pos, const QString &text, QWidget *w=nullptr)
Shows text as a "What's This?" window, at global position pos.
QRect crect
Definition qwidget.h:90
QWidget * wid
bool isFocusChainConsistent() const
uint mustHaveWindowHandle
Definition qwidget_p.h:726
void deleteExtra()
Definition qwidget.cpp:1670
void setEnabled_helper(bool)
Definition qwidget.cpp:3365
uint dirtyOpaqueChildren
Definition qwidget_p.h:719
const QMetaObject * polished
Definition qwidget_p.h:656
void hideChildren(bool spontaneous)
Definition qwidget.cpp:8428
QSize adjustedSize() const
Definition qwidget.cpp:8681
QMargins safeAreaMargins() const
Definition qwidget.cpp:7672
QWidget * nextPrevElementInFocusChain(FocusDirection direction) const
QWindow * _q_closestWindowHandle() const
Definition qwidget.cpp:1085
void setWindowFilePath_sys(const QString &filePath)
Definition qwidget.cpp:6278
QTLWExtra * maybeTopData() const
Definition qwidget_p.h:867
static QWidgetList takeFromFocusChain(QWidget *from, QWidget *to, FocusDirection direction=FocusDirection::Next)
static int instanceCounter
Definition qwidget_p.h:701
void setModal_sys()
Definition qwidget.cpp:2807
uint inheritedFontResolveMask
Definition qwidget_p.h:690
void setLayoutItemMargins(int left, int top, int right, int bottom)
bool hasChildWithFocusPolicy(Qt::FocusPolicy policy, const QWidget *excludeChildrenOf=nullptr) const
QWidgetData data
Definition qwidget_p.h:704
static void adjustFlags(Qt::WindowFlags &flags, QWidget *w=nullptr)
Definition qwidget.cpp:889
bool isExplicitlyHidden() const
Definition qwidget.cpp:8384
void deactivateWidgetCleanup()
Definition qwidget.cpp:2306
virtual void setWindowFlags(Qt::WindowFlags windowFlags)
void repaint(T t)
bool setScreen(QScreen *screen)
Definition qwidget.cpp:2420
QRegion clipRegion() const
Definition qwidget.cpp:1889
void createSysExtra()
Definition qwidget.cpp:1661
void createTLExtra()
Definition qwidget.cpp:1599
void getLayoutItemMargins(int *left, int *top, int *right, int *bottom) const
void subtractOpaqueChildren(QRegion &rgn, const QRect &clipRect) const
Definition qwidget.cpp:2007
void setWindowTitle_helper(const QString &cap)
Definition qwidget.cpp:6029
void setMask_sys(const QRegion &)
QScreen * associatedScreen() const
Definition qwidget.cpp:1090
bool insertIntoFocusChain(FocusDirection direction, QWidget *position)
QWidget * childAtRecursiveHelper(const QPoint &p, bool) const
uint usesDoubleBufferedGLContext
Definition qwidget_p.h:725
void updateFont(const QFont &)
Definition qwidget.cpp:4777
void setParent_sys(QWidget *parent, Qt::WindowFlags)
QFont localFont() const
Definition qwidget.cpp:4746
signed char leftLayoutItemMargin
Definition qwidget_p.h:697
virtual void beginBackingStorePainting()
Definition qwidget_p.h:606
QWidget * determineLastFocusChild(QWidget *noFurtherThan)
void setUpdatesEnabled_helper(bool)
Definition qwidget.cpp:1800
void scrollRect(const QRect &, int dx, int dy)
void hide_helper()
Definition qwidget.cpp:8142
uint high_attributes[4]
Definition qwidget_p.h:716
bool updateBrushOrigin(QPainter *, const QBrush &brush) const
Definition qwidget.cpp:2244
void updateFrameStrut()
QPalette::ResolveMask inheritedPaletteResolveMask
Definition qwidget_p.h:692
virtual QImage grabFramebuffer()
Definition qwidget_p.h:605
uint renderToTextureReallyDirty
Definition qwidget_p.h:732
QFont naturalWidgetFont(uint inheritedMask) const
Definition qwidget.cpp:4700
void activateChildLayoutsRecursively()
Definition qwidget.cpp:7948
void setSystemClip(QPaintEngine *paintEngine, qreal devicePixelRatio, const QRegion &region)
Definition qwidget.cpp:1926
virtual void endBackingStorePainting()
Definition qwidget_p.h:607
virtual QPlatformBackingStoreRhiConfig rhiConfig() const
Definition qwidget_p.h:590
static QWidgetMapper * mapper
Definition qwidget_p.h:661
void render(QPaintDevice *target, const QPoint &targetOffset, const QRegion &sourceRegion, QWidget::RenderFlags renderFlags)
Definition qwidget.cpp:5645
bool shouldDiscardSyncRequest() const
void restoreRedirected()
Definition qwidget_p.h:517
void setWindowIcon_sys()
Definition qwidget.cpp:6192
void updateContentsRect()
Definition qwidget.cpp:7626
void setSharedPainter(QPainter *painter)
Definition qwidget_p.h:879
bool setScreenForPoint(const QPoint &pos)
Definition qwidget.cpp:2405
uint retainSizeWhenHiddenChanged
Definition qwidget_p.h:721
void setWSGeometry()
Definition qwidget.cpp:219
void adjustQuitOnCloseAttribute()
void clipToEffectiveMask(QRegion &region) const
Definition qwidget.cpp:2104
void setFocus_sys()
Definition qwidget.cpp:6618
static QWidgetPrivate * get(QWidget *w)
Definition qwidget_p.h:212
void resolveLayoutDirection()
Definition qwidget.cpp:4853
@ DontSubtractOpaqueChildren
Definition qwidget_p.h:191
void scrollChildren(int dx, int dy)
Definition qwidget.cpp:197
bool stealKeyboardGrab(bool grab)
signed char topLayoutItemMargin
Definition qwidget_p.h:698
void setLocale_helper(const QLocale &l, bool forceUpdate=false)
Definition qwidget.cpp:5889
void reparentFocusWidgets(QWidget *oldtlw)
Definition qwidget.cpp:7073
void resolvePalette()
Definition qwidget.cpp:4597
QWidgetRepaintManager * maybeRepaintManager() const
Definition qwidget_p.h:893
static void setWidgetParentHelper(QObject *widgetAsObject, QObject *newParent)
const QRegion & getOpaqueChildren() const
Definition qwidget.cpp:1977
void showChildren(bool spontaneous)
Definition qwidget.cpp:8397
void propagatePaletteChange()
Definition qwidget.cpp:1829
void paintOnScreen(const QRegion &rgn)
Definition qwidget.cpp:1764
void paintSiblingsRecursive(QPaintDevice *pdev, const QObjectList &children, int index, const QRegion &rgn, const QPoint &offset, DrawWidgetFlags flags, QPainter *sharedPainter, QWidgetRepaintManager *repaintManager)
Definition qwidget.cpp:5717
void updateGeometry_helper(bool forceUpdate)
void setCursor_sys(const QCursor &cursor)
Definition qwidget.cpp:4976
QRegion prepareToRender(const QRegion &region, QWidget::RenderFlags renderFlags)
Definition qwidget.cpp:5326
QWidget * closestParentWidgetWithWindowHandle() const
Definition qwidget.cpp:1046
QPaintEngine * extraPaintEngine
Definition qwidget_p.h:655
QWidget * deepestFocusProxy() const
Definition qwidget.cpp:6598
std::unique_ptr< QWExtra > extra
Definition qwidget_p.h:647
static void checkRestoredGeometry(const QRect &availableGeometry, QRect *restoredGeometry, int frameHeight)
Definition qwidget.cpp:7386
bool setMaximumSize_helper(int &maxw, int &maxh)
Definition qwidget.cpp:3970
void subtractOpaqueSiblings(QRegion &source, bool *hasDirtySiblingsAbove=nullptr, bool alsoNonOpaque=false) const
Definition qwidget.cpp:2018
void sendPaintEvent(const QRegion &toBePainted)
Definition qwidget.cpp:5635
void setStyle_helper(QStyle *newStyle, bool propagate)
Definition qwidget.cpp:2649
signed char bottomLayoutItemMargin
Definition qwidget_p.h:700
QRegion overlappedRegion(const QRect &rect, bool breakAfterFirst=false) const
Definition qwidget.cpp:1704
void updateWidgetTransform(QEvent *event)
Definition qwidget.cpp:226
QRegion dirty
Definition qwidget_p.h:672
void resolveFont()
Definition qwidget.cpp:4761
QLocale locale
Definition qwidget_p.h:706
@ CloseWithSpontaneousEvent
Definition qwidget_p.h:340
void scroll_sys(int dx, int dy)
QGraphicsEffect * graphicsEffect
Definition qwidget_p.h:657
signed char rightLayoutItemMargin
Definition qwidget_p.h:699
void render_helper(QPainter *painter, const QPoint &targetOffset, const QRegion &sourceRegion, QWidget::RenderFlags renderFlags)
Definition qwidget.cpp:5384
void setWinId(WId)
Definition qwidget.cpp:1579
void createTLSysExtra()
Definition qwidget.cpp:1402
uint textureChildSeen
Definition qwidget_p.h:728
bool stealMouseGrab(bool grab)
void reparentWidgetWindowChildren(QWidget *parentWithWindow)
void setRedirected(QPaintDevice *replacement, const QPoint &offset)
Definition qwidget_p.h:503
void resolveLocale()
Definition qwidget.cpp:5928
void setWindowIcon_helper()
Definition qwidget.cpp:6147
void setNetWmWindowTypes(bool skipIfMissing=false)
QRect frameStrut() const
bool shouldPaintOnScreen() const
Definition qwidget.cpp:2129
void setDirtyOpaqueRegion()
Definition qwidget.cpp:1954
void initFocusChain()
QWidget * focus_child
Definition qwidget_p.h:650
QRhi * rhi() const
Definition qwidget.cpp:1030
void reparentFocusChildren(FocusDirection direction)
void updateIsOpaque()
Definition qwidget.cpp:2144
std::string flagsForDumping() const override
void syncBackingStore()
Definition qwidget.cpp:1745
virtual void beginCompose()
Definition qwidget_p.h:608
QRegion opaqueChildren
Definition qwidget_p.h:671
bool pointInsideRectAndMask(const QPoint &) const
Definition qwidget_p.h:886
void setWindowModified_helper()
QPalette naturalWidgetPalette(QPalette::ResolveMask inheritedMask) const
Definition qwidget.cpp:4553
void invalidateBackingStore_resizeHelper(const QPoint &oldPos, const QSize &oldSize)
Invalidates the backing store when the widget is resized.
QWidgetItemV2 * widgetItem
Definition qwidget_p.h:654
virtual void resolveSamples()
Definition qwidget_p.h:632
void setWindowTitle_sys(const QString &cap)
Definition qwidget.cpp:6036
void updateSystemBackground()
Definition qwidget.cpp:4617
void setVisible(bool)
Definition qwidget.cpp:8274
void paintBackground(QPainter *, const QRegion &, DrawWidgetFlags flags=DrawAsRoot) const
Definition qwidget.cpp:2261
void setOpaque(bool opaque)
Definition qwidget.cpp:2183
QWidget * childAt_helper(const QPoint &, bool) const
void unsetCursor_sys()
Definition qwidget.cpp:4996
void drawWidget(QPaintDevice *pdev, const QRegion &rgn, const QPoint &offset, DrawWidgetFlags flags, QPainter *sharedPainter=nullptr, QWidgetRepaintManager *repaintManager=nullptr)
Definition qwidget.cpp:5448
void setWindowIconText_helper(const QString &cap)
Definition qwidget.cpp:6047
void updateIsTranslucent()
Definition qwidget.cpp:2191
void inheritStyle()
Definition qwidget.cpp:2696
uint renderToTexture
Definition qwidget_p.h:727
QRect effectiveRectFor(const QRegion &region) const
Definition qwidget_p.h:540
void update(T t)
QSizePolicy size_policy
Definition qwidget_p.h:705
QRect clipRect() const
Definition qwidget.cpp:1865
QWidget * effectiveFocusWidget()
Definition qwidget_p.h:440
QTLWExtra * topData() const
Definition qwidget_p.h:861
void setLayoutDirection_helper(Qt::LayoutDirection)
Definition qwidget.cpp:4835
void sendPendingMoveAndResizeEvents(bool recursive=false, bool disableUpdates=false)
Definition qwidget.cpp:7916
void setWindowOpacity_sys(qreal opacity)
void moveRect(const QRect &, int dx, int dy)
bool handleClose(CloseMode mode)
Definition qwidget.cpp:8497
void setPalette_helper(const QPalette &)
Definition qwidget.cpp:4604
QPaintDevice * redirected(QPoint *offset) const
Definition qwidget_p.h:510
QPainter * sharedPainter() const
Definition qwidget_p.h:872
bool setMinimumSize_helper(int &minw, int &minh)
Definition qwidget.cpp:3882
void init(QWidget *desktopWidget, Qt::WindowFlags f)
Definition qwidget.cpp:937
uint directFontResolveMask
Definition qwidget_p.h:689
bool removeFromFocusChain(FocusChainRemovalRules rules=FocusChainRemovalRules(), FocusDirection direction=FocusDirection::Next)
void deleteSysExtra()
Definition qwidget.cpp:1687
void setGeometry_sys(int, int, int, int, bool)
Definition qwidget.cpp:7211
void setFont_helper(const QFont &font)
Definition qwidget_p.h:276
static int maxInstances
Definition qwidget_p.h:702
void createExtra()
Definition qwidget.cpp:1632
decltype(std::declval< QPalette >().resolveMask()) directPaletteResolveMask
Definition qwidget_p.h:691
void invalidateBackingStore(const T &)
void show_recursive()
Definition qwidget.cpp:7898
virtual void endCompose()
Definition qwidget_p.h:609
void setWindowIconText_sys(const QString &cap)
Definition qwidget.cpp:6054
virtual QObject * focusObject()
Definition qwidget.cpp:6833
void createWinId()
Definition qwidget.cpp:2370
void setWindowFilePath_helper(const QString &filePath)
Definition qwidget.cpp:6262
void deleteTLSysExtra()
Definition qwidget.cpp:1691
bool isInFocusChain() const
void createRecursively()
Definition qwidget.cpp:1019
QWidgetPrivate(int version=QObjectPrivateVersion)
Definition qwidget.cpp:105
QLayout * layout
Definition qwidget_p.h:651
void fixPosIncludesFrame()
Definition qwidget.cpp:7143
void reparentWidgetWindows(QWidget *parentWithWindow, Qt::WindowFlags windowFlags={})
void updateFocusChild()
Definition qwidget.cpp:6638
void stackUnder_sys(QWidget *)
void show_helper()
Definition qwidget.cpp:7978
static QWidgetSet * allWidgets
Definition qwidget_p.h:662
QWindow * windowHandle(WindowHandleMode mode=WindowHandleMode::Direct) const
Definition qwidget.cpp:1055
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:5312
void _q_showIfNotHidden()
Definition qwidget.cpp:8390
void setConstraints_sys()
Definition qwidget.cpp:3915
QBackingStore * backingStore() const
void setBackingStore(QBackingStore *backingStore)
void markNeedsFlush(QWidget *widget, const QRegion &region, const QPoint &topLevelOffset)
Marks the region of the widget as needing a flush.
QObject * focusObject() const override
Returns the QObject that will be the final receiver of events tied focus, such as key events.
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
void setAutoFillBackground(bool enabled)
Definition qwidget.cpp:330
QRect normalGeometry
the geometry of the widget as it will appear when shown as a normal (not maximized or full screen) to...
Definition qwidget.h:108
void setWindowFilePath(const QString &filePath)
Definition qwidget.cpp:6250
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:8667
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:4333
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:6294
QWidget * window() const
Returns the window for this widget, i.e.
Definition qwidget.cpp:4313
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:6081
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:4391
bool autoFillBackground
whether the widget background is filled automatically
Definition qwidget.h:172
void setUpdatesEnabled(bool enable)
Definition qwidget.cpp:7858
QPointF mapFromParent(const QPointF &) const
Translates the parent widget coordinate pos to widget coordinates.
Definition qwidget.cpp:4286
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:9731
void setWindowModality(Qt::WindowModality windowModality)
Definition qwidget.cpp:2799
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:9461
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:7590
Q_INVOKABLE QPixmap grab(const QRect &rectangle=QRect(QPoint(0, 0), QSize(-1, -1)))
Definition qwidget.cpp:5215
void setParent(QWidget *parent)
Sets the parent of the widget to parent, and resets the window flags.
Qt::WindowModality windowModality
which windows are blocked by the modal widget
Definition qwidget.h:104
void setMinimumSize(const QSize &)
Definition qwidget.h:832
void setMask(const QBitmap &)
Causes only the pixels of the widget for which bitmap has a corresponding 1 bit to be visible.
void updateGeometry()
Notifies the layout system that this widget has changed and may need to change geometry.
void setSizePolicy(QSizePolicy)
void setStyle(QStyle *)
Sets the widget's GUI style to style.
Definition qwidget.cpp:2630
QWidget * focusProxy() const
Returns the focus proxy, or \nullptr if there is no focus proxy.
Definition qwidget.cpp:6427
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:9856
void setMinimumWidth(int minw)
Definition qwidget.cpp:4112
bool isMinimized() const
Definition qwidget.cpp:2836
bool isFullScreen() const
Definition qwidget.cpp:2982
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:6845
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:6683
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:6981
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:3358
void setWindowOpacity(qreal level)
void setFocusProxy(QWidget *)
Sets the widget's focus proxy to widget w.
Definition qwidget.cpp:6368
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:4530
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:9835
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:9483
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:8643
@ 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:2847
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:6859
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:9530
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:2876
friend class QStyleSheetStyle
Definition qwidget.h:760
QRect contentsRect() const
Returns the area inside the widget's margins.
Definition qwidget.cpp:7667
void overrideWindowState(Qt::WindowStates state)
Definition qwidget.cpp:2900
~QWidget()
Destroys the widget.
Definition qwidget.cpp:1439
void unsetCursor()
Definition qwidget.cpp:4983
void setShortcutAutoRepeat(int id, bool enable=true)
bool close()
Closes this widget.
Definition qwidget.cpp:8562
void adjustSize()
Adjusts the size of the widget to fit its contents.
Definition qwidget.cpp:8743
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:2441
void showFullScreen()
Shows the widget in full-screen mode.
Definition qwidget.cpp:3021
QWidget * focusWidget() const
Returns the last child of this widget that setFocus had been called on.
Definition qwidget.cpp:6828
void setContextMenuPolicy(Qt::ContextMenuPolicy policy)
Definition qwidget.cpp:7790
static QWidget * find(WId)
Returns a pointer to the widget with window identifier/handle id.
Definition qwidget.cpp:2327
virtual void focusInEvent(QFocusEvent *event)
This event handler can be reimplemented in a subclass to receive keyboard focus events (focus receive...
Definition qwidget.cpp:9665
bool isModal() const
Definition qwidget.h:817
void setAcceptDrops(bool on)
Definition qwidget.cpp:3436
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:9508
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:9641
QSizePolicy sizePolicy
the default layout behavior of the widget
Definition qwidget.h:119
void setMaximumHeight(int maxh)
Definition qwidget.cpp:4139
QLocale locale
the widget's locale
Definition qwidget.h:176
void setFocusPolicy(Qt::FocusPolicy policy)
Definition qwidget.cpp:7822
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:9801
void setWindowRole(const QString &)
Sets the window's role to role.
Definition qwidget.cpp:6304
QSize minimumSizeHint
the recommended minimum size for the widget
Definition qwidget.h:149
void hide()
Hides the widget.
Definition qwidget.cpp:8135
void setMinimumHeight(int minh)
Definition qwidget.cpp:4121
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:6777
virtual QVariant inputMethodQuery(Qt::InputMethodQuery) const
This method is only relevant for input widgets.
Definition qwidget.cpp:9913
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:3207
int devType() const override
Definition qwidget.cpp:882
void setHidden(bool hidden)
Convenience function, equivalent to setVisible(!hidden).
Definition qwidget.cpp:8379
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:3090
void setWindowState(Qt::WindowStates state)
Sets the window state to windowState.
Definition qwidget.cpp:2937
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:3450
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:4879
void show()
Shows the widget and its child widgets.
Definition qwidget.cpp:7875
virtual void setVisible(bool visible)
Definition qwidget.cpp:8255
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:3142
void setScreen(QScreen *)
Sets the screen on which the widget should be shown to screen.
Definition qwidget.cpp:2524
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:9715
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:2483
virtual void changeEvent(QEvent *)
This event handler can be reimplemented to handle state changes.
Definition qwidget.cpp:9382
void setFixedHeight(int h)
Sets both the minimum and maximum heights of the widget to h without changing the widths.
Definition qwidget.cpp:4175
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:3044
void setFixedWidth(int w)
Sets both the minimum and maximum width of the widget to w without changing the heights.
Definition qwidget.cpp:4155
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:9898
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:4229
Qt::InputMethodHints inputMethodHints
What input method specific hints the widget has.
Definition qwidget.h:178
WId effectiveWinId() const
Definition qwidget.cpp:2462
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:3127
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:2357
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:6105
QPaintDevice * redirected(QPoint *offset) const override
QByteArray saveGeometry() const
Definition qwidget.cpp:7337
bool event(QEvent *event) override
This is the main event handler; it handles event event.
Definition qwidget.cpp:8866
void setLocale(const QLocale &locale)
Definition qwidget.cpp:5913
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:2600
void setWindowIcon(const QIcon &icon)
Definition qwidget.cpp:6174
void setFont(const QFont &)
Definition qwidget.cpp:4667
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:5092
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:1156
void destroy(bool destroyWindow=true, bool destroySubWindows=true)
Frees up window system resources.
bool hasFocus() const
Definition qwidget.cpp:6446
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:9691
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:9822
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:4411
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:4197
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:2888
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:8822
QBackingStore * backingStore() const
QScreen * screen() const
Returns the screen the widget is on.
Definition qwidget.cpp:2496
void showNormal()
Restores the widget after it has been maximized or minimized.
Definition qwidget.cpp:3060
void setForegroundRole(QPalette::ColorRole)
Sets the foreground role of the widget to role.
Definition qwidget.cpp:4456
void clearMask()
Removes any mask set by setMask().
bool restoreGeometry(const QByteArray &geometry)
Definition qwidget.cpp:7449
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:3176
bool isActiveWindow
whether this widget's window is the active window
Definition qwidget.h:139
void setStyleSheet(const QString &styleSheet)
Definition qwidget.cpp:2555
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:4360
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:9606
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:4263
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:4082
QMargins contentsMargins() const
The contentsMargins function returns the widget's contents margins.
Definition qwidget.cpp:7654
void removeAction(QAction *action)
Removes the action action from this widget's list of actions.
Definition qwidget.cpp:3186
virtual void paintEvent(QPaintEvent *event)
This event handler can be reimplemented in a subclass to receive paint events passed in event.
Definition qwidget.cpp:9783
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:4897
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:3117
void releaseMouse()
Releases the mouse grab.
void setInputMethodHints(Qt::InputMethodHints hints)
Definition qwidget.cpp:9971
Qt::WindowType windowType() const
Returns the window type of this widget.
Definition qwidget.h:801
void setCursor(const QCursor &)
Definition qwidget.cpp:4960
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:9875
void unsetLocale()
Definition qwidget.cpp:5939
void setMaximumWidth(int maxw)
Definition qwidget.cpp:4130
void windowTitleChanged(const QString &title)
This signal is emitted when the window's title has changed, with the new title as an argument.
bool visible
whether the widget is visible
Definition qwidget.h:144
QRect childrenRect
the bounding rectangle of the widget's children
Definition qwidget.h:117
virtual int heightForWidth(int) const
Returns the preferred height for this widget, given the width w.
void setWindowFlags(Qt::WindowFlags type)
static void parentWasChanged(QWidget *parent)
static void parentWasRaised(QWidget *parent)
static void parentWasMoved(QWidget *parent)
static void parentWasLowered(QWidget *parent)
static void toplevelAboutToBeDestroyed(QWidget *parent)
\inmodule QtGui
Definition qevent.h:899
\inmodule QtGui
Definition qwindow.h:63
void focusObjectChanged(QObject *object)
This signal is emitted when the final receiver of events tied to focus is changed to object.
QOpenGLWidget * widget
[1]
QString text
QCursor cursor
QSet< QString >::iterator it
rect
[4]
direction
QStyleOptionButton opt
short next
Definition keywords.cpp:445
Combined button and popup list for selecting options.
Definition qcompare.h:63
WindowState
Definition qnamespace.h:251
@ WindowFullScreen
Definition qnamespace.h:255
@ WindowNoState
Definition qnamespace.h:252
@ WindowMinimized
Definition qnamespace.h:253
@ WindowMaximized
Definition qnamespace.h:254
@ WindowActive
Definition qnamespace.h:256
InputMethodQuery
@ ImInputItemClipRectangle
@ ImCursorPosition
@ ImFont
@ ImAnchorPosition
@ ImCursorRectangle
@ ImHints
@ ImEnabled
@ NavigationModeKeypadDirectional
@ NavigationModeKeypadTabOrder
QTextStream & hex(QTextStream &stream)
Calls QTextStream::setIntegerBase(16) on stream and returns stream.
@ NoButton
Definition qnamespace.h:57
WidgetAttribute
Definition qnamespace.h:282
@ WA_GrabbedShortcut
Definition qnamespace.h:316
@ WA_X11NetWmWindowTypeDND
Definition qnamespace.h:398
@ WA_SetWindowIcon
Definition qnamespace.h:319
@ WA_X11NetWmWindowTypePopupMenu
Definition qnamespace.h:394
@ WA_WState_ExplicitShowHide
Definition qnamespace.h:335
@ WA_AcceptTouchEvents
Definition qnamespace.h:404
@ WA_UnderMouse
Definition qnamespace.h:284
@ WA_AlwaysStackOnTop
Definition qnamespace.h:411
@ WA_WState_WindowOpacitySet
Definition qnamespace.h:401
@ WA_TransparentForMouseEvents
Definition qnamespace.h:317
@ WA_ForceUpdatesDisabled
Definition qnamespace.h:325
@ WA_PendingResizeEvent
Definition qnamespace.h:302
@ WA_SetLayoutDirection
Definition qnamespace.h:323
@ WA_StyleSheet
Definition qnamespace.h:372
@ WA_MacMiniSize
Definition qnamespace.h:363
@ WA_SetLocale
Definition qnamespace.h:358
@ WA_SetPalette
Definition qnamespace.h:303
@ WA_WindowPropagation
Definition qnamespace.h:349
@ WA_MacAlwaysShowToolWindow
Definition qnamespace.h:370
@ WA_SetWindowModality
Definition qnamespace.h:400
@ WA_X11NetWmWindowTypeDock
Definition qnamespace.h:387
@ WA_X11NetWmWindowTypeUtility
Definition qnamespace.h:390
@ WA_RightToLeft
Definition qnamespace.h:322
@ WA_X11NetWmWindowTypeDialog
Definition qnamespace.h:392
@ WA_X11NetWmWindowTypeSplash
Definition qnamespace.h:391
@ WA_SetCursor
Definition qnamespace.h:305
@ WA_X11NetWmWindowTypeDropDownMenu
Definition qnamespace.h:393
@ WA_Resized
Definition qnamespace.h:308
@ WA_QuitOnClose
Definition qnamespace.h:342
@ WA_WState_Polished
Definition qnamespace.h:332
@ WA_TranslucentBackground
Definition qnamespace.h:402
@ WA_NoChildEventsFromChildren
Definition qnamespace.h:306
@ WA_DontShowOnScreen
Definition qnamespace.h:383
@ WA_ContentsMarginsRespectsSafeArea
Definition qnamespace.h:415
@ WA_X11NetWmWindowTypeToolTip
Definition qnamespace.h:395
@ WA_X11NetWmWindowTypeCombo
Definition qnamespace.h:397
@ WA_X11NetWmWindowTypeToolBar
Definition qnamespace.h:388
@ WA_DropSiteRegistered
Definition qnamespace.h:347
@ WA_KeyboardFocusChange
Definition qnamespace.h:344
@ WA_PendingMoveEvent
Definition qnamespace.h:301
@ WA_PaintOnScreen
Definition qnamespace.h:290
@ WA_NoChildEventsForParent
Definition qnamespace.h:324
@ WA_AttributeCount
Definition qnamespace.h:420
@ WA_DontCreateNativeAncestors
Definition qnamespace.h:379
@ WA_Moved
Definition qnamespace.h:309
@ WA_SetStyle
Definition qnamespace.h:356
@ WA_MacNormalSize
Definition qnamespace.h:361
@ WA_NativeWindow
Definition qnamespace.h:378
@ WA_Disabled
Definition qnamespace.h:283
@ WA_TabletTracking
Definition qnamespace.h:413
@ WA_OutsideWSRange
Definition qnamespace.h:315
@ WA_WState_Hidden
Definition qnamespace.h:297
@ WA_StaticContents
Definition qnamespace.h:288
@ WA_ShowWithoutActivating
Definition qnamespace.h:374
@ WA_X11NetWmWindowTypeMenu
Definition qnamespace.h:389
@ WA_WState_Visible
Definition qnamespace.h:296
@ WA_NoSystemBackground
Definition qnamespace.h:291
@ WA_WState_InPaintEvent
Definition qnamespace.h:329
@ WA_WState_OwnSizePolicy
Definition qnamespace.h:334
@ WA_SetFont
Definition qnamespace.h:304
@ WA_StyledBackground
Definition qnamespace.h:366
@ WA_WState_Created
Definition qnamespace.h:327
@ WA_MacSmallSize
Definition qnamespace.h:362
@ WA_TintedBackground
Definition qnamespace.h:352
@ WA_ShowModal
Definition qnamespace.h:337
@ WA_X11NetWmWindowTypeDesktop
Definition qnamespace.h:386
@ WA_UpdatesDisabled
Definition qnamespace.h:292
@ WA_InputMethodEnabled
Definition qnamespace.h:295
@ WA_MouseTracking
Definition qnamespace.h:285
@ WA_ForceDisabled
Definition qnamespace.h:299
@ WA_Mapped
Definition qnamespace.h:293
@ WA_OpaquePaintEvent
Definition qnamespace.h:287
@ WA_DeleteOnClose
Definition qnamespace.h:321
@ WA_WindowModified
Definition qnamespace.h:307
@ WA_LayoutOnEntireRect
Definition qnamespace.h:314
@ WA_AcceptDrops
Definition qnamespace.h:346
@ WA_X11NetWmWindowTypeNotification
Definition qnamespace.h:396
WindowModality
@ NonModal
@ ApplicationModal
LayoutDirection
@ LeftToRight
@ LayoutDirectionAuto
@ RightToLeft
QTextStream & noforcesign(QTextStream &stream)
Calls QTextStream::setNumberFlags(QTextStream::numberFlags() & ~QTextStream::ForceSign) on stream and...
FocusPolicy
Definition qnamespace.h:106
@ NoFocus
Definition qnamespace.h:107
@ TabFocus
Definition qnamespace.h:108
Orientation
Definition qnamespace.h:98
@ Horizontal
Definition qnamespace.h:99
@ Vertical
Definition qnamespace.h:100
@ ArrowCursor
@ ImhNone
@ transparent
Definition qnamespace.h:47
@ Key_Tab
Definition qnamespace.h:664
@ Key_Right
Definition qnamespace.h:679
@ Key_Backtab
Definition qnamespace.h:665
@ Key_Left
Definition qnamespace.h:677
@ Key_Up
Definition qnamespace.h:678
@ Key_Down
Definition qnamespace.h:680
@ Key_F1
Definition qnamespace.h:690
QTextStream & dec(QTextStream &stream)
Calls QTextStream::setIntegerBase(10) on stream and returns stream.
@ FindDirectChildrenOnly
@ FindChildrenRecursively
@ ShiftModifier
@ ControlModifier
@ AltModifier
@ AA_DontCreateNativeWidgetSiblings
Definition qnamespace.h:429
@ AA_UseStyleSheetPropagationInWidgetStyles
Definition qnamespace.h:457
@ AA_NativeWindows
Definition qnamespace.h:428
@ AA_PluginApplication
Definition qnamespace.h:430
QTextStream & forcesign(QTextStream &stream)
Calls QTextStream::setNumberFlags(QTextStream::numberFlags() | QTextStream::ForceSign) on stream and ...
@ SolidPattern
@ TexturePattern
@ NoBrush
@ ApplicationActive
Definition qnamespace.h:266
ConnectionType
CoordinateSystem
@ DeviceCoordinates
GestureType
WindowType
Definition qnamespace.h:205
@ CustomizeWindowHint
Definition qnamespace.h:239
@ Desktop
Definition qnamespace.h:215
@ Widget
Definition qnamespace.h:206
@ FramelessWindowHint
Definition qnamespace.h:225
@ MSWindowsOwnDC
Definition qnamespace.h:222
@ WindowContextHelpButtonHint
Definition qnamespace.h:231
@ ToolTip
Definition qnamespace.h:213
@ Popup
Definition qnamespace.h:211
@ WindowType_Mask
Definition qnamespace.h:220
@ Window
Definition qnamespace.h:207
@ SplashScreen
Definition qnamespace.h:214
@ WindowFullscreenButtonHint
Definition qnamespace.h:245
@ WindowMaximizeButtonHint
Definition qnamespace.h:229
@ WindowMinimizeButtonHint
Definition qnamespace.h:228
@ Dialog
Definition qnamespace.h:208
@ WindowMinMaxButtonsHint
Definition qnamespace.h:230
@ Sheet
Definition qnamespace.h:209
@ WindowTransparentForInput
Definition qnamespace.h:234
@ SubWindow
Definition qnamespace.h:216
@ MaximizeUsingFullscreenGeometryHint
Definition qnamespace.h:237
@ Tool
Definition qnamespace.h:212
@ WindowTitleHint
Definition qnamespace.h:226
@ WindowSystemMenuHint
Definition qnamespace.h:227
@ WindowCloseButtonHint
Definition qnamespace.h:241
ContextMenuPolicy
@ ActionsContextMenu
@ DefaultContextMenu
@ CustomContextMenu
@ PreventContextMenu
FocusReason
@ PopupFocusReason
@ BacktabFocusReason
@ NoFocusReason
@ MenuBarFocusReason
@ OtherFocusReason
@ TabFocusReason
ShortcutContext
Definition brush.cpp:5
static void * context
Q_WIDGETS_EXPORT QWidget * qt_button_down
void qt_qpa_set_cursor(QWidget *w, bool force)
Definition qwidget.cpp:5014
int qstrncmp(const char *str1, const char *str2, size_t len)
#define Q_FALLTHROUGH()
#define Q_UNLIKELY(x)
#define Q_FUNC_INFO
#define qApp
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char return DBusMessage return DBusMessage const char return DBusMessage dbus_bool_t return DBusMessage dbus_uint32_t return DBusMessage void
EGLStreamKHR stream
EGLConfig config
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
EGLOutputLayerEXT EGLint attribute
#define QT_RETHROW
#define QT_CATCH(A)
#define QT_TRY
bool qFuzzyIsNull(qfloat16 f) noexcept
Definition qfloat16.h:349
int qRound(qfloat16 d) noexcept
Definition qfloat16.h:327
#define qDebug
[1]
Definition qlogging.h:164
@ QtWarningMsg
Definition qlogging.h:31
#define qWarning
Definition qlogging.h:166
#define qFatal
Definition qlogging.h:168
#define Q_LOGGING_CATEGORY(name,...)
#define qCInfo(category,...)
#define qCWarning(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:53
static bool contains(const QJsonArray &haystack, unsigned needle)
Definition qopengl.cpp:116
GLsizei const GLfloat * v
[13]
GLuint64 GLenum void * handle
GLint GLint GLint GLint GLint x
[0]
GLint GLenum GLsizei GLsizei GLsizei depth
GLenum mode
const GLfloat * m
GLenum GLuint GLint level
GLuint64 key
GLfloat GLfloat GLfloat w
[0]
GLint GLsizei GLsizei height
GLboolean GLboolean GLboolean GLboolean a
[7]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLuint index
[2]
GLboolean r
[2]
GLuint GLuint end
GLenum GLuint id
[7]
GLdouble GLdouble GLdouble GLdouble top
GLenum GLenum GLsizei count
GLdouble GLdouble right
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLenum GLenum GLsizei const GLuint GLboolean enabled
GLfloat GLfloat f
GLint left
GLenum type
GLint GLint bottom
GLenum target
GLbitfield flags
GLboolean enable
GLuint GLsizei const GLchar * message
GLenum GLuint GLintptr offset
GLboolean GLboolean g
GLuint name
GLint first
GLint GLint GLint GLint GLint GLint GLint GLbitfield mask
GLint GLsizei GLsizei GLenum format
GLint y
GLfloat GLfloat GLfloat GLfloat h
GLsizei GLsizei GLchar * source
struct _cl_event * event
GLuint GLenum GLenum transform
GLdouble s
[6]
Definition qopenglext.h:235
GLenum query
GLuint res
const GLubyte * c
GLint void * img
Definition qopenglext.h:233
GLenum array
GLsizei GLfixed GLfixed GLfixed GLfixed const GLubyte * bitmap
GLdouble GLdouble t
Definition qopenglext.h:243
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259
GLsizei const GLchar *const * path
GLuint64EXT * result
[6]
GLfloat GLfloat p
[1]
GLenum cap
static const QRectF boundingRect(const QPointF *points, int pointCount)
static constexpr quint16 currentMajorVersion
\qmltype FileInstancing \inherits Instancing \inqmlmodule QtQuick3D
static qreal position(const QQuickItem *item, QQuickAnchors::Anchor anchorLine)
static QT_BEGIN_NAMESPACE qreal dpr(const QWindow *w)
void forceUpdate(QQuickItem *item)
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
#define Q_ASSERT_X(cond, x, msg)
Definition qrandom.cpp:48
QScopeGuard< typename std::decay< F >::type > qScopeGuard(F &&f)
[qScopeGuard]
Definition qscopeguard.h:60
bool qWidgetShortcutContextMatcher(QObject *object, Qt::ShortcutContext context)
#define qPrintable(string)
Definition qstring.h:1531
static char * toLocal8Bit(char *out, QStringView in, QStringConverter::State *state)
QStyleSheetStyle * qt_styleSheet(QStyle *style)
#define sp
#define fp
QScreen * screen
[1]
Definition main.cpp:29
#define QT_CONFIG(feature)
Q_CORE_EXPORT int qEnvironmentVariableIntValue(const char *varName, bool *ok=nullptr) noexcept
#define emit
#define Q_UNUSED(x)
unsigned int quint32
Definition qtypes.h:50
unsigned short quint16
Definition qtypes.h:48
int qint32
Definition qtypes.h:49
unsigned int uint
Definition qtypes.h:34
double qreal
Definition qtypes.h:187
unsigned char quint8
Definition qtypes.h:46
ptrdiff_t qintptr
Definition qtypes.h:166
static bool canMapPosition(QWindow *window)
static void unsetCursor(QWidget *w)
Definition qwidget.cpp:5008
static QWidget * keyboardGrb
void q_createNativeChildrenAndSetParent(const QWidget *parentWidget)
Definition qwidget.cpp:1242
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:5992
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:5188
static void applyCursor(QWidget *w, const QCursor &c)
Definition qwidget.cpp:5002
#define FOCUS_PREV(w)
static bool isEmbedded(const QWindow *w)
Definition qwidget.cpp:6612
static void releaseMouseGrabOfWidget(QWidget *widget)
#define FOCUS_NEXT(w)
static void grabMouseForWidget(QWidget *widget, const QCursor *cursor=nullptr)
QWidget * qt_button_down
static MapToGlobalTransformResult mapToGlobalTransform(const QWidget *w)
static void setAttribute_internal(Qt::WidgetAttribute attribute, bool on, QWidgetData *data, QWidgetPrivate *d)
void qSendWindowChangeToTextureChildrenRecursively(QWidget *widget, QEvent::Type eventType)
static bool qRectIntersects(const QRect &r1, const QRect &r2)
Definition qwidget.cpp:97
QWidgetList focusPath(QWidget *from, QWidget *to, QWidgetPrivate::FocusDirection direction)
QWidget * qt_pressGrab
void qt_qpa_set_cursor(QWidget *w, bool force)
Definition qwidget.cpp:5014
bool q_evaluateRhiConfig(const QWidget *w, QPlatformBackingStoreRhiConfig *outConfig, QSurface::SurfaceType *outType)
Definition qwidget.cpp:1122
static QWindow * grabberWindow(const QWidget *w)
static void fillRegion(QPainter *painter, const QRegion &rgn, const QBrush &brush)
Definition qwidget.cpp:2223
static bool q_evaluateRhiConfigRecursive(const QWidget *w, QPlatformBackingStoreRhiConfig *outConfig, QSurface::SurfaceType *outType)
Definition qwidget.cpp:1103
QWidget * qt_mouseGrb
bool qt_sendSpontaneousEvent(QObject *, QEvent *)
#define QWIDGETSIZE_MAX
Definition qwidget.h:917
const QWidget * qobject_cast< const QWidget * >(const QObject *o)
Definition qwidget.h:791
QWidget * qobject_cast< QWidget * >(QObject *o)
Definition qwidget.h:786
static bool bypassGraphicsProxyWidget(const QWidget *p)
Definition qwidget_p.h:169
Q_GUI_EXPORT QWindowPrivate * qt_window_private(QWindow *window)
Definition qwindow.cpp:2950
QT_BEGIN_NAMESPACE typedef QHash< WId, QWidget * > QWidgetMapper
Definition qwindowdefs.h:68
QList< QWidget * > QWidgetList
Definition qwindowdefs.h:47
static QWindowsDirect2DWindow * nativeWindow(QWindow *window)
static QRect frameGeometry(HWND hwnd, bool topLevel)
const char property[13]
Definition qwizard.cpp: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()
QList< QWidget * > widgets
[11]
QObject::connect nullptr
QVBoxLayout * layout
QString title
[35]
QRect r1(100, 200, 11, 16)
[0]
QRect r2(QPoint(100, 200), QSize(11, 16))
QGraphicsOpacityEffect * effect
the effect attached to this item
QGraphicsScene scene
[0]
edit isVisible()
QLayoutItem * child
[0]
widget render & pixmap
QPainter painter(this)
[7]
aWidget window() -> setWindowTitle("New Window Title")
[2]
QSizePolicy policy
QNetworkAccessManager manager
QNetworkProxy proxy
[0]
view create()
QJSEngine engine
[0]
qsizetype indexOf(const AT &t, qsizetype from=0) const noexcept
Definition qlist.h:962
\inmodule QtCore
QRect frameStrut
Definition qwidget_p.h:109
uint posIncludesFrame
Definition qwidget_p.h:118
QRect normalGeometry
Definition qwidget_p.h:110
uint opacity
Definition qwidget_p.h:117
QScreen * initialScreen
Definition qwidget_p.h:112
QBackingStore * backingStore
Definition qwidget_p.h:95
short basew
Definition qwidget_p.h:107
QWidgetWindow * window
Definition qwidget_p.h:97
short incw
Definition qwidget_p.h:106
static void cleanup(QWidget *that, QWidgetPrivate *d)
Definition qwidget.cpp:816