1
votes

How can I get the location of a QDockWidget in its current dock area? For example, if I have a dock area split in half with two widgets, how can I query the framework to find out which one is on top and which one is on bottom? The user can, of course, be dragging and dropping QDockWidgets dynamically.

1

1 Answers

2
votes

You can determine which dock is above the other by checking the value of both of their geometries.

if you have two docks,

QDockWidget dock1;
QDockWidget dock2;

then the one on top will have the lesser y() value (since the top left corner of the screen is (0,0) and the y value increases as you move towards the bottom)

if(dock1.geometry().y() < dock2.geometry().y())
{
     qDebug() << "Dock 1 is above Dock 2";
}

Left and right can be calculated using the x() value. If the geometries are equivalent, the docks are tabbed, and the one on top can be determined by the value of isVisible().

If you want to recalculate which dock is on top in relation to user input, I would recommend connecting to the QDockWidget::dockLocationChanged signal, since it will be emitted whenever a dock changes dock location, or is moved within its current location, which should cover all the necessary cases.