QDockWidget: Always show dock widgets with the main window

QMainWindow::show() also showed its dock widget children. When a main
window with dock widget children consumed a show event for another
reason, hidden dock widget children remained hidden.

If a dock widget application went to the background, e.g. because it
was hidden behind another application gaining focus, a klick on the
dock widget application's app icon would not show its dock widget
children. Unless the dock widget application provides shows them
explicitly, they can never been shown again by the user.

=> show all dock widget and group window children, when QMainWindow
consumes a show event.

Pick-to: 6.6 6.5
Change-Id: I7e8b59f021ec4ec5679d0d08d0eeda1e3225a385
Reviewed-by: David Faure <david.faure@kdab.com>
This commit is contained in:
Axel Spoerl 2023-11-14 09:41:54 +01:00
parent 0e435b7f13
commit 4c60a11d8f
3 changed files with 19 additions and 0 deletions

View File

@ -1290,6 +1290,13 @@ bool QMainWindow::event(QEvent *event)
return true;
#endif // QT_CONFIG(statustip)
#if QT_CONFIG(dockwidget)
case QEvent::Show:
Q_ASSERT(d->layout);
d->layout->showDockWidgets();
break;
#endif // QT_CONFIG(dockwidget)
case QEvent::StyleChange:
#if QT_CONFIG(dockwidget)
Q_ASSERT(d->layout);

View File

@ -1494,6 +1494,17 @@ inline static Qt::DockWidgetArea toDockWidgetArea(int pos)
return QDockWidgetPrivate::toDockWidgetArea(static_cast<QInternal::DockPosition>(pos));
}
void QMainWindowLayout::showDockWidgets() const
{
const auto dockWidgets = parent()->findChildren<QDockWidget *>(Qt::FindDirectChildrenOnly);
for (auto *dockWidget : dockWidgets)
dockWidget->show();
const auto groupWindows = parent()->findChildren<QDockWidgetGroupWindow *>(Qt::FindDirectChildrenOnly);
for (auto *groupWindow : groupWindows)
groupWindow->show();
}
// Checks if QDockWidgetGroupWindow or QDockWidget can be plugged the area indicated by path.
// Returns false if called with invalid widget type or if compiled without dockwidget support.
static bool isAreaAllowed(QWidget *widget, const QList<int> &path)

View File

@ -498,6 +498,7 @@ public:
Qt::Orientation orientation);
Qt::DockWidgetArea dockWidgetArea(QWidget* widget) const;
bool restoreDockWidget(QDockWidget *dockwidget);
void showDockWidgets() const;
#if QT_CONFIG(tabbar)
void tabifyDockWidget(QDockWidget *first, QDockWidget *second);
void raise(QDockWidget *widget);