PDA

View Full Version : [SOLVED] widgets moving after setVisible(false) in aQLayout



dmcr
3rd February 2010, 14:54
Hello,

I very much like Qt, witch works very well for me up to now, and allow fast coding!

I have a very simple pb tough :
Given some widget displayed in a layout, i would like to hide some of them without moving others, in a QVBoxlayout for example.

I did not find the answer of this elementary pb.
Thanks in advance.

dmcr

psih128
3rd February 2010, 16:17
Consider putting a spacer along with the item in a separate V or H layout, and then adding this layout to your main layout. This way the spacer would fill all the free space when the item is hidden.

dmcr
3rd February 2010, 17:04
//this not so obvious thing for me was not so long!

QWidget *abWidget::createWidgetWithSpacer( QWidget* w)
{
QWidget *wdgt = new QWidget;
QHBoxLayout *l = new QHBoxLayout;

l->addWidget( w, 0, Qt::AlignCenter ) ;
l->addSpacing(w->width());

wdgt->setLayout(l);
return wdgt;
}