I’ve seen some strange things when trying to remove QWidgets from a QLayout while using code such as:
Code:
MyWidget->layout()->removeWidget(AnotherWidget); |
Sometimes AnotherWidget wouldn’t be removed, sometimes it would display only part of it.
After a bit of searching I came across a different solution that worked a treat. The below code removes all widgets MyWidget’s layout.
Code:
while((QLayoutItem *child = MyWidget->layout()->takeAt(0)) != 0) | |
{ | |
delete child->widget(); | |
delete child; | |
} |
And if you wanted to only remove a single widget from the layout:
Code:
while((QLayoutItem *child = MyWidget->layout()->takeAt(0)) != 0) | |
{ | |
if(child == AnotherWidget) | |
{ | |
delete child->widget(); | |
delete child; | |
} | |
} |
Source: http://www.qtcentre.org/archive/index.php/t-21561.html
This post has 1 feedback awaiting moderation...