如何清除父小部件中的所有小部件? [英] How to Clear all the Widgets in Parent Widgets?
本文介绍了如何清除父小部件中的所有小部件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用构造函数QWidget(QWidget *parent)
.这个父小部件包含很多子小部件.我需要在运行时从父级清除所有子级小部件.我该怎么做?
I am using the constructor QWidget(QWidget *parent)
. This parent widget contains a lot of child widgets. I need to clear all the child widgets from the parent at runtime. How can I do this?
推荐答案
您可以在父小部件类中使用以下内容:
You can use the following in your parent widget class:
QList<QWidget *> widgets = findChildren<QWidget *>();
foreach(QWidget * widget, widgets)
{
delete widget;
}
这篇关于如何清除父小部件中的所有小部件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文