[Qt-interest] how do I Remove the Stretch item in a QVBoxLayout?

S. Aguinaga sa_jr at yahoo.com
Tue Oct 6 21:31:42 CEST 2009



Alessandro,
Thank you this works like a charm.

// Salvador


________________________________
From: Alessandro Portale <Alessandro.Portale at trolltech.com>
To: Qt-interest at trolltech.com
Sent: Wednesday, September 23, 2009 5:24:01 PM
Subject: Re: [Qt-interest] how do I Remove the Stretch item in a QVBoxLayout?

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
_______________________________________________
Qt-interest mailing list
Qt-interest at trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-interest


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20091006/04161f7f/attachment.html 


More information about the Qt-interest-old mailing list