PDA

View Full Version : How delete contents in QGridLayout?



aomegax
1st August 2010, 08:07
Hi, I am a new user of the forum and a beginner programmer in Qt.
I have 2 problems.
First:
I have a QGridLayout in which I insert my custom widget. When I add a new widget to the list I must refresh it. So how can I delete all widget conteined in QGridLayout?

I have tried with the following code:



while(grid->layout()->count() > 0) {
grid->layout()->removeWidget(grid->layout()->itemId(0)->widget());
}


but really the widgets aren't removed. How can I solve?

Second:
I must do a grid in n rows x m cols in which cells I must add my custom widget. I have to add them from top-left, filling before the entire first row, then the second and so on...how can I do?
Now I have done as before, but the widgets are placed in column.


Thanks a lot

tbscope
1st August 2010, 14:26
Layouts do not contain widgets.
They contain layout items.

So, if you want to delete the widgets, first browse through the list of items, delete the widget or child layout in the item, then remove the item itself.

In pseudo code:


while layout has items
layoutitem i = layout.takeat(0) //takes the first item
if (i.widget())
delete i.widget();
if (i.layout())
delete i.layout();

delete i;
loop

aomegax
1st August 2010, 16:56
Thanks...I have solved my first problem...

now I have this dialog:
http://img825.imageshack.us/img825/9126/schermata3v.png
how can I know in partend widget which of children widget I have selected with radio button? I must know item id to modify information.

however thank you!