[Qt-interest] Nested widget disappears when I add a spacer item / dynamically adding widgets to widgets
Tony Rietwyk
tony.rietwyk at rightsoft.com.au
Wed May 26 14:02:14 CEST 2010
Kustaa,
I sent a response to the list and received it...
And I think the answer is the same in this case as well !
Tony.
> -----Original Message-----
> Related to my unanswered question yesterday here is a more specific
> test case:
>
> I've got following simple code:
>
> gLayout = new QBoxLayout(QBoxLayout::TopToBottom, this);
>
> QWidget* top=new QWidget();
> new QPushButton("A",top);
>
> gLayout->addWidget(top);
>
> gLayout->addWidget(new QPushButton("B"));
>
>
> This works, and displays two buttons, A and B.
>
> But if I add a spacer to the mix by adding a single line:
>
> gLayout->addItem(
> new QSpacerItem(20, 40, QSizePolicy::Minimum,
> QSizePolicy::Expanding));
>
> then button A disappers!
>
> What is going on?
>
> Note that button A is a child of the widget 'top' which is what I add
> to the layout. If I add A button to gLayout directly then there is no
> problem but inmy bigger application that is not feasible
> because 'top' is a
> form maintained with Qt Designer...
>
> So what is the proper way to add a widget that contains widgets
> to a layout?
>
> br Kusti
More information about the Qt-interest-old
mailing list