Burton
Burton

Reputation: 71

How to resize QDockWidget

I have created one application without centralwidget in my mainwindows, and shown as maximized:

setCentralWidget(0);
setWindowState(Qt::WindowMaximized);

In my mainwindow, I have three docks. The dock1 is set to be docked to leftDockWidgetArea, the dock2 and dock3 are set to be docked to the rightDockWidgetArea. Also, I arrange dock2 and dock3 by

splitDockWidget(ui->dock2, ui->dock3, Qt::Horizontal);

So I got a results that the ratio of the width of the three docks are 2:1:1.

My question is how could I set the width of the three docks so that they can be arranged as 1:4:1.

Suppose my screen's width is 1024. I have tried

ui->dockWidget_PrimeVis->resize(1000, 1000);

This does not work since I found some people say the size of docks are controlled by mainwindow. So I found I could call resizeDocks in mainwindow such as

resizeDocks({ ui->dock1, ui->dock2,ui->dock3}, { 150,600,150 }, Qt::Horizontal); 

And it does not work. Also, since each dock contains one subclassed widget, I also tried to set the size to each subclassed widget, again, does not work.

Since we can manually change the size of each dock by GUI, so I believe there should be a way to set the size of each dock with codes, right? Anyone has a clue?

Upvotes: 3

Views: 4431

Answers (1)

Tim Körner
Tim Körner

Reputation: 385

The official documentation states the following:

A QDockWidget acts as a wrapper for its child widget, set with setWidget(). Custom size hints, minimum and maximum sizes and size policies should be implemented in the child widget. QDockWidget will respect them, adjusting its own constraints to include the frame and title. Size constraints should not be set on the QDockWidgetitself, because they change depending on whether it is docked; a docked QDockWidget has no frame and a smaller title bar.

Solution:

Just subclass the widget you are showing inside of the dockwidget. You can than overload different methods to change the size hint. For example: QWidget.minimumSizeHint()

Not Tested:

You could also just try to set the minimum size. But i do not know if this works.

Upvotes: 3

Related Questions