diff options
author | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2023-11-21 18:13:41 +0100 |
---|---|---|
committer | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2023-12-13 18:52:17 +0000 |
commit | 3472aa6e28469ffd23cfa24e3933541f295e9e1d (patch) | |
tree | 11ca2fca9838abef68f7a06cee5a0e0c8a160baf | |
parent | c0b0cdcb61e5e8b5a0770a5c311b9fa38afbdeda (diff) |
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().
Pick-to: 6.7
Change-Id: Ie8caf2df2d854194b9985c9427a9eac1312aba65
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
-rw-r--r-- | src/gui/kernel/qwindow.cpp | 20 | ||||
-rw-r--r-- | 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 57fe8fa287..46a787e706 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 f9151f6147..f644cb53ec 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 |