Search code examples
qtqdockwidget

How to anchor QDockWidget to top right area?


There is a QMainWindow and two QDockWidgets. The first widget is docked to the top, the second - to the left. The result is that the first widget occupies full width and the second widget occupies the remaining area. I want to make it so that the second widget occupies the full height and the first - the remaining area.

To show this visually. "-" - the first widget, "|" - the second, o - central widget.

Default Qt behavior:

------
|ooooo
|ooooo
|ooooo

I need this:

|-----
|ooooo
|ooooo
|ooooo

Solution

  • Please take a look at the QMainWindow::​setCorner() documentation. This will allow you to customize corner -> dockwidget_area.

    For example, according to your question, you should call:

    QMainWindow * w = ...;
    w->setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
    

    to associate the top left corner with the left dockwidget area.

    simple!