PDA

View Full Version : Applying size constraints to dock widgets



fullmetalcoder
8th September 2007, 18:08
I'm facing a small but very annoying trouble : I add dock widgets to a QMainWindow and I want them to be as small as possible (i.e. to leave more space to the central widget...) I set the size policy of the dock and of its widget to QSizePolicy::Maximum while setting the policy of the central widget to QSizePolicy::Expanding but there's still a waste of space (my goal is to make the dock as small as possible by default). Besides, if I use QSizePolicy::MinimumExpanding instead on the central widget, the layout goes mad and the main window gets bigger than the available screen space...

Any hints?

marcel
8th September 2007, 18:19
What about if you set minimum heights for the docks and also use QSizePolicy::Minimum, while keeping the central widget at QSizePolicy::Expanding?

This way the docks will get a size hint = their minimum size while the central widget will be allowed to exercise it's expanding size policy.

I am not sure it works. Dock sizes are very sensitive to restrictions especially because of the main window's dock widget layout( it is somewhat complex and doesn't behave well for few cases, such as setting minimum sizes - both width and height for the docks - doing this will result in peculiar dock movement behavior and also empty space between the docks and/or the docks and central widget).

Any way, you can try it.

Regards

fullmetalcoder
8th September 2007, 19:45
What about if you set minimum heights for the docks and also use QSizePolicy::Minimum, while keeping the central widget at QSizePolicy::Expanding?
This doesn't help...


Any way, you can try it.
I tried a couple more things (including reimp of sizeHint()) without any kind of success and I finally decided to take a look at the dock widgets example... It did it!!! :) The Trolls, knowing what they were doing I guess ;), used a special trick of theirs : create a custom QFrame-based class to hold the "real" content of your widget, subclass its sizeHint() method according to your needs and set it as the widget() of your dock widget... It solved it all and I thought it might be worth mentioning in case someone stumble across the same issue...

wysota
8th September 2007, 23:38
Well... yes, it seems like a trollish idea... Hiding everything useful from end users and exposing a limited interface instead of using it themselves ;)

dyams
23rd October 2007, 13:22
Hi Could you share that code here
Iam using Qt 4.3.2 I dont see a frame being used in the dockWidgets example here

I think we are refering 2 different versions of Qt here.
Please share a snip of that code


This doesn't help...


I tried a couple more things (including reimp of sizeHint()) without any kind of success and I finally decided to take a look at the dock widgets example... It did it!!! :) The Trolls, knowing what they were doing I guess ;), used a special trick of theirs : create a custom QFrame-based class to hold the "real" content of your widget, subclass its sizeHint() method according to your needs and set it as the widget() of your dock widget... It solved it all and I thought it might be worth mentioning in case someone stumble across the same issue...