From e29ffd3bd13dbc1e808cfc4f7764878f855d1a62 Mon Sep 17 00:00:00 2001 From: Axel Spoerl Date: Mon, 26 Dec 2022 10:28:55 +0100 Subject: [PATCH] Fix size calculation of unplugged dock widgets When unplugging a dock widget, it still grows by the separator size when dragged upwards or to the left. The unplugged dock widget's size can become too small to drag it or to access window handles. This patch corrects the size offset for all drag directions. It expands the target size to a minimum size, making sure that title bar and window handles can be accessed after unplugging. Fixes: QTBUG-106531 Pick-to: 6.5 6.4 6.2 Change-Id: Ie771a9338ebfb4c0eafd3b3b4205de730cbd20ac Reviewed-by: Shawn Rutledge --- src/widgets/widgets/qmainwindowlayout.cpp | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/widgets/widgets/qmainwindowlayout.cpp b/src/widgets/widgets/qmainwindowlayout.cpp index 12d8876fcc..08abcd1ada 100644 --- a/src/widgets/widgets/qmainwindowlayout.cpp +++ b/src/widgets/widgets/qmainwindowlayout.cpp @@ -2654,21 +2654,36 @@ QLayoutItem *QMainWindowLayout::unplug(QWidget *widget, bool group) } else #endif // QT_CONFIG(tabwidget) { - // Dock widget is unplugged from the main window - // => geometry needs to be adjusted by separator size + // Dock widget is unplugged from a main window dock + // => height or width need to be decreased by separator size switch (dockWidgetArea(dw)) { case Qt::LeftDockWidgetArea: case Qt::RightDockWidgetArea: - r.adjust(0, 0, 0, -sep); + r.setHeight(r.height() - sep); break; case Qt::TopDockWidgetArea: case Qt::BottomDockWidgetArea: - r.adjust(0, 0, -sep, 0); + r.setWidth(r.width() - sep); break; case Qt::NoDockWidgetArea: case Qt::DockWidgetArea_Mask: break; } + + // Depending on the title bar layout (vertical / horizontal), + // width and height have to provide minimum space for window handles + // and mouse dragging. + // Assuming horizontal title bar, if the dock widget does not have a layout. + const auto *layout = qobject_cast(dw->layout()); + const bool verticalTitleBar = layout ? layout->verticalTitleBar : false; + const int tbHeight = QApplication::style() + ? QApplication::style()->pixelMetric(QStyle::PixelMetric::PM_TitleBarHeight) + : 20; + const int minHeight = verticalTitleBar ? 2 * tbHeight : tbHeight; + const int minWidth = verticalTitleBar ? tbHeight : 2 * tbHeight; + r.setSize(r.size().expandedTo(QSize(minWidth, minHeight))); + qCDebug(lcQpaDockWidgets) << dw << "will be unplugged with size" << r.size(); + dw->d_func()->unplug(r); } }