Monday, 4 July, 2011
Qt Trick
I was looking for a simple way to delete all subwidgets and layout from a Qt container widget today.
Mark pointed me to a post that suggested a method, and I thought others might benefit from a code example of how I ended up solving this.
void MyWidget::clearSubWidgets()
{
QObjectList ch = children();
foreach (QObject *o, ch)
{
QObject *todel = qobject_cast<QWidget *>(o);
if (!todel)
todel = qobject_cast<QLayout *>(o);
if (todel)
delete todel;
}
}
Feel free email in suggested improvements
0 Comments
Please use the DP Forums for further discussion of this topic.



