summaryrefslogtreecommitdiffstats
path: root/src/widgets/kernel/qwidget.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/widgets/kernel/qwidget.cpp')
-rw-r--r--src/widgets/kernel/qwidget.cpp1173
1 files changed, 758 insertions, 415 deletions
diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp
index a92454547a..30daee1b79 100644
--- a/src/widgets/kernel/qwidget.cpp
+++ b/src/widgets/kernel/qwidget.cpp
@@ -1,42 +1,6 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 The Qt Company Ltd.
-** Copyright (C) 2016 Intel Corporation.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWidgets module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2017 The Qt Company Ltd.
+// Copyright (C) 2016 Intel Corporation.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qapplication.h"
#include "qapplication_p.h"
@@ -57,7 +21,7 @@
#include "qwidget.h"
#include "qstyleoption.h"
#include "qstylehints.h"
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
# include "qaccessible.h"
#endif
#include <qpa/qplatformwindow.h>
@@ -77,9 +41,6 @@
#include "qscopeguard.h"
#include <QtGui/private/qhighdpiscaling_p.h>
#include <QtGui/qinputmethod.h>
-#include <QtGui/qopenglcontext.h>
-#include <QtGui/private/qopenglcontext_p.h>
-#include <QtGui/qoffscreensurface.h>
#if QT_CONFIG(graphicseffect)
#include <private/qgraphicseffect_p.h>
@@ -113,15 +74,23 @@
#include "qwindowcontainer_p.h"
-// widget/widget data creation count
-//#define QWIDGET_EXTRA_DEBUG
-//#define ALIEN_DEBUG
+#include <sstream>
QT_BEGIN_NAMESPACE
using namespace QNativeInterface::Private;
+using namespace Qt::StringLiterals;
Q_LOGGING_CATEGORY(lcWidgetPainting, "qt.widgets.painting", QtWarningMsg);
+Q_LOGGING_CATEGORY(lcWidgetShowHide, "qt.widgets.showhide", QtWarningMsg);
+Q_LOGGING_CATEGORY(lcWidgetWindow, "qt.widgets.window", QtWarningMsg);
+
+#ifndef QT_NO_DEBUG_STREAM
+namespace {
+ struct WidgetAttributes { const QWidget *widget; };
+ QDebug operator<<(QDebug debug, const WidgetAttributes &attributes);
+}
+#endif
static inline bool qRectIntersects(const QRect &r1, const QRect &r2)
{
@@ -178,10 +147,8 @@ QWidgetPrivate::QWidgetPrivate(int version)
#ifndef QT_NO_IM
, inheritsInputMethodHints(0)
#endif
-#ifndef QT_NO_OPENGL
, renderToTextureReallyDirty(1)
- , renderToTextureComposeActive(0)
-#endif
+ , usesRhiFlush(0)
, childrenHiddenByWState(0)
, childrenShownByExpose(0)
#if defined(Q_OS_WIN)
@@ -203,7 +170,7 @@ QWidgetPrivate::QWidgetPrivate(int version)
version, QObjectPrivateVersion);
#endif
- isWidget = true;
+ willBeWidget = true; // used in QObject's ctor
memset(high_attributes, 0, sizeof(high_attributes));
#ifdef QWIDGET_EXTRA_DEBUG
@@ -399,14 +366,14 @@ void QWidget::setAutoFillBackground(bool enabled)
If not, it will be a child of \e parent, and be constrained by
\e parent's geometry (unless you specify Qt::Window as window flag).
\li \c{Qt::WindowFlags f = { }} (where available) sets the window flags;
- the default is suitable for almost all widgets, but to get, for
+ the default is suitable for most widgets, but to get, for
example, a window without a window system frame, you must use
special flags.
\endlist
QWidget has many member functions, but some of them have little direct
functionality; for example, QWidget has a font property, but never uses
- this itself. There are many subclasses which provide real functionality,
+ this itself. There are many subclasses that provide real functionality,
such as QLabel, QPushButton, QListWidget, and QTabWidget.
@@ -414,7 +381,7 @@ void QWidget::setAutoFillBackground(bool enabled)
A widget without a parent widget is always an independent window (top-level
widget). For these widgets, setWindowTitle() and setWindowIcon() set the
- title bar and icon respectively.
+ title bar and icon, respectively.
Non-window widgets are child widgets, displayed within their parent
widgets. Most widgets in Qt are mainly useful as child widgets. For
@@ -427,7 +394,7 @@ void QWidget::setAutoFillBackground(bool enabled)
widgets in a layout provided by QGridLayout. The QLabel child widgets have
been outlined to indicate their full sizes.
- If you want to use a QWidget to hold child widgets you will usually want to
+ If you want to use a QWidget to hold child widgets, you will usually want to
add a layout to the parent QWidget. See \l{Layout Management} for more
information.
@@ -437,14 +404,13 @@ void QWidget::setAutoFillBackground(bool enabled)
When a widget is used as a container to group a number of child widgets, it
is known as a composite widget. These can be created by constructing a
widget with the required visual properties - a QFrame, for example - and
- adding child widgets to it, usually managed by a layout. The above diagram
- shows such a composite widget that was created using Qt Designer.
+ adding child widgets to it, usually managed by a layout.
Composite widgets can also be created by subclassing a standard widget,
such as QWidget or QFrame, and adding the necessary layout and child
widgets in the constructor of the subclass. Many of the \l{Qt Widgets Examples}
{examples provided with Qt} use this approach, and it is also covered in
- the Qt \l{Tutorials}.
+ the Qt \l{Widgets Tutorial}.
\section1 Custom Widgets and Painting
@@ -458,7 +424,7 @@ void QWidget::setAutoFillBackground(bool enabled)
Each widget performs all painting operations from within its paintEvent()
function. This is called whenever the widget needs to be redrawn, either
- as a result of some external change or when requested by the application.
+ because of some external change or when requested by the application.
The \l{widgets/analogclock}{Analog Clock example} shows how a simple widget
can handle paint events.
@@ -470,7 +436,7 @@ void QWidget::setAutoFillBackground(bool enabled)
sizeHint() to provide a reasonable default size for the widget and to set
the correct size policy with setSizePolicy().
- By default, composite widgets which do not provide a size hint will be
+ By default, composite widgets that do not provide a size hint will be
sized according to the space requirements of their child widgets.
The size policy lets you supply good default behavior for the layout
@@ -490,9 +456,9 @@ void QWidget::setAutoFillBackground(bool enabled)
delivers events to widgets by calling specific event handler functions with
instances of QEvent subclasses containing information about each event.
- If your widget only contains child widgets, you probably do not need to
+ If your widget only contains child widgets, you probably don't need to
implement any event handlers. If you want to detect a mouse click in a
- child widget call the child's underMouse() function inside the widget's
+ child widget, call the child's underMouse() function inside the widget's
mousePressEvent().
The \l{widgets/scribble}{Scribble example} implements a wider set of
@@ -557,7 +523,7 @@ void QWidget::setAutoFillBackground(bool enabled)
button is held down. This can be useful during drag and drop
operations. If you call \l{setMouseTracking()}{setMouseTracking}(true),
you get mouse move events even when no buttons are held down.
- (See also the \l{Drag and Drop} guide.)
+ (See also the \l{Drag and Drop in Qt}{Drag and Drop} guide.)
\li keyReleaseEvent() is called whenever a key is released and while it
is held down (if the key is auto-repeating). In that case, the
widget will receive a pair of key release and key press event for
@@ -571,7 +537,7 @@ void QWidget::setAutoFillBackground(bool enabled)
space. (This excludes screen space owned by any of the widget's
children.)
\li leaveEvent() is called when the mouse leaves the widget's screen
- space. If the mouse enters a child widget it will not cause a
+ space. If the mouse enters a child widget, it will not cause a
leaveEvent().
\li moveEvent() is called when the widget has been moved relative to
its parent.
@@ -709,11 +675,11 @@ void QWidget::setAutoFillBackground(bool enabled)
\section1 Transparency and Double Buffering
- Since Qt 4.0, QWidget automatically double-buffers its painting, so there
+ QWidget automatically double-buffers its painting, so there
is no need to write double-buffering code in paintEvent() to avoid
flicker.
- Since Qt 4.1, the contents of parent widgets are propagated by
+ The contents of parent widgets are propagated by
default to each of their children as long as Qt::WA_PaintOnScreen is not
set. Custom widgets can be written to take advantage of this feature by
updating irregular regions (to create non-rectangular child widgets), or
@@ -730,7 +696,7 @@ void QWidget::setAutoFillBackground(bool enabled)
\list
\li The left widget has no additional properties or widget attributes
- set. This default state suits most custom widgets using
+ set. This default state suits most custom widgets that have
transparency, are irregularly-shaped, or do not paint over their
entire area with an opaque brush.
\li The center widget has the \l autoFillBackground property set. This
@@ -741,10 +707,7 @@ void QWidget::setAutoFillBackground(bool enabled)
set. This indicates that the widget will paint over its entire area
with opaque colors. The widget's area will initially be
\e{uninitialized}, represented in the diagram with a red diagonal
- grid pattern that shines through the overpainted area. The
- Qt::WA_OpaquePaintArea attribute is useful for widgets that need to
- paint their own specialized contents quickly and do not need a
- default filled background.
+ grid pattern that shines through the overpainted area.
\endlist
To rapidly update custom widgets with simple background colors, such as
@@ -754,19 +717,18 @@ void QWidget::setAutoFillBackground(bool enabled)
implement the necessary drawing functionality in the widget's paintEvent().
To rapidly update custom widgets that constantly paint over their entire
- areas with opaque content, e.g., video streaming widgets, it is better to
- set the widget's Qt::WA_OpaquePaintEvent, avoiding any unnecessary overhead
- associated with repainting the widget's background.
+ areas with opaque content, for example, video streaming widgets, it is
+ better to set the widget's Qt::WA_OpaquePaintEvent, avoiding any unnecessary
+ overhead associated with repainting the widget's background.
If a widget has both the Qt::WA_OpaquePaintEvent widget attribute \e{and}
the \l autoFillBackground property set, the Qt::WA_OpaquePaintEvent
attribute takes precedence. Depending on your requirements, you should
choose either one of them.
- Since Qt 4.1, the contents of parent widgets are also propagated to
- standard Qt widgets. This can lead to some unexpected results if the
- parent widget is decorated in a non-standard way, as shown in the diagram
- below.
+ The contents of parent widgets are also propagated to standard Qt widgets.
+ This can lead to some unexpected results if the parent widget is decorated
+ in a non-standard way, as shown in the diagram below.
\image propagation-standard.png
@@ -778,8 +740,8 @@ void QWidget::setAutoFillBackground(bool enabled)
\section1 Creating Translucent Windows
- Since Qt 4.5, it has been possible to create windows with translucent regions
- on window systems that support compositing.
+ You can create windows with translucent regions on window systems that
+ support compositing.
To enable this feature in a top-level widget, set its Qt::WA_TranslucentBackground
attribute with setAttribute() and ensure that its background is painted with
@@ -799,19 +761,19 @@ void QWidget::setAutoFillBackground(bool enabled)
\section1 Native Widgets vs Alien Widgets
- Introduced in Qt 4.4, alien widgets are widgets unknown to the windowing
- system. They do not have a native window handle associated with them. This
- feature significantly speeds up widget painting, resizing, and removes flicker.
+ Alien widgets are widgets unknown to the windowing system. They do not have
+ a native window handle associated with them. This feature significantly
+ speeds up widget painting, resizing, and removes flicker.
- Should you require the old behavior with native windows, you can choose
- one of the following options:
+ Should you require the old behavior with native windows, choose one of the
+ following options:
\list 1
\li Use the \c{QT_USE_NATIVE_WINDOWS=1} in your environment.
\li Set the Qt::AA_NativeWindows attribute on your application. All
widgets will be native widgets.
\li Set the Qt::WA_NativeWindow attribute on widgets: The widget itself
- and all of its ancestors will become native (unless
+ and all its ancestors will become native (unless
Qt::WA_DontCreateNativeAncestors is set).
\li Call QWidget::winId to enforce a native window (this implies 3).
\li Set the Qt::WA_PaintOnScreen attribute to enforce a native window
@@ -978,6 +940,9 @@ void QWidgetPrivate::adjustFlags(Qt::WindowFlags &flags, QWidget *w)
void QWidgetPrivate::init(QWidget *parentWidget, Qt::WindowFlags f)
{
Q_Q(QWidget);
+ isWidget = true;
+ wasWidget = true;
+
Q_ASSERT_X(q != parentWidget, Q_FUNC_INFO, "Cannot parent a QWidget to itself");
if (Q_UNLIKELY(!qobject_cast<QApplication *>(QCoreApplication::instance())))
@@ -1065,6 +1030,31 @@ void QWidgetPrivate::createRecursively()
}
}
+QRhi *QWidgetPrivate::rhi() const
+{
+ if (QWidgetRepaintManager *repaintManager = maybeRepaintManager())
+ return repaintManager->rhi();
+ else
+ return nullptr;
+}
+
+/*!
+ \internal
+ Returns the closest parent widget that has a QWindow window handle
+
+ \note This behavior is different from nativeParentWidget(), which
+ returns the closest parent that has a QWindow window handle with
+ a created QPlatformWindow, and hence native window (winId).
+*/
+QWidget *QWidgetPrivate::closestParentWidgetWithWindowHandle() const
+{
+ Q_Q(const QWidget);
+ QWidget *parent = q->parentWidget();
+ while (parent && !parent->windowHandle())
+ parent = parent->parentWidget();
+ return parent;
+}
+
QWindow *QWidgetPrivate::windowHandle(WindowHandleMode mode) const
{
if (mode == WindowHandleMode::Direct || mode == WindowHandleMode::Closest) {
@@ -1074,6 +1064,7 @@ QWindow *QWidgetPrivate::windowHandle(WindowHandleMode mode) const
}
}
if (mode == WindowHandleMode::Closest) {
+ // FIXME: Use closestParentWidgetWithWindowHandle instead
if (auto nativeParent = q_func()->nativeParentWidget()) {
if (auto window = nativeParent->windowHandle())
return window;
@@ -1101,11 +1092,57 @@ QWindow *QWidgetPrivate::_q_closestWindowHandle() const
QScreen *QWidgetPrivate::associatedScreen() const
{
+#if QT_CONFIG(graphicsview)
+ // embedded widgets never have a screen associated, let QWidget::screen fall back to toplevel
+ if (nearestGraphicsProxyWidget(q_func()))
+ return nullptr;
+#endif
if (auto window = windowHandle(WindowHandleMode::Closest))
return window->screen();
return nullptr;
}
+// finds the first rhiconfig in the hierarchy that has enable==true
+static bool q_evaluateRhiConfigRecursive(const QWidget *w, QPlatformBackingStoreRhiConfig *outConfig, QSurface::SurfaceType *outType)
+{
+ QPlatformBackingStoreRhiConfig config = QWidgetPrivate::get(w)->rhiConfig();
+ if (config.isEnabled()) {
+ if (outConfig)
+ *outConfig = config;
+ if (outType)
+ *outType = QBackingStoreRhiSupport::surfaceTypeForConfig(config);
+ return true;
+ }
+ for (const QObject *child : w->children()) {
+ if (const QWidget *childWidget = qobject_cast<const QWidget *>(child)) {
+ if (q_evaluateRhiConfigRecursive(childWidget, outConfig, outType))
+ return true;
+ }
+ }
+ return false;
+}
+
+bool q_evaluateRhiConfig(const QWidget *w, QPlatformBackingStoreRhiConfig *outConfig, QSurface::SurfaceType *outType)
+{
+ // First, check env.vars. or other means that force the usage of rhi-based
+ // flushing with a specific graphics API. This takes precedence over what
+ // the widgets themselves declare. This is global, applying to all
+ // top-levels.
+ if (QBackingStoreRhiSupport::checkForceRhi(outConfig, outType)) {
+ qCDebug(lcWidgetPainting) << "Tree with root" << w << "evaluated to forced flushing with QRhi";
+ return true;
+ }
+
+ // Otherwise, check the widget hierarchy to see if there is a child (or
+ // ourselves) that declare the need for rhi-based composition.
+ if (q_evaluateRhiConfigRecursive(w, outConfig, outType)) {
+ qCDebug(lcWidgetPainting) << "Tree with root" << w << "evaluates to flushing with QRhi";
+ return true;
+ }
+
+ return false;
+}
+
// ### fixme: Qt 6: Remove parameter window from QWidget::create()
/*!
@@ -1166,11 +1203,6 @@ void QWidget::create(WId window, bool initializeWindow, bool destroyOldWindow)
if (QApplicationPrivate::testAttribute(Qt::AA_NativeWindows))
setAttribute(Qt::WA_NativeWindow);
-#ifdef ALIEN_DEBUG
- qDebug() << "QWidget::create:" << this << "parent:" << parentWidget()
- << "Alien?" << !testAttribute(Qt::WA_NativeWindow);
-#endif
-
d->updateIsOpaque();
setAttribute(Qt::WA_WState_Created); // set created flag
@@ -1269,7 +1301,6 @@ void QWidgetPrivate::create()
win->setProperty("_q_showWithoutActivating", QVariant(true));
if (q->testAttribute(Qt::WA_MacAlwaysShowToolWindow))
win->setProperty("_q_macAlwaysShowToolWindow", QVariant(true));
- setNetWmWindowTypes(true); // do nothing if none of WA_X11NetWmWindowType* is set
win->setFlags(flags);
fixPosIncludesFrame();
if (q->testAttribute(Qt::WA_Moved)
@@ -1317,8 +1348,6 @@ void QWidgetPrivate::create()
}
data.window_flags = win->flags();
- if (!win->isTopLevel()) // In a Widget world foreign windows can only be top level
- data.window_flags &= ~Qt::ForeignWindow;
#if QT_CONFIG(xcb)
if (!topData()->role.isNull()) {
@@ -1328,14 +1357,21 @@ void QWidgetPrivate::create()
#endif
QBackingStore *store = q->backingStore();
+ usesRhiFlush = false;
if (!store) {
if (q->windowType() != Qt::Desktop) {
- if (q->isWindow())
+ if (q->isWindow()) {
q->setBackingStore(new QBackingStore(win));
+ QPlatformBackingStoreRhiConfig rhiConfig;
+ usesRhiFlush = q_evaluateRhiConfig(q, &rhiConfig, nullptr);
+ topData()->backingStore->handle()->setRhiConfig(rhiConfig);
+ }
} else {
q->setAttribute(Qt::WA_PaintOnScreen, true);
}
+ } else if (win->handle()) {
+ usesRhiFlush = q_evaluateRhiConfig(q, nullptr, nullptr);
}
setWindowModified_helper();
@@ -1346,6 +1382,7 @@ void QWidgetPrivate::create()
Q_ASSERT(id != WId(0));
setWinId(id);
}
+ setNetWmWindowTypes(true); // do nothing if none of WA_X11NetWmWindowType* is set
// Check children and create windows for them if necessary
q_createNativeChildrenAndSetParent(q);
@@ -1389,6 +1426,8 @@ void QWidgetPrivate::createTLSysExtra()
#endif
if (isTipLabel || isAlphaWidget || q->inherits("QRollEffect"))
qt_window_private(extra->topextra->window)->setAutomaticPositionAndResizeEnabled(false);
+
+ updateIsTranslucent();
}
}
@@ -1421,7 +1460,7 @@ QWidget::~QWidget()
#ifndef QT_NO_ACTION
// remove all actions from this widget
- for (auto action : qAsConst(d->actions)) {
+ for (auto action : std::as_const(d->actions)) {
QActionPrivate *apriv = action->d_func();
apriv->associatedObjects.removeAll(this);
}
@@ -1541,6 +1580,8 @@ QWidget::~QWidget()
#if QT_CONFIG(graphicseffect)
delete d->graphicsEffect;
#endif
+
+ d->isWidget = false;
}
int QWidgetPrivate::instanceCounter = 0; // Current number of widget instances
@@ -1646,10 +1687,9 @@ void QWidgetPrivate::deleteExtra()
if (QStyleSheetStyle *proxy = qt_styleSheet(extra->style))
proxy->deref();
#endif
- if (extra->topextra) {
+ if (extra->topextra)
deleteTLSysExtra();
- // extra->topextra->backingStore destroyed in QWidgetPrivate::deleteTLSysExtra()
- }
+
// extra->xic destroyed in QWidget::destroy()
extra.reset();
}
@@ -1659,37 +1699,11 @@ void QWidgetPrivate::deleteSysExtra()
{
}
-static void deleteBackingStore(QWidgetPrivate *d)
-{
- QTLWExtra *topData = d->topData();
-
- delete topData->backingStore;
- topData->backingStore = nullptr;
-}
-
void QWidgetPrivate::deleteTLSysExtra()
{
if (extra && extra->topextra) {
- //the qplatformbackingstore may hold a reference to the window, so the backingstore
- //needs to be deleted first.
-
- extra->topextra->repaintManager.reset(nullptr);
- deleteBackingStore(this);
-#ifndef QT_NO_OPENGL
- extra->topextra->widgetTextures.clear();
- extra->topextra->shareContext.reset();
-#endif
-
- //the toplevel might have a context with a "qglcontext associated with it. We need to
- //delete the qglcontext before we delete the qplatformopenglcontext.
- //One unfortunate thing about this is that we potentially create a glContext just to
- //delete it straight afterwards.
- if (extra->topextra->window) {
- extra->topextra->window->destroy();
- }
delete extra->topextra->window;
extra->topextra->window = nullptr;
-
}
}
@@ -2191,7 +2205,7 @@ void QWidgetPrivate::updateIsTranslucent()
if (QWindow *window = q->windowHandle()) {
QSurfaceFormat format = window->format();
const int oldAlpha = format.alphaBufferSize();
- const int newAlpha = q->testAttribute(Qt::WA_TranslucentBackground)? 8 : 0;
+ const int newAlpha = q->testAttribute(Qt::WA_TranslucentBackground) ? 8 : -1;
if (oldAlpha != newAlpha) {
// QTBUG-85714: Do this only when the QWindow has not yet been create()'ed yet.
//
@@ -2305,7 +2319,7 @@ void QWidgetPrivate::deactivateWidgetCleanup()
Q_Q(QWidget);
// If this was the active application window, reset it
if (QApplication::activeWindow() == q)
- QApplication::setActiveWindow(nullptr);
+ QApplicationPrivate::setActiveWindow(nullptr);
// If the is the active mouse press widget, reset it
if (q == qt_button_down)
qt_button_down = nullptr;
@@ -2313,7 +2327,7 @@ void QWidgetPrivate::deactivateWidgetCleanup()
/*!
- Returns a pointer to the widget with window identifer/handle \a
+ Returns a pointer to the widget with window identifier/handle \a
id.
The window identifier type depends on the underlying window
@@ -2356,9 +2370,6 @@ WId QWidget::winId() const
if (!data->in_destructor
&& (!testAttribute(Qt::WA_WState_Created) || !internalWinId()))
{
-#ifdef ALIEN_DEBUG
- qDebug() << "QWidget::winId: creating native window for" << this;
-#endif
QWidget *that = const_cast<QWidget*>(this);
that->setAttribute(Qt::WA_NativeWindow);
that->d_func()->createWinId();
@@ -2371,9 +2382,6 @@ void QWidgetPrivate::createWinId()
{
Q_Q(QWidget);
-#ifdef ALIEN_DEBUG
- qDebug() << "QWidgetPrivate::createWinId for" << q;
-#endif
const bool forceNativeWindow = q->testAttribute(Qt::WA_NativeWindow);
if (!q->testAttribute(Qt::WA_WState_Created) || (forceNativeWindow && !q->internalWinId())) {
if (!q->isWindow()) {
@@ -2444,10 +2452,6 @@ Ensures that the widget has a window system identifier, i.e. that it is known to
void QWidget::createWinId()
{
Q_D(QWidget);
-#ifdef ALIEN_DEBUG
- qDebug() << "QWidget::createWinId" << this;
-#endif
-// qWarning("QWidget::createWinId is obsolete, please fix your code.");
d->createWinId();
}
@@ -2642,7 +2646,7 @@ void QWidget::setStyle(QStyle *style)
#ifndef QT_NO_STYLE_STYLESHEET
if (QStyleSheetStyle *styleSheetStyle = qt_styleSheet(style)) {
//if for some reason someone try to set a QStyleSheetStyle, ref it
- //(this may happen for exemple in QButtonDialogBox which propagates its style)
+ //(this may happen for example in QButtonDialogBox which propagates its style)
styleSheetStyle->ref();
d->setStyle_helper(style, false);
} else if (qt_styleSheet(d->extra->style) || !qApp->styleSheet().isEmpty()) {
@@ -2925,7 +2929,7 @@ void QWidget::overrideWindowState(Qt::WindowStates newstate)
\snippet code/src_gui_kernel_qwidget.cpp 0
- In order to restore and activate a minimized window (while
+ To restore and activate a minimized window (while
preserving its maximized and/or full-screen state), use the following:
\snippet code/src_gui_kernel_qwidget.cpp 1
@@ -3001,7 +3005,7 @@ bool QWidget::isFullScreen() const
ICCCM protocol that specifies the communication between X11
clients and the window manager. ICCCM simply does not understand
the concept of non-decorated full-screen windows. Therefore, the
- best we can do is to request a borderless window and place and
+ best you can do is to request a borderless window and place and
resize it to fill the entire screen. Depending on the window
manager, this may or may not work. The borderless window is
requested using MOTIF hints, which are at least partially
@@ -3009,7 +3013,7 @@ bool QWidget::isFullScreen() const
An alternative would be to bypass the window manager entirely and
create a window with the Qt::X11BypassWindowManagerHint flag. This
- has other severe problems though, like totally broken keyboard focus
+ has other severe problems though, like broken keyboard focus
and very strange effects on desktop changes or when the user raises
other windows.
@@ -3109,7 +3113,7 @@ bool QWidget::isEnabledTo(const QWidget *ancestor) const
/*!
Appends the action \a action to this widget's list of actions.
- All QWidgets have a list of \l{QAction}s, however they can be
+ All QWidgets have a list of \l{QAction}s. However, they can be
represented graphically in many different ways. The default use of
the QAction list (as returned by actions()) is to create a context
QMenu.
@@ -3133,7 +3137,7 @@ void QWidget::addAction(QAction *action)
*/
void QWidget::addActions(const QList<QAction *> &actions)
{
- for(int i = 0; i < actions.count(); i++)
+ for(int i = 0; i < actions.size(); i++)
insertAction(nullptr, actions.at(i));
}
@@ -3182,7 +3186,7 @@ void QWidget::insertAction(QAction *before, QAction *action)
*/
void QWidget::insertActions(QAction *before, const QList<QAction*> &actions)
{
- for(int i = 0; i < actions.count(); ++i)
+ for(int i = 0; i < actions.size(); ++i)
insertAction(before, actions.at(i));
}
@@ -3247,6 +3251,7 @@ QAction *QWidget::addAction(const QIcon &icon, const QString &text)
return ret;
}
+#if QT_CONFIG(shortcut)
QAction *QWidget::addAction(const QString &text, const QKeySequence &shortcut)
{
QAction *ret = addAction(text);
@@ -3260,6 +3265,7 @@ QAction *QWidget::addAction(const QIcon &icon, const QString &text, const QKeySe
ret->setShortcut(shortcut);
return ret;
}
+#endif
/*!
\fn QAction *QWidget::addAction(const QString &text, const QObject *receiver, const char* member, Qt::ConnectionType type)
@@ -3317,10 +3323,10 @@ QAction *QWidget::addAction(const QIcon &icon, const QString &text, const QKeySe
#endif // QT_CONFIG(shortcut)
/*!
- \fn template<typename...Args> QAction *QWidget::addAction(const QString &text, Args&&...args)
- \fn template<typename...Args> QAction *QWidget::addAction(const QString &text, const QKeySequence &shortcut, Args&&...args)
- \fn template<typename...Args> QAction *QWidget::addAction(const QIcon &icon, const QString &text, Args&&...args)
- \fn template<typename...Args> QAction *QWidget::addAction(const QIcon &icon, const QString &text, const QKeySequence &shortcut, Args&&...args)
+ \fn template<typename...Args, typename = compatible_action_slot_args<Args...>> QAction *QWidget::addAction(const QString &text, Args&&...args)
+ \fn template<typename...Args, typename = compatible_action_slot_args<Args...>> QAction *QWidget::addAction(const QString &text, const QKeySequence &shortcut, Args&&...args)
+ \fn template<typename...Args, typename = compatible_action_slot_args<Args...>> QAction *QWidget::addAction(const QIcon &icon, const QString &text, Args&&...args)
+ \fn template<typename...Args, typename = compatible_action_slot_args<Args...>> QAction *QWidget::addAction(const QIcon &icon, const QString &text, const QKeySequence &shortcut, Args&&...args)
\since 6.3
\overload
@@ -3431,7 +3437,7 @@ void QWidgetPrivate::setEnabled_helper(bool enable)
By default, this property is \c false.
- \sa {Drag and Drop}
+ \sa {Drag and Drop in Qt}{Drag and Drop}
*/
bool QWidget::acceptDrops() const
{
@@ -3545,6 +3551,10 @@ int QWidget::y() const
See the \l{Window Geometry} documentation for an overview of geometry
issues with windows.
+ \note Not all windowing systems support setting or querying top level window positions.
+ On such a system, programmatically moving windows may not have any effect, and artificial
+ values may be returned for the current positions, such as \c QPoint(0, 0).
+
\sa frameGeometry, size, x(), y()
*/
QPoint QWidget::pos() const
@@ -3584,19 +3594,6 @@ QPoint QWidget::pos() const
*/
/*!
- \property QWidget::normalGeometry
-
- \brief the geometry of the widget as it will appear when shown as
- a normal (not maximized or full screen) top-level widget
-
- For child widgets this property always holds an empty rectangle.
-
- By default, this property contains an empty rectangle.
-
- \sa QWidget::windowState(), QWidget::geometry
-*/
-
-/*!
\property QWidget::size
\brief the size of the widget excluding any window frame
@@ -3664,11 +3661,25 @@ QPoint QWidget::pos() const
\sa size
*/
+/*!
+ \property QWidget::normalGeometry
+ \brief the geometry of the widget as it will appear when shown as
+ a normal (not maximized or full screen) top-level widget
+
+ If the widget is already in this state the normal geometry will
+ reflect the widget's current geometry().
+
+ For child widgets this property always holds an empty rectangle.
+
+ By default, this property contains an empty rectangle.
+
+ \sa QWidget::windowState(), QWidget::geometry
+*/
QRect QWidget::normalGeometry() const
{
Q_D(const QWidget);
- if (!d->extra || !d->extra->topextra)
+ if (!isWindow())
return QRect();
if (!isMaximized() && !isFullScreen())
@@ -3741,7 +3752,7 @@ QRegion QWidget::childrenRegion() const
the current size is smaller.
The minimum size set by this function will override the minimum size
- defined by QLayout. In order to unset the minimum size, use a
+ defined by QLayout. To unset the minimum size, use a
value of \c{QSize(0, 0)}.
By default, this property contains a size with zero width and height.
@@ -4352,7 +4363,7 @@ QWidget *QWidget::nativeParentWidget() const
The background role defines the brush from the widget's \l palette that
is used to render the background.
- If no explicit background role is set, the widget inherts its parent
+ If no explicit background role is set, the widget inherits its parent
widget's background role.
\sa setBackgroundRole(), foregroundRole()
@@ -4496,7 +4507,7 @@ void QWidget::setForegroundRole(QPalette::ColorRole role)
QWidget's palette propagation is similar to its font propagation.
The current style, which is used to render the content of all standard Qt
- widgets, is free to choose colors and brushes from the widget palette, or
+ widgets, is free to choose colors and brushes from the widget palette, or,
in some cases, to ignore the palette (partially, or completely). In
particular, certain styles like GTK style, Mac style, and Windows Vista
style, depend on third party APIs to render the content of widgets,
@@ -5462,10 +5473,11 @@ void QWidgetPrivate::drawWidget(QPaintDevice *pdev, const QRegion &rgn, const QP
QWidgetEffectSourcePrivate *sourced = static_cast<QWidgetEffectSourcePrivate *>
(source->d_func());
if (!sourced->context) {
- QWidgetPaintContext context(pdev, rgn, offset, flags, sharedPainter, repaintManager);
+ const QRegion effectRgn((flags & UseEffectRegionBounds) ? rgn.boundingRect() : rgn);
+ QWidgetPaintContext context(pdev, effectRgn, offset, flags, sharedPainter, repaintManager);
sourced->context = &context;
if (!sharedPainter) {
- setSystemClip(pdev->paintEngine(), pdev->devicePixelRatio(), rgn.translated(offset));
+ setSystemClip(pdev->paintEngine(), pdev->devicePixelRatio(), effectRgn.translated(offset));
QPainter p(pdev);
p.translate(offset);
context.painter = &p;
@@ -5479,7 +5491,7 @@ void QWidgetPrivate::drawWidget(QPaintDevice *pdev, const QRegion &rgn, const QP
}
sharedPainter->save();
sharedPainter->translate(offset);
- setSystemClip(sharedPainter->paintEngine(), sharedPainter->device()->devicePixelRatio(), rgn.translated(offset));
+ setSystemClip(sharedPainter->paintEngine(), sharedPainter->device()->devicePixelRatio(), effectRgn.translated(offset));
graphicsEffect->draw(sharedPainter);
setSystemClip(sharedPainter->paintEngine(), 1, QRegion());
sharedPainter->restore();
@@ -5487,12 +5499,13 @@ void QWidgetPrivate::drawWidget(QPaintDevice *pdev, const QRegion &rgn, const QP
sourced->context = nullptr;
if (repaintManager)
- repaintManager->markNeedsFlush(q, rgn, offset);
+ repaintManager->markNeedsFlush(q, effectRgn, offset);
return;
}
}
#endif // QT_CONFIG(graphicseffect)
+ flags = flags & ~UseEffectRegionBounds;
const bool alsoOnScreen = flags & DrawPaintOnScreen;
const bool recursive = flags & DrawRecursive;
@@ -5526,30 +5539,23 @@ void QWidgetPrivate::drawWidget(QPaintDevice *pdev, const QRegion &rgn, const QP
//paint the background
if ((asRoot || q->autoFillBackground() || onScreen || q->testAttribute(Qt::WA_StyledBackground))
&& !q->testAttribute(Qt::WA_OpaquePaintEvent) && !q->testAttribute(Qt::WA_NoSystemBackground)) {
-#ifndef QT_NO_OPENGL
beginBackingStorePainting();
-#endif
QPainter p(q);
+ p.setRenderHint(QPainter::SmoothPixmapTransform);
paintBackground(&p, toBePainted, (asRoot || onScreen) ? (flags | DrawAsRoot) : DrawWidgetFlags());
-#ifndef QT_NO_OPENGL
endBackingStorePainting();
-#endif
}
if (!sharedPainter)
setSystemClip(pdev->paintEngine(), pdev->devicePixelRatio(), toBePainted.translated(offset));
if (!onScreen && !asRoot && !isOpaque && q->testAttribute(Qt::WA_TintedBackground)) {
-#ifndef QT_NO_OPENGL
beginBackingStorePainting();
-#endif
QPainter p(q);
QColor tint = q->palette().window().color();
tint.setAlphaF(.6f);
p.fillRect(toBePainted.boundingRect(), tint);
-#ifndef QT_NO_OPENGL
endBackingStorePainting();
-#endif
}
}
@@ -5560,7 +5566,6 @@ void QWidgetPrivate::drawWidget(QPaintDevice *pdev, const QRegion &rgn, const QP
#endif
bool skipPaintEvent = false;
-#ifndef QT_NO_OPENGL
if (renderToTexture) {
// This widget renders into a texture which is composed later. We just need to
// punch a hole in the backingstore, so the texture will be visible.
@@ -5586,7 +5591,6 @@ void QWidgetPrivate::drawWidget(QPaintDevice *pdev, const QRegion &rgn, const QP
else
skipPaintEvent = true;
}
-#endif // QT_NO_OPENGL
if (!skipPaintEvent) {
//actually send the paint event
@@ -5642,10 +5646,8 @@ void QWidgetPrivate::sendPaintEvent(const QRegion &toBePainted)
QPaintEvent e(toBePainted);
QCoreApplication::sendSpontaneousEvent(q, &e);
-#ifndef QT_NO_OPENGL
if (renderToTexture)
resolveSamples();
-#endif // QT_NO_OPENGL
}
void QWidgetPrivate::render(QPaintDevice *target, const QPoint &targetOffset,
@@ -5979,7 +5981,7 @@ QString QWidget::windowTitle() const
if (!d->extra->topextra->caption.isEmpty())
return d->extra->topextra->caption;
if (!d->extra->topextra->filePath.isEmpty())
- return QFileInfo(d->extra->topextra->filePath).fileName() + QLatin1String("[*]");
+ return QFileInfo(d->extra->topextra->filePath).fileName() + "[*]"_L1;
}
return QString();
}
@@ -6003,7 +6005,7 @@ QString qt_setWindowTitle_helperHelper(const QString &title, const QWidget *widg
if (cap.isEmpty())
return cap;
- QLatin1String placeHolder("[*]");
+ const auto placeHolder = "[*]"_L1;
int index = cap.indexOf(placeHolder);
// here the magic begins
@@ -6027,7 +6029,7 @@ QString qt_setWindowTitle_helperHelper(const QString &title, const QWidget *widg
index = cap.indexOf(placeHolder, index);
}
- cap.replace(QLatin1String("[*][*]"), placeHolder);
+ cap.replace("[*][*]"_L1, placeHolder);
return cap;
}
@@ -6389,6 +6391,57 @@ void QWidget::setFocusProxy(QWidget * w)
d->createExtra();
d->extra->focus_proxy = w;
+ if (w && isAncestorOf(w)) {
+ // If the focus proxy is a child of this (so this is a compound widget), then
+ // we need to make sure that this widget is immediately in front of its own children
+ // in the focus chain. Otherwise focusNextPrev_helper might jump over unrelated
+ // widgets that are positioned between this compound widget, and its proxy in
+ // the focus chain.
+ const QWidget *parentOfW = w->parentWidget();
+ Q_ASSERT(parentOfW); // can't be nullptr since we are an ancestor of w
+ QWidget *firstChild = nullptr;
+ const auto childList = children();
+ for (QObject *child : childList) {
+ if ((firstChild = qobject_cast<QWidget *>(child)))
+ break;
+ }
+ Q_ASSERT(firstChild); // can't be nullptr since w is a child
+ QWidget *oldNext = d->focus_next;
+ QWidget *oldPrev = d->focus_prev;
+ oldNext->d_func()->focus_prev = oldPrev;
+ oldPrev->d_func()->focus_next = oldNext;
+
+ oldPrev = firstChild->d_func()->focus_prev;
+ d->focus_next = firstChild;
+ d->focus_prev = oldPrev;
+ oldPrev->d_func()->focus_next = this;
+ firstChild->d_func()->focus_prev = this;
+ } else if (w && w->isAncestorOf(this)) {
+ // If the focus proxy is a parent, 'this' has to be inserted directly after its parent in the focus chain
+ // remove it from the chain and insert this into the focus chain after its parent
+
+ // is this the case already?
+ QWidget *parentsNext = w->d_func()->focus_next;
+ if (parentsNext == this) {
+ // nothing to do.
+ Q_ASSERT(d->focus_prev == w);
+ } else {
+ // Remove 'this' from the focus chain by making prev and next point directly to each other
+ QWidget *myOldNext = d->focus_next;
+ QWidget *myOldPrev = d->focus_prev;
+ if (myOldNext && myOldPrev) {
+ myOldNext->d_func()->focus_prev = myOldPrev;
+ myOldPrev->d_func()->focus_next = myOldNext;
+ }
+
+ // Insert 'this' behind the parent
+ w->d_func()->focus_next = this;
+ d->focus_prev = w;
+ d->focus_next = parentsNext;
+ parentsNext->d_func()->focus_prev = this;
+ }
+ }
+
if (moveFocusToProxy)
setFocus(Qt::OtherFocusReason);
}
@@ -6523,7 +6576,7 @@ void QWidget::setFocus(Qt::FocusReason reason)
f->d_func()->updateFocusChild();
QApplicationPrivate::setFocusWidget(f, reason);
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
// menus update the focus manually and this would create bogus events
if (!(f->inherits("QMenuBar") || f->inherits("QMenu") || f->inherits("QMenuItem")))
{
@@ -6647,8 +6700,8 @@ void QWidgetPrivate::updateFocusChild()
If the widget has active focus, a \l{focusOutEvent()}{focus out event} is sent to this widget to tell it that it has
lost the focus.
- This widget must enable focus setting in order to get the keyboard
- input focus, i.e. it must call setFocusPolicy().
+ This widget must enable focus setting to get the keyboard
+ input focus; that is, it must call setFocusPolicy().
\sa hasFocus(), setFocus(), focusInEvent(), focusOutEvent(),
setFocusPolicy(), QApplication::focusWidget()
@@ -6665,7 +6718,14 @@ void QWidget::clearFocus()
}
QTLWExtra *extra = window()->d_func()->maybeTopData();
- QObject *originalFocusObject = (extra && extra->window) ? extra->window->focusObject() : nullptr;
+ QObject *originalFocusObject = nullptr;
+ if (extra && extra->window) {
+ originalFocusObject = extra->window->focusObject();
+ // the window's focus object might already be nullptr if we are in the destructor, but we still
+ // need to update QGuiApplication and input context if we have a focus widget.
+ if (!originalFocusObject)
+ originalFocusObject = focusWidget();
+ }
QWidget *w = this;
while (w) {
@@ -6691,7 +6751,7 @@ void QWidget::clearFocus()
if (hasFocus()) {
// Update proxy state
QApplicationPrivate::setFocusWidget(nullptr, Qt::OtherFocusReason);
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
QAccessibleEvent event(this, QAccessible::Focus);
QAccessible::updateAccessibility(&event);
#endif
@@ -6797,6 +6857,13 @@ QWidget *QWidget::focusWidget() const
return const_cast<QWidget *>(d_func()->focus_child);
}
+QObject *QWidgetPrivate::focusObject()
+{
+ Q_Q(QWidget);
+ QWidget *proxy = deepestFocusProxy();
+ return proxy ? proxy : q;
+}
+
/*!
Returns the next widget in this widget's focus chain.
@@ -6887,6 +6954,30 @@ bool QWidget::isActiveWindow() const
}
/*!
+ \fn void QWidget::setTabOrder(std::initializer_list<QWidget *> widgets)
+ \overload
+ \since 6.6
+
+ Sets the tab order for the widgets in the \a widgets list by calling
+ \l{QWidget::setTabOrder(QWidget *, QWidget *)} for each consecutive
+ pair of widgets.
+
+ Instead of setting up each pair manually like this:
+
+ \snippet code/src_gui_kernel_qwidget.cpp 9
+
+ you can call:
+
+ \snippet code/src_gui_kernel_qwidget.cpp 9.list
+
+ The call does not create a closed tab focus loop. If there are more widgets
+ with \l{Qt::TabFocus} focus policy, tabbing on \c{d} will move focus to one
+ of those widgets, not back to \c{a}.
+
+ \sa setFocusPolicy(), setFocusProxy(), {Keyboard Focus in Widgets}
+*/
+
+/*!
Puts the \a second widget after the \a first widget in the focus order.
It effectively removes the \a second widget from its focus chain and
@@ -6924,16 +7015,16 @@ void QWidget::setTabOrder(QWidget* first, QWidget *second)
return;
}
- auto determineLastFocusChild = [](QWidget *target, QWidget *&lastFocusChild)
+ const auto determineLastFocusChild = [](QWidget *target, QWidget *noFurtherThan)
{
// Since we need to repeat the same logic for both 'first' and 'second', we add a function that
// determines the last focus child for a widget, taking proxies and compound widgets into account.
// If the target is not a compound widget (it doesn't have a focus proxy that points to a child),
// 'lastFocusChild' will be set to the target itself.
- lastFocusChild = target;
+ QWidget *lastFocusChild = target;
QWidget *focusProxy = target->d_func()->deepestFocusProxy();
- if (!focusProxy || !target->isAncestorOf(focusProxy)) {
+ if (!focusProxy) {
// QTBUG-81097: Another case is possible here. We can have a child
// widget, that sets its focusProxy() to the parent (target).
// An example of such widget is a QLineEdit, nested into
@@ -6946,30 +7037,35 @@ void QWidget::setTabOrder(QWidget* first, QWidget *second)
break;
}
}
- return;
- }
-
- lastFocusChild = focusProxy;
-
- for (QWidget *focusNext = lastFocusChild->d_func()->focus_next;
- focusNext != focusProxy && target->isAncestorOf(focusNext) && focusNext->window() == focusProxy->window();
- focusNext = focusNext->d_func()->focus_next) {
- if (focusNext->focusPolicy() != Qt::NoFocus)
- lastFocusChild = focusNext;
+ } else if (target->isAncestorOf(focusProxy)) {
+ lastFocusChild = focusProxy;
+ for (QWidget *focusNext = lastFocusChild->d_func()->focus_next;
+ focusNext != focusProxy && target->isAncestorOf(focusNext) && focusNext->window() == focusProxy->window();
+ focusNext = focusNext->d_func()->focus_next) {
+ if (focusNext == noFurtherThan)
+ break;
+ if (focusNext->focusPolicy() != Qt::NoFocus)
+ lastFocusChild = focusNext;
+ }
}
+ return lastFocusChild;
};
- auto setPrev = [](QWidget *w, QWidget *prev)
- {
+ auto setPrev = [](QWidget *w, QWidget *prev) {
w->d_func()->focus_prev = prev;
};
- auto setNext = [](QWidget *w, QWidget *next)
- {
+ auto setNext = [](QWidget *w, QWidget *next) {
w->d_func()->focus_next = next;
};
+ // detect inflection in case we have compound widgets
+ QWidget *lastFocusChildOfFirst = determineLastFocusChild(first, second);
+ if (lastFocusChildOfFirst == second)
+ lastFocusChildOfFirst = first;
+ QWidget *lastFocusChildOfSecond = determineLastFocusChild(second, first);
+ if (lastFocusChildOfSecond == first)
+ lastFocusChildOfSecond = second;
+
// remove the second widget from the chain
- QWidget *lastFocusChildOfSecond;
- determineLastFocusChild(second, lastFocusChildOfSecond);
{
QWidget *oldPrev = second->d_func()->focus_prev;
QWidget *prevWithFocus = oldPrev;
@@ -6984,8 +7080,6 @@ void QWidget::setTabOrder(QWidget* first, QWidget *second)
}
// insert the second widget into the chain
- QWidget *lastFocusChildOfFirst;
- determineLastFocusChild(first, lastFocusChildOfFirst);
{
QWidget *oldNext = lastFocusChildOfFirst->d_func()->focus_next;
setPrev(second, lastFocusChildOfFirst);
@@ -6995,6 +7089,20 @@ void QWidget::setTabOrder(QWidget* first, QWidget *second)
}
}
+void QWidget::setTabOrder(std::initializer_list<QWidget *> widgets)
+{
+ QWidget *prev = nullptr;
+ for (const auto &widget : widgets) {
+ if (!prev) {
+ prev = widget;
+ } else {
+ QWidget::setTabOrder(prev, widget);
+ prev = widget;
+ }
+ }
+}
+
+
/*!\internal
Moves the relevant subwidgets of this widget from the \a oldtlw's
@@ -7073,8 +7181,8 @@ void QWidgetPrivate::reparentFocusWidgets(QWidget * oldtlw)
n->d_func()->focus_next = topLevel;
} else {
//repair the new list
- n->d_func()->focus_next = q;
- focus_prev = n;
+ n->d_func()->focus_next = q;
+ focus_prev = n;
}
}
@@ -7356,15 +7464,67 @@ QByteArray QWidget::saveGeometry() const
return array;
}
-static void checkRestoredGeometry(const QRect &availableGeometry, QRect *restoredGeometry,
+/*!
+ \internal
+
+ Check a if \a restoredGeometry fits into \a availableGeometry
+ This method is used to verify that a widget is restored to a geometry, which
+ fits into the target screen.
+
+ \param frameHeight represents the height of the widget's title bar, which is expected
+ to be on its top.
+
+ If the size of \a restoredGeometry exceeds \a availableGeometry, its height and width
+ will be resized to be two pixels smaller than \a availableGeometry. An exact match would
+ be full screen.
+
+ If at least one edge of \a restoredGeometry is outside \a availableGeometry,
+ \a restoredGeometry will be moved
+ \list
+ \li down if its top is off screen
+ \li up if its bottom is off screen
+ \li right if its left edge is off screen
+ \li left if its right edge is off screen
+ \endlist
+ */
+void QWidgetPrivate::checkRestoredGeometry(const QRect &availableGeometry, QRect *restoredGeometry,
int frameHeight)
{
- if (!restoredGeometry->intersects(availableGeometry)) {
- restoredGeometry->moveBottom(qMin(restoredGeometry->bottom(), availableGeometry.bottom()));
- restoredGeometry->moveLeft(qMax(restoredGeometry->left(), availableGeometry.left()));
- restoredGeometry->moveRight(qMin(restoredGeometry->right(), availableGeometry.right()));
+ // compare with restored geometry's height increased by frameHeight
+ const int height = restoredGeometry->height() + frameHeight;
+
+ // Step 1: Resize if necessary:
+ // make height / width 2px smaller than screen, because an exact match would be fullscreen
+ if (availableGeometry.height() <= height)
+ restoredGeometry->setHeight(availableGeometry.height() - 2 - frameHeight);
+ if (availableGeometry.width() <= restoredGeometry->width())
+ restoredGeometry->setWidth(availableGeometry.width() - 2);
+
+ // Step 2: Move if necessary:
+ // Construct a rectangle from restored Geometry adjusted by frameHeight
+ const QRect restored = restoredGeometry->adjusted(0, -frameHeight, 0, 0);
+
+ // Return if restoredGeometry (including frame) fits into screen
+ if (availableGeometry.contains(restored))
+ return;
+
+ // (size is correct, but at least one edge is off screen)
+
+ // Top out of bounds => move down
+ if (restored.top() <= availableGeometry.top()) {
+ restoredGeometry->moveTop(availableGeometry.top() + 1 + frameHeight);
+ } else if (restored.bottom() >= availableGeometry.bottom()) {
+ // Bottom out of bounds => move up
+ restoredGeometry->moveBottom(availableGeometry.bottom() - 1);
+ }
+
+ // Left edge out of bounds => move right
+ if (restored.left() <= availableGeometry.left()) {
+ restoredGeometry->moveLeft(availableGeometry.left() + 1);
+ } else if (restored.right() >= availableGeometry.right()) {
+ // Right edge out of bounds => move left
+ restoredGeometry->moveRight(availableGeometry.right() - 1);
}
- restoredGeometry->moveTop(qMax(restoredGeometry->top(), availableGeometry.top() + frameHeight));
}
/*!
@@ -7451,7 +7611,9 @@ bool QWidget::restoreGeometry(const QByteArray &geometry)
return false;
}
- const int frameHeight = 20;
+ const int frameHeight = QApplication::style()
+ ? QApplication::style()->pixelMetric(QStyle::PM_TitleBarHeight, nullptr, this)
+ : 20;
if (!restoredNormalGeometry.isValid())
restoredNormalGeometry = QRect(QPoint(0, frameHeight), sizeHint());
@@ -7467,11 +7629,11 @@ bool QWidget::restoreGeometry(const QByteArray &geometry)
// Modify the restored geometry if we are about to restore to coordinates
// that would make the window "lost". This happens if:
- // - The restored geometry is completely oustside the available geometry
+ // - The restored geometry is completely or partly oustside the available geometry
// - The title bar is outside the available geometry.
- checkRestoredGeometry(availableGeometry, &restoredGeometry, frameHeight);
- checkRestoredGeometry(availableGeometry, &restoredNormalGeometry, frameHeight);
+ QWidgetPrivate::checkRestoredGeometry(availableGeometry, &restoredGeometry, frameHeight);
+ QWidgetPrivate::checkRestoredGeometry(availableGeometry, &restoredNormalGeometry, frameHeight);
if (maximized || fullScreen) {
// set geometry before setting the window state to make
@@ -7503,6 +7665,8 @@ bool QWidget::restoreGeometry(const QByteArray &geometry)
d_func()->topData()->normalGeometry = restoredNormalGeometry;
} else {
setWindowState(windowState() & ~(Qt::WindowMaximized | Qt::WindowFullScreen));
+
+ // FIXME: Why fall back to restoredNormalGeometry if majorVersion <= 2?
if (majorVersion > 2)
setGeometry(restoredGeometry);
else
@@ -7801,21 +7965,29 @@ void QWidget::setUpdatesEnabled(bool enable)
/*!
Shows the widget and its child widgets.
- This is equivalent to calling showFullScreen(), showMaximized(), or setVisible(true),
- depending on the platform's default behavior for the window flags.
+ For child windows, this is equivalent to calling setVisible(true).
+ Otherwise, it is equivalent to calling showFullScreen(), showMaximized(),
+ or setVisible(true), depending on the platform's default behavior for the window flags.
- \sa raise(), showEvent(), hide(), setVisible(), showMinimized(), showMaximized(),
+ \sa raise(), showEvent(), hide(), setVisible(), showMinimized(), showMaximized(),
showNormal(), isVisible(), windowFlags()
*/
void QWidget::show()
{
- Qt::WindowState defaultState = QGuiApplicationPrivate::platformIntegration()->defaultWindowState(data->window_flags);
- if (defaultState == Qt::WindowFullScreen)
- showFullScreen();
- else if (defaultState == Qt::WindowMaximized)
- showMaximized();
- else
- setVisible(true); // Don't call showNormal() as not to clobber Qt::Window(Max/Min)imized
+ // Note: We don't call showNormal() as not to clobber Qt::Window(Max/Min)imized
+
+ if (!isWindow()) {
+ setVisible(true);
+ } else {
+ const auto *platformIntegration = QGuiApplicationPrivate::platformIntegration();
+ Qt::WindowState defaultState = platformIntegration->defaultWindowState(data->window_flags);
+ if (defaultState == Qt::WindowFullScreen)
+ showFullScreen();
+ else if (defaultState == Qt::WindowMaximized)
+ showMaximized();
+ else
+ setVisible(true);
+ }
}
/*! \internal
@@ -7966,7 +8138,7 @@ void QWidgetPrivate::show_helper()
if (!isEmbedded && q->windowType() == Qt::Popup)
qApp->d_func()->openPopup(q);
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
if (q->windowType() != Qt::ToolTip) { // Tooltips are read aloud twice in MS narrator.
QAccessibleEvent event(q, QAccessible::ObjectShow);
QAccessible::updateAccessibility(&event);
@@ -8112,7 +8284,7 @@ void QWidgetPrivate::hide_helper()
if (QWidgetRepaintManager *repaintManager = maybeRepaintManager())
repaintManager->removeDirtyWidget(q);
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
if (wasVisible) {
QAccessibleEvent event(q, QAccessible::ObjectHide);
QAccessible::updateAccessibility(&event);
@@ -8182,13 +8354,17 @@ void QWidgetPrivate::hide_sys()
void QWidget::setVisible(bool visible)
{
+ Q_D(QWidget);
+ qCDebug(lcWidgetShowHide) << "Setting visibility of" << this
+ << "with attributes" << WidgetAttributes{this}
+ << "to" << visible << "via QWidget";
+
if (testAttribute(Qt::WA_WState_ExplicitShowHide) && testAttribute(Qt::WA_WState_Hidden) == !visible)
return;
// Remember that setVisible was called explicitly
setAttribute(Qt::WA_WState_ExplicitShowHide);
- Q_D(QWidget);
d->setVisible(visible);
}
@@ -8198,6 +8374,10 @@ void QWidget::setVisible(bool visible)
void QWidgetPrivate::setVisible(bool visible)
{
Q_Q(QWidget);
+ qCDebug(lcWidgetShowHide) << "Setting visibility of" << q
+ << "with attributes" << WidgetAttributes{q}
+ << "to" << visible << "via QWidgetPrivate";
+
if (visible) { // show
// Designer uses a trick to make grabWidget work without showing
if (!q->isWindow() && q->parentWidget() && q->parentWidget()->isVisible()
@@ -8277,8 +8457,7 @@ void QWidgetPrivate::setVisible(bool visible)
if (!q->testAttribute(Qt::WA_WState_Hidden)) {
q->setAttribute(Qt::WA_WState_Hidden);
- if (q->testAttribute(Qt::WA_WState_Created))
- hide_helper();
+ hide_helper();
}
// invalidate layout similar to updateGeometry()
@@ -8302,23 +8481,35 @@ void QWidget::setHidden(bool hidden)
setVisible(!hidden);
}
+bool QWidgetPrivate::isExplicitlyHidden() const
+{
+ Q_Q(const QWidget);
+ return q->isHidden() && q->testAttribute(Qt::WA_WState_ExplicitShowHide);
+}
+
void QWidgetPrivate::_q_showIfNotHidden()
{
Q_Q(QWidget);
- if ( !(q->isHidden() && q->testAttribute(Qt::WA_WState_ExplicitShowHide)) )
+ if (!isExplicitlyHidden())
q->setVisible(true);
}
void QWidgetPrivate::showChildren(bool spontaneous)
{
+ Q_Q(QWidget);
+ qCDebug(lcWidgetShowHide) << "Showing children of" << q
+ << "spontaneously" << spontaneous;
+
QList<QObject*> childList = children;
for (int i = 0; i < childList.size(); ++i) {
QWidget *widget = qobject_cast<QWidget*>(childList.at(i));
- if (widget && widget->windowHandle() && !widget->testAttribute(Qt::WA_WState_ExplicitShowHide))
+ if (!widget)
+ continue;
+ qCDebug(lcWidgetShowHide) << "Considering" << widget
+ << "with attributes" << WidgetAttributes{widget};
+ if (widget->windowHandle() && !widget->testAttribute(Qt::WA_WState_ExplicitShowHide))
widget->setAttribute(Qt::WA_WState_Hidden, false);
- if (!widget
- || widget->isWindow()
- || widget->testAttribute(Qt::WA_WState_Hidden))
+ if (widget->isWindow() || widget->testAttribute(Qt::WA_WState_Hidden))
continue;
if (spontaneous) {
widget->setAttribute(Qt::WA_Mapped);
@@ -8329,17 +8520,25 @@ void QWidgetPrivate::showChildren(bool spontaneous)
if (widget->testAttribute(Qt::WA_WState_ExplicitShowHide))
widget->d_func()->show_recursive();
else
- widget->show();
+ widget->d_func()->setVisible(true);
}
}
}
void QWidgetPrivate::hideChildren(bool spontaneous)
{
+ Q_Q(QWidget);
+ qCDebug(lcWidgetShowHide) << "Hiding children of" << q
+ << "spontaneously" << spontaneous;
+
QList<QObject*> childList = children;
for (int i = 0; i < childList.size(); ++i) {
QWidget *widget = qobject_cast<QWidget*>(childList.at(i));
- if (!widget || widget->isWindow() || widget->testAttribute(Qt::WA_WState_Hidden))
+ if (!widget)
+ continue;
+ qCDebug(lcWidgetShowHide) << "Considering" << widget
+ << "with attributes" << WidgetAttributes{widget};
+ if (widget->isWindow() || widget->testAttribute(Qt::WA_WState_Hidden))
continue;
if (spontaneous)
@@ -8360,13 +8559,21 @@ void QWidgetPrivate::hideChildren(bool spontaneous)
}
}
qApp->d_func()->sendSyntheticEnterLeave(widget);
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
if (!spontaneous) {
QAccessibleEvent event(widget, QAccessible::ObjectHide);
QAccessible::updateAccessibility(&event);
}
#endif
}
+
+ // If the window of this widget is not closed, then the leave event
+ // will eventually handle the widget under mouse use case.
+ // Otherwise, we need to explicitly handle it here.
+ if (QWidget* widgetWindow = q->window();
+ widgetWindow && widgetWindow->data->is_closing) {
+ q->setAttribute(Qt::WA_UnderMouse, false);
+ }
}
/*!
@@ -8389,15 +8596,16 @@ void QWidgetPrivate::hideChildren(bool spontaneous)
*/
bool QWidgetPrivate::handleClose(CloseMode mode)
{
+ Q_Q(QWidget);
+ qCDebug(lcWidgetShowHide) << "Handling close event for" << q;
+
if (data.is_closing)
return true;
// We might not have initiated the close, so update the state now that we know
data.is_closing = true;
- Q_Q(QWidget);
QPointer<QWidget> that = q;
- QPointer<QWidget> parentWidget = (q->parentWidget() && !QObjectPrivate::get(q->parentWidget())->wasDeleted) ? q->parentWidget() : nullptr;
if (data.in_destructor)
mode = CloseNoEvent;
@@ -8443,7 +8651,7 @@ bool QWidgetPrivate::handleClose(CloseMode mode)
is also deleted. A close events is delivered to the widget no
matter if the widget is visible or not.
- The \l QApplication::lastWindowClosed() signal is emitted when the
+ The \l QGuiApplication::lastWindowClosed() signal is emitted when the
last visible primary window (i.e. window with no parent) with the
Qt::WA_QuitOnClose attribute set is closed. By default this
attribute is set for all widgets except transient windows such as
@@ -8466,8 +8674,10 @@ bool QWidgetPrivate::close()
// Close native widgets via QWindow::close() in order to run QWindow
// close code. The QWidget-specific close code in handleClose() will
// in this case be called from the Close event handler in QWidgetWindow.
- if (QWindow *widgetWindow = windowHandle())
- return widgetWindow->close();
+ if (QWindow *widgetWindow = windowHandle()) {
+ if (widgetWindow->isTopLevel())
+ return widgetWindow->close();
+ }
return handleClose(QWidgetPrivate::CloseWithEvent);
}
@@ -8504,7 +8714,7 @@ bool QWidgetPrivate::close()
when the user minimizes the window, and a spontaneous show event
when the window is restored again.
- You almost never have to reimplement the setVisible() function. If
+ You seldom have to reimplement the setVisible() function. If
you need to change some settings before a widget is shown, use
showEvent() instead. If you need to do some delayed initialization
use the Polish event delivered to the event() function.
@@ -8831,7 +9041,7 @@ bool QWidget::event(QEvent *event)
break;
#endif
case QEvent::KeyPress: {
- QKeyEvent *k = (QKeyEvent *)event;
+ QKeyEvent *k = static_cast<QKeyEvent *>(event);
bool res = false;
if (!(k->modifiers() & (Qt::ControlModifier | Qt::AltModifier))) { //### Add MetaModifier?
if (k->key() == Qt::Key_Backtab
@@ -8888,16 +9098,22 @@ bool QWidget::event(QEvent *event)
inputMethodEvent((QInputMethodEvent *) event);
break;
- case QEvent::InputMethodQuery:
- if (testAttribute(Qt::WA_InputMethodEnabled)) {
+ case QEvent::InputMethodQuery: {
QInputMethodQueryEvent *query = static_cast<QInputMethodQueryEvent *>(event);
Qt::InputMethodQueries queries = query->queries();
for (uint i = 0; i < 32; ++i) {
Qt::InputMethodQuery q = (Qt::InputMethodQuery)(int)(queries & (1<<i));
if (q) {
QVariant v = inputMethodQuery(q);
- if (q == Qt::ImEnabled && !v.isValid() && isEnabled())
- v = QVariant(true); // special case for Qt4 compatibility
+ if (q == Qt::ImEnabled && !v.isValid() && isEnabled()) {
+ // Qt:ImEnabled was added in Qt 5.3. So not all widgets support it, even
+ // if they implement IM otherwise (by overriding inputMethodQuery()). Instead
+ // they set the widget attribute Qt::WA_InputMethodEnabled. But this attribute
+ // will only be set if the widget supports IM _and_ is not read-only. So for
+ // read-only widgets, not all IM features will be supported when ImEnabled is
+ // not implemented explicitly (e.g selection handles for read-only widgets on iOS).
+ v = QVariant(testAttribute(Qt::WA_InputMethodEnabled));
+ }
query->setValue(q, v);
}
}
@@ -8994,7 +9210,7 @@ bool QWidget::event(QEvent *event)
break;
#if QT_CONFIG(menu)
case Qt::ActionsContextMenu:
- if (d->actions.count()) {
+ if (d->actions.size()) {
QMenu::exec(d->actions, static_cast<QContextMenuEvent *>(event)->globalPos(),
nullptr, this);
break;
@@ -9218,16 +9434,15 @@ bool QWidget::event(QEvent *event)
const QWindow *win = te->window;
d->setWinId((win && win->handle()) ? win->handle()->winId() : 0);
}
+ break;
+ case QEvent::DevicePixelRatioChange:
if (d->data.fnt.d->dpi != logicalDpiY())
d->updateFont(d->data.fnt);
-#ifndef QT_NO_OPENGL
d->renderToTextureReallyDirty = 1;
-#endif
break;
-#ifndef QT_NO_PROPERTIES
case QEvent::DynamicPropertyChange: {
const QByteArray &propName = static_cast<QDynamicPropertyChangeEvent *>(event)->propertyName();
- if (propName.length() == 13 && !qstrncmp(propName, "_q_customDpi", 12)) {
+ if (propName.size() == 13 && !qstrncmp(propName, "_q_customDpi", 12)) {
uint value = property(propName.constData()).toUInt();
if (!d->extra)
d->createExtra();
@@ -9242,7 +9457,6 @@ bool QWidget::event(QEvent *event)
windowHandle()->setProperty(propName, property(propName));
Q_FALLTHROUGH();
}
-#endif
default:
return QObject::event(event);
}
@@ -9270,7 +9484,7 @@ void QWidget::changeEvent(QEvent * event)
switch(event->type()) {
case QEvent::EnabledChange: {
update();
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
QAccessible::State s;
s.disabled = true;
QAccessibleStateChangeEvent event(this, s);
@@ -9486,7 +9700,7 @@ void QWidget::tabletEvent(QTabletEvent *event)
implementation if you act upon the key.
\sa keyReleaseEvent(), setFocusPolicy(),
- focusInEvent(), focusOutEvent(), event(), QKeyEvent, {Tetrix Example}
+ focusInEvent(), focusOutEvent(), event(), QKeyEvent
*/
void QWidget::keyPressEvent(QKeyEvent *event)
@@ -9537,7 +9751,7 @@ void QWidget::keyReleaseEvent(QKeyEvent *event)
is passed in the \a event parameter
A widget normally must setFocusPolicy() to something other than
- Qt::NoFocus in order to receive focus events. (Note that the
+ Qt::NoFocus to receive focus events. (Note that the
application programmer can call setFocus() on any widget, even
those that do not normally accept focus.)
@@ -9563,7 +9777,7 @@ void QWidget::focusInEvent(QFocusEvent *)
passed in the \a event parameter.
A widget normally must setFocusPolicy() to something other than
- Qt::NoFocus in order to receive focus events. (Note that the
+ Qt::NoFocus to receive focus events. (Note that the
application programmer can call setFocus() on any widget, even
those that do not normally accept focus.)
@@ -9663,7 +9877,7 @@ void QWidget::leaveEvent(QEvent *)
never be called; the backingstore will be used instead.
\sa event(), repaint(), update(), QPainter, QPixmap, QPaintEvent,
- {Analog Clock Example}
+ {Analog Clock}
*/
void QWidget::paintEvent(QPaintEvent *)
@@ -9735,13 +9949,8 @@ void QWidget::actionEvent(QActionEvent *)
Main window applications typically use reimplementations of this function to check
whether the user's work has been saved and ask for permission before closing.
- For example, the \l{Qt Widgets - Application Example} uses a helper function to
- determine whether or not to close the window:
- \snippet mainwindows/application/mainwindow.cpp 3
- \snippet mainwindows/application/mainwindow.cpp 4
-
- \sa event(), hide(), close(), QCloseEvent, {Qt Widgets - Application Example}
+ \sa event(), hide(), close(), QCloseEvent
*/
void QWidget::closeEvent(QCloseEvent *event)
@@ -9830,7 +10039,7 @@ QVariant QWidget::inputMethodQuery(Qt::InputMethodQuery query) const
is set, the input method may change its visual components to reflect
that only numbers can be entered.
- \warning Some widgets require certain flags in order to work as
+ \warning Some widgets require certain flags to work as
intended. To set a flag, do \c{w->setInputMethodHints(w->inputMethodHints()|f)}
instead of \c{w->setInputMethodHints(f)}.
@@ -10080,7 +10289,7 @@ void QWidget::ensurePolished() const
Returns the mask currently set on a widget. If no mask is set the
return value will be an empty region.
- \sa setMask(), clearMask(), QRegion::isEmpty(), {Shaped Clock Example}
+ \sa setMask(), clearMask(), QRegion::isEmpty()
*/
QRegion QWidget::mask() const
{
@@ -10501,22 +10710,20 @@ void QWidget::setParent(QWidget *parent)
setParent((QWidget*)parent, windowFlags() & ~Qt::WindowType_Mask);
}
-#ifndef QT_NO_OPENGL
-static void sendWindowChangeToTextureChildrenRecursively(QWidget *widget)
+void qSendWindowChangeToTextureChildrenRecursively(QWidget *widget, QEvent::Type eventType)
{
QWidgetPrivate *d = QWidgetPrivate::get(widget);
if (d->renderToTexture) {
- QEvent e(QEvent::WindowChangeInternal);
+ QEvent e(eventType);
QCoreApplication::sendEvent(widget, &e);
}
for (int i = 0; i < d->children.size(); ++i) {
QWidget *w = qobject_cast<QWidget *>(d->children.at(i));
if (w && !w->isWindow() && QWidgetPrivate::get(w)->textureChildSeen)
- sendWindowChangeToTextureChildrenRecursively(w);
+ qSendWindowChangeToTextureChildrenRecursively(w, eventType);
}
}
-#endif
/*!
\overload
@@ -10543,8 +10750,8 @@ void QWidget::setParent(QWidget *parent, Qt::WindowFlags f)
});
#endif
- bool resized = testAttribute(Qt::WA_Resized);
- bool wasCreated = testAttribute(Qt::WA_WState_Created);
+ const bool resized = testAttribute(Qt::WA_Resized);
+ const bool wasCreated = testAttribute(Qt::WA_WState_Created);
QWidget *oldtlw = window();
if (f & Qt::Window) // Frame geometry likely changes, refresh.
@@ -10553,7 +10760,7 @@ void QWidget::setParent(QWidget *parent, Qt::WindowFlags f)
QWidget *desktopWidget = nullptr;
if (parent && parent->windowType() == Qt::Desktop)
desktopWidget = parent;
- bool newParent = (parent != parentWidget()) || !wasCreated || desktopWidget;
+ bool newParent = (parent != parentWidget()) || desktopWidget;
if (newParent && parent && !desktopWidget) {
if (testAttribute(Qt::WA_NativeWindow) && !QCoreApplication::testAttribute(Qt::AA_DontCreateNativeWidgetSiblings))
@@ -10564,7 +10771,20 @@ void QWidget::setParent(QWidget *parent, Qt::WindowFlags f)
if (wasCreated) {
if (!testAttribute(Qt::WA_WState_Hidden)) {
+ // Hiding the widget will set WA_WState_Hidden as well, which would
+ // normally require the widget to be explicitly shown again to become
+ // visible, even as a child widget. But we refine this value later in
+ // setParent_sys(), applying WA_WState_Hidden based on whether the
+ // widget is a top level or not.
hide();
+
+ // We reset WA_WState_ExplicitShowHide here, likely as a remnant of
+ // when we only had QWidget::setVisible(), which is treated as an
+ // explicit show/hide. Nowadays we have QWidgetPrivate::setVisible(),
+ // that allows us to hide a widget without affecting ExplicitShowHide.
+ // Though it can be argued that ExplicitShowHide should reflect the
+ // last update of the widget's state, so if we hide the widget as a
+ // side effect of changing parent, perhaps we _should_ reset it?
setAttribute(Qt::WA_WState_ExplicitShowHide, false);
}
if (newParent) {
@@ -10572,7 +10792,15 @@ void QWidget::setParent(QWidget *parent, Qt::WindowFlags f)
QCoreApplication::sendEvent(this, &e);
}
}
- if (newParent && isAncestorOf(focusWidget()))
+
+ // texture-based widgets need a pre-notification when their associated top-level window changes
+ // This is not under the wasCreated/newParent conditions above in order to also play nice with QDockWidget.
+ if (d->textureChildSeen && ((!parent && parentWidget()) || (parent && parent->window() != oldtlw)))
+ qSendWindowChangeToTextureChildrenRecursively(this, QEvent::WindowAboutToChangeInternal);
+
+ // If we get parented into another window, children will be folded
+ // into the new parent's focus chain, so clear focus now.
+ if (newParent && isAncestorOf(focusWidget()) && !(f & Qt::Window))
focusWidget()->clearFocus();
d->setParent_sys(parent, f);
@@ -10580,12 +10808,10 @@ void QWidget::setParent(QWidget *parent, Qt::WindowFlags f)
if (desktopWidget)
parent = nullptr;
-#ifndef QT_NO_OPENGL
if (d->textureChildSeen && parent) {
// set the textureChildSeen flag up the whole parent chain
QWidgetPrivate::get(parent)->setTextureChildSeen();
}
-#endif
if (QWidgetRepaintManager *oldPaintManager = oldtlw->d_func()->maybeRepaintManager()) {
if (newParent)
@@ -10619,7 +10845,7 @@ void QWidget::setParent(QWidget *parent, Qt::WindowFlags f)
// event to handle recreation/rebinding of the GL context, hence the
// (f & Qt::MSWindowsOwnDC) clause (which is set on QGLWidgets on all
// platforms).
- if (newParent
+ if (newParent || !wasCreated
#if QT_CONFIG(opengles2)
|| (f & Qt::MSWindowsOwnDC)
#endif
@@ -10647,12 +10873,11 @@ void QWidget::setParent(QWidget *parent, Qt::WindowFlags f)
QEvent e(QEvent::ParentChange);
QCoreApplication::sendEvent(this, &e);
}
-#ifndef QT_NO_OPENGL
- //renderToTexture widgets also need to know when their top-level window changes
- if (d->textureChildSeen && oldtlw != window()) {
- sendWindowChangeToTextureChildrenRecursively(this);
- }
-#endif
+
+ // texture-based widgets need another event when their top-level window
+ // changes (more precisely, has already changed at this point)
+ if (d->textureChildSeen && oldtlw != window())
+ qSendWindowChangeToTextureChildrenRecursively(this, QEvent::WindowChangeInternal);
if (!wasCreated) {
if (isWindow() || parentWidget()->isVisible())
@@ -10678,6 +10903,37 @@ void QWidget::setParent(QWidget *parent, Qt::WindowFlags f)
if (d->extra && d->extra->hasWindowContainer)
QWindowContainer::parentWasChanged(this);
+
+ QWidget *newtlw = window();
+ if (oldtlw != newtlw) {
+ QSurface::SurfaceType surfaceType = QSurface::RasterSurface;
+ // Only evaluate the reparented subtree. While it might be tempting to
+ // do it on newtlw instead, the performance implications of that are
+ // problematic when it comes to large widget trees.
+ if (q_evaluateRhiConfig(this, nullptr, &surfaceType)) {
+ const bool wasUsingRhiFlush = newtlw->d_func()->usesRhiFlush;
+ newtlw->d_func()->usesRhiFlush = true;
+ bool recreate = false;
+ if (QWindow *w = newtlw->windowHandle()) {
+ if (w->surfaceType() != surfaceType || !wasUsingRhiFlush)
+ recreate = true;
+ }
+ // QTBUG-115652: Besides the toplevel the nativeParentWidget()'s QWindow must be checked as well.
+ if (QWindow *w = d->windowHandle(QWidgetPrivate::WindowHandleMode::Closest)) {
+ if (w->surfaceType() != surfaceType)
+ recreate = true;
+ }
+ if (recreate) {
+ const auto windowStateBeforeDestroy = newtlw->windowState();
+ const auto visibilityBeforeDestroy = newtlw->isVisible();
+ newtlw->destroy();
+ newtlw->create();
+ Q_ASSERT(newtlw->windowHandle());
+ newtlw->windowHandle()->setWindowStates(windowStateBeforeDestroy);
+ QWidgetPrivate::get(newtlw)->setVisible(visibilityBeforeDestroy);
+ }
+ }
+ }
}
void QWidgetPrivate::setParent_sys(QWidget *newparent, Qt::WindowFlags f)
@@ -10698,57 +10954,61 @@ void QWidgetPrivate::setParent_sys(QWidget *newparent, Qt::WindowFlags f)
setWinId(0);
- if (parent != newparent) {
- QObjectPrivate::setParent_helper(newparent); //### why does this have to be done in the _sys function???
- if (q->windowHandle()) {
- q->windowHandle()->setFlags(f);
- QWidget *parentWithWindow =
- newparent ? (newparent->windowHandle() ? newparent : newparent->nativeParentWidget()) : nullptr;
- if (parentWithWindow) {
- QWidget *topLevel = parentWithWindow->window();
- if ((f & Qt::Window) && topLevel && topLevel->windowHandle()) {
- q->windowHandle()->setTransientParent(topLevel->windowHandle());
- q->windowHandle()->setParent(nullptr);
- } else {
- q->windowHandle()->setTransientParent(nullptr);
- q->windowHandle()->setParent(parentWithWindow->windowHandle());
- }
- } else {
- q->windowHandle()->setTransientParent(nullptr);
- q->windowHandle()->setParent(nullptr);
- }
- }
- }
-
if (!newparent) {
f |= Qt::Window;
if (parent)
targetScreen = q->parentWidget()->window()->screen();
}
- bool explicitlyHidden = q->testAttribute(Qt::WA_WState_Hidden) && q->testAttribute(Qt::WA_WState_ExplicitShowHide);
+ const bool destroyWindow = (
+ // Reparenting top level to child
+ (oldFlags & Qt::Window) && !(f & Qt::Window)
+ // And we can dispose of the window
+ && wasCreated && !q->testAttribute(Qt::WA_NativeWindow)
+ );
- // Reparenting toplevel to child
- if (wasCreated && !(f & Qt::Window) && (oldFlags & Qt::Window) && !q->testAttribute(Qt::WA_NativeWindow)) {
- if (extra && extra->hasWindowContainer)
- QWindowContainer::toplevelAboutToBeDestroyed(q);
+ if (parent != newparent) {
+ // Update object parent now, so we can resolve new parent window below
+ QObjectPrivate::setParent_helper(newparent);
- QWindow *newParentWindow = newparent->windowHandle();
- if (!newParentWindow)
- if (QWidget *npw = newparent->nativeParentWidget())
- newParentWindow = npw->windowHandle();
+ if (q->windowHandle())
+ q->windowHandle()->setFlags(f);
- for (QObject *child : q->windowHandle()->children()) {
- QWindow *childWindow = qobject_cast<QWindow *>(child);
- if (!childWindow)
- continue;
+ // If the widget itself or any of its children have been created,
+ // we need to reparent their QWindows as well.
+ QWidget *parentWithWindow = closestParentWidgetWithWindowHandle();
+ // But if the widget is about to be destroyed we must skip the
+ // widget itself, and only reparent children.
+ if (destroyWindow)
+ reparentWidgetWindowChildren(parentWithWindow);
+ else
+ reparentWidgetWindows(parentWithWindow, f);
+ }
- QWidgetWindow *childWW = qobject_cast<QWidgetWindow *>(childWindow);
- QWidget *childWidget = childWW ? childWW->widget() : nullptr;
- if (!childWW || (childWidget && childWidget->testAttribute(Qt::WA_NativeWindow)))
- childWindow->setParent(newParentWindow);
+ bool explicitlyHidden = isExplicitlyHidden();
+
+ if (destroyWindow) {
+ if (extra && extra->hasWindowContainer)
+ QWindowContainer::toplevelAboutToBeDestroyed(q);
+
+ // There shouldn't be any QWindow children left, but if there
+ // are, re-parent them now, before we destroy.
+ if (!q->windowHandle()->children().isEmpty()) {
+ QWidget *parentWithWindow = closestParentWidgetWithWindowHandle();
+ QWindow *newParentWindow = parentWithWindow ? parentWithWindow->windowHandle() : nullptr;
+ for (QObject *child : q->windowHandle()->children()) {
+ if (QWindow *childWindow = qobject_cast<QWindow *>(child)) {
+ qCWarning(lcWidgetWindow) << "Reparenting" << childWindow
+ << "before destroying" << this;
+ childWindow->setParent(newParentWindow);
+ }
+ }
}
- q->destroy();
+
+ // We have reparented any child windows of the widget we are
+ // about to destroy to the new parent window handle, so we can
+ // safely destroy this widget without destroying sub windows.
+ q->destroy(true, false);
}
adjustFlags(f, q);
@@ -10774,6 +11034,53 @@ void QWidgetPrivate::setParent_sys(QWidget *newparent, Qt::WindowFlags f)
}
}
+void QWidgetPrivate::reparentWidgetWindows(QWidget *parentWithWindow, Qt::WindowFlags windowFlags)
+{
+ if (QWindow *window = windowHandle()) {
+ // Reparent this QWindow, and all QWindow children will follow
+ if (parentWithWindow) {
+ // The reparented widget has not updated its window flags yet,
+ // so we can't ask the widget directly. And we can't use the
+ // QWindow flags, as unlike QWidgets the QWindow flags always
+ // reflect Qt::Window, even for child windows. And we can't use
+ // QWindow::isTopLevel() either, as that depends on the parent,
+ // which we are in the process of updating. So we propagate the
+ // new flags of the reparented window from setParent_sys().
+ if (windowFlags & Qt::Window) {
+ // Top level windows can only have transient parents,
+ // and the transient parent must be another top level.
+ QWidget *topLevel = parentWithWindow->window();
+ auto *transientParent = topLevel->windowHandle();
+ Q_ASSERT(transientParent);
+ qCDebug(lcWidgetWindow) << "Setting" << window << "transient parent to" << transientParent;
+ window->setTransientParent(transientParent);
+ window->setParent(nullptr);
+ } else {
+ auto *parentWindow = parentWithWindow->windowHandle();
+ qCDebug(lcWidgetWindow) << "Reparenting" << window << "into" << parentWindow;
+ window->setTransientParent(nullptr);
+ window->setParent(parentWindow);
+ }
+ } else {
+ qCDebug(lcWidgetWindow) << "Making" << window << "top level window";
+ window->setTransientParent(nullptr);
+ window->setParent(nullptr);
+ }
+ } else {
+ reparentWidgetWindowChildren(parentWithWindow);
+ }
+}
+
+void QWidgetPrivate::reparentWidgetWindowChildren(QWidget *parentWithWindow)
+{
+ for (auto *child : std::as_const(children)) {
+ if (auto *childWidget = qobject_cast<QWidget*>(child)) {
+ auto *childPrivate = QWidgetPrivate::get(childWidget);
+ childPrivate->reparentWidgetWindows(parentWithWindow);
+ }
+ }
+}
+
/*!
Scrolls the widget including its children \a dx pixels to the
right and \a dy downward. Both \a dx and \a dy may be negative.
@@ -10868,7 +11175,7 @@ void QWidgetPrivate::scroll_sys(int dx, int dy, const QRect &r)
unless updates are disabled or the widget is hidden.
We suggest only using repaint() if you need an immediate repaint,
- for example during animation. In almost all circumstances update()
+ for example during animation. In most circumstances update()
is better, as it permits Qt to optimize for speed and minimize
flicker.
@@ -10935,7 +11242,7 @@ void QWidgetPrivate::repaint(T r)
return;
QTLWExtra *tlwExtra = q->window()->d_func()->maybeTopData();
- if (tlwExtra && tlwExtra->backingStore)
+ if (tlwExtra && tlwExtra->backingStore && tlwExtra->repaintManager)
tlwExtra->repaintManager->markDirty(r, q, QWidgetRepaintManager::UpdateNow);
}
@@ -10955,7 +11262,7 @@ void QWidgetPrivate::repaint(T r)
If the Qt::WA_OpaquePaintEvent widget attribute is set, the widget is
responsible for painting all its pixels with an opaque color.
- \sa repaint(), paintEvent(), setUpdatesEnabled(), {Analog Clock Example}
+ \sa repaint(), paintEvent(), setUpdatesEnabled(), {Analog Clock}
*/
void QWidget::update()
{
@@ -10996,6 +11303,11 @@ void QWidgetPrivate::update(T r)
{
Q_Q(QWidget);
+ if (renderToTexture && !q->isVisible()) {
+ renderToTextureReallyDirty = 1;
+ return;
+ }
+
if (!q->isVisible() || !q->updatesEnabled())
return;
@@ -11010,7 +11322,7 @@ void QWidgetPrivate::update(T r)
}
QTLWExtra *tlwExtra = q->window()->d_func()->maybeTopData();
- if (tlwExtra && tlwExtra->backingStore)
+ if (tlwExtra && tlwExtra->backingStore && tlwExtra->repaintManager)
tlwExtra->repaintManager->markDirty(clipped, q);
}
@@ -11359,8 +11671,7 @@ void QWidgetPrivate::setWindowOpacity_sys(qreal level)
its parent because other children of the parent might have been
modified.
- \sa windowTitle, {Qt Widgets - Application Example}, {SDI Example},
- {MDI Example}
+ \sa windowTitle
*/
bool QWidget::isWindowModified() const
{
@@ -11389,7 +11700,7 @@ void QWidgetPrivate::setWindowModified_helper()
return;
bool on = q->testAttribute(Qt::WA_WindowModified);
if (!platformWindow->setWindowModified(on)) {
- if (Q_UNLIKELY(on && !q->windowTitle().contains(QLatin1String("[*]"))))
+ if (Q_UNLIKELY(on && !q->windowTitle().contains("[*]"_L1)))
qWarning("QWidget::setWindowModified: The window title does not contain a '[*]' placeholder");
setWindowTitle_helper(q->windowTitle());
setWindowIconText_helper(q->windowIconText());
@@ -11501,7 +11812,7 @@ QString QWidget::whatsThis() const
}
#endif // QT_CONFIG(whatsthis)
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
/*!
\property QWidget::accessibleName
@@ -11566,7 +11877,7 @@ QString QWidget::accessibleDescription() const
Q_D(const QWidget);
return d->accessibleDescription;
}
-#endif // QT_NO_ACCESSIBILITY
+#endif // QT_CONFIG(accessibility)
#ifndef QT_NO_SHORTCUT
/*!
@@ -12051,7 +12362,7 @@ void QWidget::setBackingStore(QBackingStore *store)
return;
QBackingStore *oldStore = topData->backingStore;
- deleteBackingStore(d);
+ delete topData->backingStore;
topData->backingStore = store;
QWidgetRepaintManager *repaintManager = d->maybeRepaintManager();
@@ -12146,27 +12457,6 @@ void QWidgetPrivate::adjustQuitOnCloseAttribute()
}
}
-QOpenGLContext *QWidgetPrivate::shareContext() const
-{
-#ifdef QT_NO_OPENGL
- return nullptr;
-#else
- if (!extra || !extra->topextra || !extra->topextra->window)
- return nullptr;
-
- if (!extra->topextra->shareContext) {
- auto ctx = std::make_unique<QOpenGLContext>();
- ctx->setShareContext(qt_gl_global_share_context());
- ctx->setFormat(extra->topextra->window->format());
- ctx->setScreen(extra->topextra->window->screen());
- ctx->create();
- extra->topextra->shareContext = std::move(ctx);
- }
- return extra->topextra->shareContext.get();
-#endif // QT_NO_OPENGL
-}
-
-#ifndef QT_NO_OPENGL
void QWidgetPrivate::sendComposeStatus(QWidget *w, bool end)
{
QWidgetPrivate *wd = QWidgetPrivate::get(w);
@@ -12182,7 +12472,6 @@ void QWidgetPrivate::sendComposeStatus(QWidget *w, bool end)
sendComposeStatus(w, end);
}
}
-#endif // QT_NO_OPENGL
Q_WIDGETS_EXPORT QWidgetData *qt_qwidget_data(QWidget *widget)
{
@@ -12271,8 +12560,8 @@ void QWidget::destroy(bool destroyWindow, bool destroySubWindows)
if ((windowType() == Qt::Popup) && qApp)
qApp->d_func()->closePopup(this);
- if (this == QApplicationPrivate::active_window)
- QApplication::setActiveWindow(nullptr);
+ if (this == qApp->activeWindow())
+ QApplicationPrivate::setActiveWindow(nullptr);
if (QWidget::mouseGrabber() == this)
releaseMouse();
if (QWidget::keyboardGrabber() == this)
@@ -12509,7 +12798,7 @@ static void releaseMouseGrabOfWidget(QWidget *widget)
terminal. Use this function with extreme caution, and consider
using the \c -nograb command line option while debugging.
- It is almost never necessary to grab the mouse when using Qt, as
+ It is seldom necessary to grab the mouse when using Qt, as
Qt grabs and releases it sensibly. In particular, Qt grabs the
mouse when a mouse button is pressed and keeps it until the last
button is released.
@@ -12698,57 +12987,59 @@ void QWidget::activateWindow()
*/
int QWidget::metric(PaintDeviceMetric m) const
{
- QWindow *topLevelWindow = nullptr;
- QScreen *screen = nullptr;
- if (QWidget *topLevel = window()) {
- topLevelWindow = topLevel->windowHandle();
- if (topLevelWindow)
- screen = topLevelWindow->screen();
- }
- if (!screen && QGuiApplication::primaryScreen())
- screen = QGuiApplication::primaryScreen();
+ QScreen *screen = this->screen();
if (!screen) {
if (m == PdmDpiX || m == PdmDpiY)
return 72;
return QPaintDevice::metric(m);
}
- int val;
- if (m == PdmWidth) {
- val = data->crect.width();
- } else if (m == PdmWidthMM) {
- val = data->crect.width() * screen->physicalSize().width() / screen->geometry().width();
- } else if (m == PdmHeight) {
- val = data->crect.height();
- } else if (m == PdmHeightMM) {
- val = data->crect.height() * screen->physicalSize().height() / screen->geometry().height();
- } else if (m == PdmDepth) {
+
+ auto resolveDevicePixelRatio = [this, screen]() -> qreal {
+
+ // Note: keep in sync with QBackingStorePrivate::backingStoreDevicePixelRatio()!
+ static bool downscale = qEnvironmentVariableIntValue("QT_WIDGETS_HIGHDPI_DOWNSCALE") > 0;
+ QWindow *window = this->window()->windowHandle();
+ if (window)
+ return downscale ? std::ceil(window->devicePixelRatio()) : window->devicePixelRatio();
+ return screen->devicePixelRatio();
+ };
+
+ switch (m) {
+ case PdmWidth:
+ return data->crect.width();
+ case PdmWidthMM:
+ return data->crect.width() * screen->physicalSize().width() / screen->geometry().width();
+ case PdmHeight:
+ return data->crect.height();
+ case PdmHeightMM:
+ return data->crect.height() * screen->physicalSize().height() / screen->geometry().height();
+ case PdmDepth:
return screen->depth();
- } else if (m == PdmDpiX) {
+ case PdmDpiX:
for (const QWidget *p = this; p; p = p->parentWidget()) {
if (p->d_func()->extra && p->d_func()->extra->customDpiX)
return p->d_func()->extra->customDpiX;
}
return qRound(screen->logicalDotsPerInchX());
- } else if (m == PdmDpiY) {
+ case PdmDpiY:
for (const QWidget *p = this; p; p = p->parentWidget()) {
if (p->d_func()->extra && p->d_func()->extra->customDpiY)
return p->d_func()->extra->customDpiY;
}
return qRound(screen->logicalDotsPerInchY());
- } else if (m == PdmPhysicalDpiX) {
+ case PdmPhysicalDpiX:
return qRound(screen->physicalDotsPerInchX());
- } else if (m == PdmPhysicalDpiY) {
+ case PdmPhysicalDpiY:
return qRound(screen->physicalDotsPerInchY());
- } else if (m == PdmDevicePixelRatio) {
- return topLevelWindow ? topLevelWindow->devicePixelRatio() : qApp->devicePixelRatio();
- } else if (m == PdmDevicePixelRatioScaled) {
- return (QPaintDevice::devicePixelRatioFScale() *
- (topLevelWindow ? topLevelWindow->devicePixelRatio() : qApp->devicePixelRatio()));
- } else {
- val = QPaintDevice::metric(m);// XXX
+ case PdmDevicePixelRatio:
+ return resolveDevicePixelRatio();
+ case PdmDevicePixelRatioScaled:
+ return QPaintDevice::devicePixelRatioFScale() * resolveDevicePixelRatio();
+ default:
+ break;
}
- return val;
+ return QPaintDevice::metric(m);
}
/*!
@@ -12806,8 +13097,16 @@ QPainter *QWidget::sharedPainter() const
widget, window system controls in that area may or may not be
visible, depending on the platform.
- Note that this effect can be slow if the region is particularly
- complex.
+ Since QRegion allows arbitrarily complex regions to be created, widget
+ masks can be made to suit the most unconventionally-shaped windows, and
+ even allow widgets to be displayed with holes in them. Note that this
+ effect can be slow if the region is particularly complex.
+
+ Widget masks are used to hint to the window system that the application
+ does not want mouse events for areas outside the mask. On most systems,
+ they also result in coarse visual clipping. To get smooth window edges, use
+ translucent background and anti-aliased painting instead, as shown in the
+ \l{Translucent Background} example.
\sa windowOpacity
*/
@@ -12893,7 +13192,7 @@ void QWidgetPrivate::setMask_sys(const QRegion &region)
Masked widgets receive mouse events only on their visible
portions.
- \sa clearMask(), windowOpacity(), {Shaped Clock Example}
+ \sa clearMask(), windowOpacity()
*/
void QWidget::setMask(const QBitmap &bitmap)
{
@@ -12923,6 +13222,25 @@ void QWidgetPrivate::setWidgetParentHelper(QObject *widgetAsObject, QObject *new
widget->setParent(static_cast<QWidget*>(newParent));
}
+std::string QWidgetPrivate::flagsForDumping() const
+{
+ Q_Q(const QWidget);
+ std::string flags = QObjectPrivate::flagsForDumping();
+ if (QApplication::focusWidget() == q)
+ flags += 'F';
+ if (q->isVisible()) {
+ std::stringstream s;
+ s << '<'
+ << q->width() << 'x' << q->height()
+ << std::showpos << q->x() << q->y()
+ << '>';
+ flags += s.str();
+ } else {
+ flags += 'I';
+ }
+ return flags;
+}
+
void QWidgetPrivate::setNetWmWindowTypes(bool skipIfMissing)
{
#if QT_CONFIG(xcb)
@@ -12969,22 +13287,47 @@ void QWidgetPrivate::setNetWmWindowTypes(bool skipIfMissing)
#endif
}
+/*!
+ \internal
+ \return \c true, if a child with \param policy exists and isn't a child of \param excludeChildrenOf.
+ Return false otherwise.
+ */
+bool QWidgetPrivate::hasChildWithFocusPolicy(Qt::FocusPolicy policy, const QWidget *excludeChildrenOf) const
+{
+ Q_Q(const QWidget);
+ const QWidgetList &children = q->findChildren<QWidget *>(Qt::FindChildrenRecursively);
+ for (const auto *child : children) {
+ if (child->focusPolicy() == policy && child->isEnabled()
+ && (!excludeChildrenOf || !excludeChildrenOf->isAncestorOf(child))) {
+ return true;
+ }
+ }
+ return false;
+}
+
#ifndef QT_NO_DEBUG_STREAM
-static inline void formatWidgetAttributes(QDebug debug, const QWidget *widget)
+namespace {
+QDebug operator<<(QDebug debug, const WidgetAttributes &attributes)
{
- const QMetaObject *qtMo = qt_getEnumMetaObject(Qt::WA_AttributeCount);
- const QMetaEnum me = qtMo->enumerator(qtMo->indexOfEnumerator("WidgetAttribute"));
- debug << ", attributes=[";
- int count = 0;
- for (int a = 0; a < Qt::WA_AttributeCount; ++a) {
- if (widget->testAttribute(static_cast<Qt::WidgetAttribute>(a))) {
- if (count++)
- debug << ',';
- debug << me.valueToKey(a);
+ const QDebugStateSaver saver(debug);
+ debug.nospace();
+ debug << '[';
+ if (const QWidget *widget = attributes.widget) {
+ const QMetaObject *qtMo = qt_getEnumMetaObject(Qt::WA_AttributeCount);
+ const QMetaEnum me = qtMo->enumerator(qtMo->indexOfEnumerator("WidgetAttribute"));
+ int count = 0;
+ for (int a = 0; a < Qt::WA_AttributeCount; ++a) {
+ if (widget->testAttribute(static_cast<Qt::WidgetAttribute>(a))) {
+ if (count++)
+ debug << ',';
+ debug << me.valueToKey(a);
+ }
}
}
debug << ']';
+ return debug;
+}
}
QDebug operator<<(QDebug debug, const QWidget *widget)
@@ -13004,7 +13347,7 @@ QDebug operator<<(QDebug debug, const QWidget *widget)
debug << ", disabled";
debug << ", states=" << widget->windowState()
<< ", type=" << widget->windowType() << ", flags=" << widget->windowFlags();
- formatWidgetAttributes(debug, widget);
+ debug << ", attributes=" << WidgetAttributes{widget};
if (widget->isWindow())
debug << ", window";
debug << ", " << geometry.width() << 'x' << geometry.height()
@@ -13031,4 +13374,4 @@ QDebug operator<<(QDebug debug, const QWidget *widget)
QT_END_NAMESPACE
#include "moc_qwidget.cpp"
-
+#include "moc_qwidget_p.cpp"