2
votes

I heavily use dock widgets to let the user arrange the tools the way she wants. Some of my dock widgets contain static controls (FS, fixed vertical size), others depict images, the larger the better (ES, expanding vertical size).

The problem I face is that I cannot get a configuration of size hints that lets me do this:

  1. Make the variable size dockwidgets as large as possible
  2. Let all dockwidgets tab with each other without buggy behavior

For 1., I can set the Vertical Policy of all FS's content widgets to "Fixed". This will force the container to use all free space for variable size widgets. However, as soon as a ES widget is tabbed with a FS widget, while the FS widget is not shown, I get stubborn behavior at best (user cannot adjust size) and buggy behavior at worst (when adjusting size, drawing errors happen, actual size did not change).

For 2., I can set all Vertical Policies to either "Preferred" (FS) or "Expanding" (ES). This should give preference to the ES, but it doesn't. I also tried playing with Vertical Stretch to no advance (while it is helpful in other scenarios where no DockWidgets are involved).

I am stuck with a situation where by default, the application wastes space and the user has to do several adjustments to the dockwidget sizes whenever the window size/layout changes. It is very tedious and counter-intuitive.

How do I do this right?

And a follow-up question: How to teach a DockWidget that it's contents have a specific aspect ratio?

1
I doubt there is a solution. QDockWidget's behavior is hardcoded, and there are too few options to control it. If you want full control on dock widgets' behavior, you need to implement it yourself.Pavel Strakhov

1 Answers

0
votes

I found the biggest issue was that I used custom widgets for display which would not overload the virtual QSize sizeHint() const method.

Overloading this method and returning a high number, e.g. 500, for the vertical size, helped the layout considerably.

It seems that the (private API) QMainWindowLayout does an initial guess on best dock widget sizes and then sticks to that. In the same course, it seems to ignore the differences between Preferred and Expanding policies or Stretch settings.

By providing a large sizeHint the custom widget gets better balance with stock Qt Widgets (e.g. QListView) that do the same.

The result is acceptable, but far from perfect.