summaryrefslogtreecommitdiffstats
path: root/src/widgets
diff options
context:
space:
mode:
authorAxel Spoerl <axel.spoerl@qt.io>2022-12-26 10:28:55 +0100
committerAxel Spoerl <axel.spoerl@qt.io>2022-12-29 14:53:50 +0100
commite29ffd3bd13dbc1e808cfc4f7764878f855d1a62 (patch)
treee5c802fd2e4e53a4750e21bb52bb463c1fbf1934 /src/widgets
parentc69e727274adae7d3943587091254696c46fb75b (diff)
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 <shawn.rutledge@qt.io>
Diffstat (limited to 'src/widgets')
-rw-r--r--src/widgets/widgets/qmainwindowlayout.cpp23
1 files 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<QDockWidgetLayout *>(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);
}
}