PDA

View Full Version : Properly show dynamically added widgets



powermax
16th June 2020, 00:20
Hi,

When I create a QWidget which contains a QVBoxLayout and I add another QWidget (with contents) inside of it and never change this, everything works as expected.
It is shown correctly (the sizes are correct) and it can be resized without problems (it expands).

But when I do not add the inner QWidget initially to the layout (before everything is shown the first time) and only add it later on when the program is already running and shown, the widget does not show unless I explicitly call setMinimumSize (or setFixedSize). Also it does not expand anymore when I resize the program.

What steps are needed to make it automatically show and resize when added dynamically during runtime (after the initial show)? (Something with SizeHints or ...?)
The functions update, show, updateGeometry, etc ... don't seem to be enough.
("If you add a child widget to an already visible widget you must explicitly show the child to make it visible" -> text from the documentation but this does not seem to be enough)

Thanks in advance

high_flyer
17th June 2020, 15:22
It could be that it is being added, and shown, but 0 or 2 pixel size.
It depends on the layout policies, and on the widgets size policies and constraints.
If you share the relevant code it might be easier to help.