From 5419df55f3a7e71690b30cf9d1ddb9ed56dd2bcb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Tue, 21 Nov 2023 18:13:41 +0100 Subject: [PATCH] Use Qt::WindowNoState for child windows/widgets shown via show() The Qt::WindowState enum is documented to specify the current state of top-level windows, and does not make sense for child windows. It's up to the client code to ensure any sizing of child windows/widgets, e.g. via layouts. Many of our QPA backends bail out on QPlatformWindow::setWindowState() for a child window. Ideally we would do this at a higher level, in QWindow, but that's a bigger task, and the semantics of what happens when a window is moved from being top level to child or back are not fully clear. As a first step, we ensure that the default window state when showing the window via show() is Qt::WindowNoState. Unfortunately, the QPlatformIntegration::defaultWindowState() API only takes into account the window flags, which sadly do not have a way to reflect whether the window is a child window or not (Qt::SubWindow is not a child window, see QTBUG-115729). We don't want to pass a QWindow to this API, as it would mean QWidget would need to create a window when requesting the default window state. Instead we hard-code the opt-out for child windows/widgets. [ChangeLog][Gui/Widgets] Child windows and widgets are now always shown in their normal state by show(). Change-Id: Ie8caf2df2d854194b9985c9427a9eac1312aba65 Reviewed-by: Assam Boudjelthia (cherry picked from commit 3472aa6e28469ffd23cfa24e3933541f295e9e1d) Reviewed-by: Qt Cherry-pick Bot --- src/gui/kernel/qwindow.cpp | 20 +++++++++++++------- src/widgets/kernel/qwidget.cpp | 28 ++++++++++++++++++---------- 2 files changed, 31 insertions(+), 17 deletions(-) diff --git a/src/gui/kernel/qwindow.cpp b/src/gui/kernel/qwindow.cpp index 57fe8fa287e..46a787e7064 100644 --- a/src/gui/kernel/qwindow.cpp +++ b/src/gui/kernel/qwindow.cpp @@ -2231,20 +2231,26 @@ QObject *QWindow::focusObject() const /*! Shows the window. - This is equivalent to calling showFullScreen(), showMaximized(), or showNormal(), + For child windows, this is equivalent to calling showNormal(). + Otherwise, it is equivalent to calling showFullScreen(), showMaximized(), or showNormal(), depending on the platform's default behavior for the window type and flags. \sa showFullScreen(), showMaximized(), showNormal(), hide(), QStyleHints::showIsFullScreen(), flags() */ void QWindow::show() { - Qt::WindowState defaultState = QGuiApplicationPrivate::platformIntegration()->defaultWindowState(d_func()->windowFlags); - if (defaultState == Qt::WindowFullScreen) - showFullScreen(); - else if (defaultState == Qt::WindowMaximized) - showMaximized(); - else + if (parent()) { showNormal(); + } else { + const auto *platformIntegration = QGuiApplicationPrivate::platformIntegration(); + Qt::WindowState defaultState = platformIntegration->defaultWindowState(d_func()->windowFlags); + if (defaultState == Qt::WindowFullScreen) + showFullScreen(); + else if (defaultState == Qt::WindowMaximized) + showMaximized(); + else + showNormal(); + } } /*! diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index f9151f6147a..f644cb53eca 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -7954,21 +7954,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