[Qt-interest] remove buttons from a QVBoxLayout
Tamas Nagy
ngy_tms at yahoo.com
Sun May 16 21:55:57 CEST 2010
Hello!
I use QVBoxLayout and I store the buttons in a buttonlist:
QList<QPushButton*> * buttonlist = new QList<QPushButton*>();
It must be on the heap!!!
This buttonlist contains 50 buttons.
If i call AddFirstButtons() it puts the first 10 buttons into the
QVBoxLayout, if i call AddSecondButtons(), it pust the second 10 buttons (from 10-20) into the QVBoxLayout.
If i call AddSecondButtons(), i should remove all items from the QVBoxLayout, it is successful, but the buttons stay there, because, the cannot be deleted by reference, because they must stay in the QList.
So the only thing i want to achive is to remove them from the gui.
They float there without parent, because they are removed from the layout.
It is ok, but they are not removed from the GUI.
If i draw the new buttons, and new buttons slip down a little, i can see the old buttons.
I call repaint on the involving groupbox, so it is sure, that it is not a repaint problem, the buttons stay there.
verticalbox->takeAt(i)->setVisible(false);
does not work it says there is no member setVisible
Tamas
--- On Sat, 5/15/10, Oszkar Ambrus <oszkar.ambrus at deri.org> wrote:
> From: Oszkar Ambrus <oszkar.ambrus at deri.org>
> Subject: Re: [Qt-interest] QVBox removeItem
> To: "Tamas Nagy" <ngy_tms at yahoo.com>, "Qt Interest List" <qt-interest at trolltech.com>
> Date: Saturday, May 15, 2010, 8:01 PM
> Hi,
> > I have Qt 4.6, and i want to remove all children of
> the widget.
> > I would like to write a Clear() function.
> >
> > If i switch the array to dynamically allocated, so i
> use
> > QList<QPushButton*> buttons = new
> QList<QPushButton*>
> >
> > These buttons are added to the QVBox.
> >
> > And i try removeItem which is not documented on the Qt
> website.
> >
> > while(vbox->children->count())
> > {
> > vbox->removeItem(0);
> > }
> >
> > Is it correct?
>
> It is strongly advised to use QVBoxLayout, not Q3VBox.
>
> Then you can write:
> while( layout->count() ) {
> layout->removeItem( layout->itemAt(0)
> );
> }
>
> Of course you have to watch for memory leaks, that is to
> properly delete those widgets if they have no parent.
>
>
> Regards,
> -- Oszkár Ambrus
>
> "Whoever believes in the Son [Jesus Christ] has eternal
> life"
> (John 3:36)
>
More information about the Qt-interest-old
mailing list