[Qt-interest] how do I Remove the Stretch item in a QVBoxLayout?
Alessandro Portale
Alessandro.Portale at trolltech.com
Thu Sep 24 00:24:01 CEST 2009
If you instead of using QBoxLayout::addStretch(), use
QBoxLayout::addSpacerItem() in order to add a QSpacerItem, you can
remove that QSpacerItem afterwards with QBoxLayout::removeItem().
<code>
#include <QtGui>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QWidget outerWidget;
QVBoxLayout *layout = new QVBoxLayout;
outerWidget.setLayout(layout);
layout->addWidget(new QGroupBox("One"));
QSpacerItem *spacer = new QSpacerItem(0, 20,
QSizePolicy::Ignored, QSizePolicy::MinimumExpanding);
layout->addSpacerItem(spacer);
layout->addWidget(new QGroupBox("Two"));
// this removes the spacer
layout->removeItem(spacer);
outerWidget.show();
return a.exec();
}
</code>
I hope that helps :)
Alessandro
S. Aguinaga schrieb:
> Hello Fellows:
>
> I have a QVBoxLayout that has some widget and ends with
> myVLayout->addStretch(1); One of the widgets on this layout is a
> comboBox, so depending on what is selected on the combo box, I need to
> re-layout the VBox, but when I can't seem to find a way to removeItem or
> removeWidget for this "Stretch" item, so when I add new widgets to this
> layout, They appear at the bottom of the VBoxLayout (see below):
>
> +------------------+
> | widget 1 |
> | widget 2 |
> | /\ |
> | || |
> | stretch |
> | || |
> | \/ |
> | new widget |
> +------------------+
>
> How do I remove the stretch only?
>
> // Salvador
More information about the Qt-interest-old
mailing list