What kind of widget is "newprofile_"? Is it a custom widget, a basic Qt widget or a complex widget composed of other widgets?
What kind of widget is "newprofile_"? Is it a custom widget, a basic Qt widget or a complex widget composed of other widgets?
newprofile_ is a class that inherits Qwidget. It contains another QWidget X which has buttons and frames. The frames will eventually display a Qwt plot. Its parent is a QMainWindow.
Depending on user choice, I show/hide X. When X is hidden, another Qwidget Y is shown in its place. Y is also a class that inherits QWidget and I use the same parent (QMainWindow). An instance of Y is created inside newprofile_.
So the display can change between X and Y but both are on newprofile_ widget.
Actually, while trying to explain all that, I realised that maybe the parent of Y should be newprofile_ and not QMainWindow. I changed my code and now the layout works without setMinimumSize() and without me having to do anything special.
Thanks wysota. Sometimes it helps just trying to explain the things I do.
A side note - for switching between X and Y you could use QStackedWidget. It would improve your design a little (as I assume you are creating/showing/hiding those widgets yourself).
I'm digging the subject, because you were certainly missing a layout or a size hint here somewhere, but it's hard to say where without knowing the details.
I only create the widgets once (I have 13 of them) and let the user select from a QTreeWidget which one to show. I need to do it this way since each type of widget can appear multiple times but present different info depending on it's location in the tree and user input.
I had a look at QStackedWidget. It displays arrows (to move between the widgets), which probably was the reason I chose not to use it and I'm not sure if the size of the scroll area will adjust for different widget sizes if I put them all in the stacked widget or just always show the biggest size.
Other than that it does seem like a good idea. I think the way I wrote the code is very similar to QStackedWidget just using show/hide instead of signals. I have to finish other parts of the application first but I will make a note to come back to this one and see if it makes a difference.
I think my original problem stemmed from not having the right parent to all those new widgets. Once that was fixed everything worked well and I didn't have to set anything more.
Bookmarks