How to move QDockWidget when topLevelChanged?
-
Hello everyone!
My problem is that when I drag QDockWidget, it always appears floating on the primary screen, regardless of where my main window is. This behavior is observed even in an empty Qt project (Qt 6.3.2, Windows 10) with QMainWindow and QDockWidget's only, so the only thing I can do here is to move QDockWidget somehow when
QDockWidget::topLevelChanged
is emitted .
But nothing helps with moving it. Here is what I've tried, of course not at the same time:CDockWidget::CDockWidget() : QDockWidget() { setScreen->(QGuiApplication::screens()[1]); //no effect connect(this, &QDockWidget::topLevelChanged, [this](bool) { auto screen = QGuiApplication::screenAt(QCursor::pos()); auto geom = screen->availableGeometry(); QPoint pos = { (geom.width() - width()) / 2, (geom.height() - height()) / 2 }; QRect dockGeom = { pos, size() }; setGeometry(dockGeom); //no effect move(pos); //no effect move(-50000, -50000); //no effect setGeometry(0, 0, 500, 500); //dock widget appears floating on the same place and has size 500, 500 hide(); move(pos); show(); //no effect setScreen->(QGuiApplication::screens()[1]); //no effect }); }
Any ideas how can I achieve my goal?
-
@Christian-Ehrlicher
Thank you, it helped!
In fact, these two commits contained what I needed:
Fix dragging a docked QDockWidget [REG-fix]
430985: Refix QDockwidget drag out dockwidget -
@bibasmall said in How to move QDockWidget when topLevelChanged?:
Any ideas how can I achieve my goal?
Try with Qt 6.5. If the problem still occous see if there is a bug report about it already and if not create one.
-
@Christian-Ehrlicher
I've found it here:
QTBUG-106064[REG] Undocking QDockWidget with drag misplaces it (a lot)
Sadly I can't use fresher versions because of the second target platform, so it seems I should checkout 6.2.7.
But I would be fine with additional manipulations that can move the widget, because these two actions (undocking and moving) don't look connected. -
The patch is trivial - so when you already compile Qt by yourself you can apply it.
-
@Christian-Ehrlicher
Thank you, it helped!
In fact, these two commits contained what I needed:
Fix dragging a docked QDockWidget [REG-fix]
430985: Refix QDockwidget drag out dockwidget -