简体   繁体   English

QT清除小部件内容

[英]QT clear widget contents

I have QWidget renameWidget which is referred to as ui->renameWidget. 我有QWidget renameWidget,它被称为ui-> renameWidget。 Within this, I have a QVBoxLayout *renamebox and within this I have several labels and textedits. 在这个中,我有一个QVBoxLayout * renamebox,在这里我有几个标签和短信。

What I need to happen is that when I hit a button to submit these textedits, I need everything within the QWidget to be deleted. 我需要做的是当我按下按钮提交这些短信时,我需要删除QWidget中的所有内容。 This will give the effect of the box being emptied or cleared. 这将使盒子被清空或清除。

I've tried to just delete the vboxlayout and I've also tried this: 我试图删除vboxlayout,我也试过这个:

qDeleteAll(ui->renameWidget->findChildren<QVBoxLayout *>());

Nothing has worked, any ideas? 没有任何效果,任何想法?

try 尝试

 qDeleteAll(ui->renamebox->findChildren<QLabel *>());
 qDeleteAll(ui->renamebox->findChildren<QTextEdit *>());

Although it's typically better to call deleteLater on most QObject based classes because it allows the objects to be cleaned up in the next pass through the event loop, not in the middle of an event being processed 虽然在大多数基于QObject的类上调用deleteLater通常更好,因为它允许在下一次通过事件循环时清理对象,而不是在处理事件的过程中

qDeleteAll(ui->renamebox->children()); would delete all children. 会删除所有孩子。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM