PDA

View Full Version : How to reset a QGroupBox's layout?



dongli
4th July 2009, 07:49
Hi,

Just like the title. :)

Thanks very much!

wysota
4th July 2009, 07:53
The title doesn't really say much...

dongli
4th July 2009, 07:58
And the previous layout should not be deleted, because it may be used again.

dongli
4th July 2009, 08:10
The title doesn't really say much...

Sorry:o

The problem is one QGroupBox is created, and set its layout to a QVBoxLayout, later the layout should be changed to another QVBoxLayout ( the content is different ), so how to change QGroupBox's layout without deleting the previous QVBoxLayout?

Execuse my poor English.

wysota
4th July 2009, 09:02
Remove all the "old" widgets from the layout using QLayout::removeWidget() and add all the "new" ones using QLayout::addWidget(). You don't need to set a new layout, the one that's already there is ok.

dongli
4th July 2009, 09:30
Remove all the "old" widgets from the layout using QLayout::removeWidget() and add all the "new" ones using QLayout::addWidget(). You don't need to set a new layout, the one that's already there is ok.
I made a class with a layout menber, and add other widgets in the class to this layout. Because I think this may be easier to represent the content of the class in different places. So any suggesion?

Thanks very much!

wysota
4th July 2009, 09:34
Why (and where) do you think my previous post was not clear enough?

dongli
4th July 2009, 09:48
Why (and where) do you think my previous post was not clear enough?
Because you said all the widgets should be removed, that is not what I wish. And the class which I made contains its own layout, it can be used as layout manager by external widgets.

wysota
4th July 2009, 10:02
Because you said all the widgets should be removed, that is not what I wish.

Ok, so you want to change one vertical layout to another vertical layout and both layouts should contain the same widgets. Is that correct? If so, then what exactly do you want to change? Because for me it seems that if you have two vertical layouts showing the same widgets in the same order then those layouts are identical.

dongli
4th July 2009, 10:08
Ok, so you want to change one vertical layout to another vertical layout and both layouts should contain the same widgets. Is that correct? If so, then what exactly do you want to change? Because for me it seems that if you have two vertical layouts showing the same widgets in the same order then those layouts are identical.
No, the widgets are not the same! For example, there are two instances of that class, A and B. Both of them have a vertical layout, and several other widgets like spin box. They will be displayed on a group box alternatively, by changing the layout of the group box ( if that can be accomplished ).

wysota
4th July 2009, 10:19
No, the widgets are not the same!
So you do want to remove widgets from the layout. Read my post where I wrote about removing widgets from the layout.


They will be displayed on a group box alternatively, by changing the layout of the group box ( if that can be accomplished ).

Maybe you just want a QStackedLayout?

dongli
4th July 2009, 10:34
So you do want to remove widgets from the layout. Read my post where I wrote about removing widgets from the layout.

I use example to express my idea~ :o

For example, the class is declared like:


class MyWidget : public QWidget
{
...
QVBoxLayout *layout;
QLabel *label;
...
};
...
MyWidget::MyWidget(QWidget *parent)
: QWidget(parent)
{
...
layout->addWidget(label);
...
}
...


And there two instances A and B, they will be displayed on QGroupBox, say C

First, display A on C


...
C.setLayout(A.layout); // here the label of A will be displayed on C
...


Then I want to display B on C alternatively, my question is how, and the layout of A should not be deleted.

Thanks for your patience! :D

wysota
4th July 2009, 10:59
I already answered your question.

oniboni
4th June 2010, 12:48
while(!hlayout->isEmpty()){
hlayout->removeItem(hlayout->itemAt(0));
}


that works for me..
i was searching for a clear or reset function too..