From dfe5f991207dcc74868d41feae5bc2bbad277808 Mon Sep 17 00:00:00 2001 From: Axel Spoerl Date: Thu, 10 Mar 2022 16:47:26 +0100 Subject: [PATCH] Fix QDockWidget's dock area permissions after hovering When a QDockWidget's dock areas are restricted by setAllowedAreas(...) and a second QDockWidget is hovered over it, the first QDockWidget can be docked to any dock area of the main window. Area restrictions will be ignored. That is due to the first QDockWidget being implicitely mutated into a QDockWidgetGroupWindow upon hovering. By definition, the latter has no docking restricitons. This fix adds a check if a QDockWidgetGroupWindow has a single QDockWidget child. In that case, the single child's area permissions will restrict docking. Fixes: QTBUG-100670 Pick-to: 6.3 6.2 5.15 Change-Id: I903b074739953791634f482c9cf4b9a95a1d93d3 Reviewed-by: Volker Hilsheimer --- src/widgets/widgets/qmainwindowlayout.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/widgets/widgets/qmainwindowlayout.cpp b/src/widgets/widgets/qmainwindowlayout.cpp index 60db982cb75..3346e0202fa 100644 --- a/src/widgets/widgets/qmainwindowlayout.cpp +++ b/src/widgets/widgets/qmainwindowlayout.cpp @@ -2725,8 +2725,18 @@ void QMainWindowLayout::hover(QLayoutItem *widgetItem, const QPoint &mousePos) if (QDockWidget *dw = qobject_cast(widget)) allowed = dw->isAreaAllowed(toDockWidgetArea(path.at(1))); - if (qobject_cast(widget)) - allowed = true; + // Read permissions from a DockWidgetGroupWindow depending on its DockWidget children + if (QDockWidgetGroupWindow* dwgw = qobject_cast(widget)) { + const QList children = dwgw->findChildren(QString(), Qt::FindDirectChildrenOnly); + + if (children.count() == 1) { + // Group window has a single child => read its permissions + allowed = children.at(0)->isAreaAllowed(toDockWidgetArea(path.at(1))); + } else { + // Group window has more than one or no children => dock it anywhere + allowed = true; + } + } #endif #if QT_CONFIG(toolbar) if (QToolBar *tb = qobject_cast(widget))