Solved how to auto-size dialog depending on which "stack" is front?
-
i have a dialog with a QStackedWidget, i switch between them with a QListWidget. I'd like the dialog to auto-size itself (animated wooshing a bonus!) based on which stack is "front". I've put vertical Spacers at the bottom of each stack, to top-justify each stack, but i'd rather resize the dialog. here's a couple stacks:
as you can see, the LAST one is the tallest one, which currently defines the minimum size of the dialog.
Is there a way to, when the user causes a stack to come to front, tell the dialog to minimize it's vertical size based on the front stack?
-dave
-
this is what worked:
QWidget *pageP; for (int i = 0; i < stackP->count (); ++i) { pageP = stackP->widget(i); pageP->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Ignored); } pageP = stackP->widget(stackIndexL); pageP->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred); stackP->adjustSize(); adjustSize();
-
@davecotter said in how to auto-size dialog depending on which "stack" is front?:
Is there a way to, when the user causes a stack to come to front, tell the dialog to minimize it's vertical size based on the front stack?
If I'm not wrong, setting the resize policy of the dialog to
QSizePolicy::MinimumExpanding
and callingQWidget::adjustSize
after you switched the stack widget might do the trick. -
i've set the size policy on the QDialog widget like this:
and here is my code:
if I un-comment that
adjustSize();
line, then my dialog gets much WIDER, and does not get shorter.it seems that it is finding the minimum size of ALL stack panels, and using that, instead of only finding the minimum size of the CURRENT (front most) stack panel?
-
Eh, I may be wrong, that's tricky. What I'd suggest you try is to remove the vertical stretches and set the policy of each of the stacked widgets to
Minimum
. If that doesn't do it, I'm out of ideas. -
yep nope. seems the minimum size of the dialog is determined by the stack panel with the maximum size, not the stack panel that is in front. i do not see a way around it.
-
can anyone contradict that? i don't yet have access to debugging the source code so i can't tell if there's a way out of this
-
If you prepare a simplistic compileable example that reproduces it, I can run it through on Linux.
-
Hi,
Take a look at this stack overflow thread. It shows a technique to achieve what you want.
-
this is what worked:
QWidget *pageP; for (int i = 0; i < stackP->count (); ++i) { pageP = stackP->widget(i); pageP->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Ignored); } pageP = stackP->widget(stackIndexL); pageP->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred); stackP->adjustSize(); adjustSize();