Hi,
Just like the title.
Thanks very much!
Hi,
Just like the title.
Thanks very much!
And the previous layout should not be deleted, because it may be used again.
Sorry
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.
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.
Why (and where) do you think my previous post was not clear enough?
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 ).
So you do want to remove widgets from the layout. Read my post where I wrote about removing widgets from the layout.
Maybe you just want a QStackedLayout?They will be displayed on a group box alternatively, by changing the layout of the group box ( if that can be accomplished ).
I use example to express my idea~So you do want to remove widgets from the layout. Read my post where I wrote about removing widgets from the layout.
For example, the class is declared like:
Qt Code:
{ ... QVBoxLayout *layout; QLabel *label; ... }; ... { ... layout->addWidget(label); ... } ...To copy to clipboard, switch view to plain text mode
And there two instances A and B, they will be displayed on QGroupBox, say C
First, display A on C
Qt Code:
... C.setLayout(A.layout); // here the label of A will be displayed on C ...To copy to clipboard, switch view to plain text mode
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!
Qt Code:
while(!hlayout->isEmpty()){ hlayout->removeItem(hlayout->itemAt(0)); }To copy to clipboard, switch view to plain text mode
that works for me..
i was searching for a clear or reset function too..
Bookmarks