[SOLVED] Help with size policy docked vs. undocked
-
I have a widget which contains only a single FrameWidget (onto which I draw a graphic, but that's not important for this discussion)
This widget can be docked into the main window.
When it is docked, I would like to ensure that the FrameWidget is a fixed 300x300 px.. But when the user undocks it, I'd like to ensure that the FrameWidget expands to fill the size they make the undocked window..
How can I make it behave like this? If I set it fixed, when undocked, the FrameWidget stays at 300x300 regardless the size the user makes the window.. If I set it to preferred or expanding, it works as I'd like while undocked, but when docked it fills the space, rather than being the fixed 300x300.
Thanks!
-
You can connect to the topLevelChanged signal of the dock and change the policy for docked or undocked state there.
-
actually I found that if I leave the size policy at maximum in both directions, when I trap the topLevelChanged signal I can then change the maximum height and width values, and get the desired effect. (it I'm not toggling the size policy, rather, specifying new max height and width values.)
seems to work, but "Feels like" it's not the right Qt way..
-
Every widget has its own policy, so you can apply it to whatever you want. In your case you want to control the size of the frame so set the policy on the frame, i.e. something like this:
connect(theDock, &QDockWidget::topLevelChanged, someObject, &SomeClass::someAdjustPolicyFunc); SomeClass::someAdjustPolicyFunc(bool topLevel) { if (topLevel) someImageFrame->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); else someImageFrame->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); }
-
Yes, starting with Qt5 there's a new connect syntax with no macros (yay!). I highly recommend switching to it, if not just for the compile time type and parameter checking it does. More info here.