QTableWidgets 内的单元格小部件在清理时会被删除吗?

发布于 2024-12-12 07:46:34 字数 335 浏览 3 评论 0原文

假设我用按钮填充 QTableWidget 的一些单元格:

ui->table->setCellWidget (i, 2, new QPushButton ("Details"));

稍后我将它们全部刮掉并再次执行:

ui->table->clear();

这些按钮会被自动删除吗?或者我是否需要存储它们的列表并手动删除?另外,我是否需要为每个按钮指定父级,如下所示:QPushButton ("Details", ui->table)

Suppose I fill some cells of a QTableWidget with buttons:

ui->table->setCellWidget (i, 2, new QPushButton ("Details"));

Just a little bit later I scratch them all and do it again:

ui->table->clear();

Will this buttons get deleted automagically? Or do I need to store a list of them and delete manually? Also, Do I need to specify parent for every button like this: QPushButton ("Details", ui->table)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

待天淡蓝洁白时 2024-12-19 07:46:34

表格小部件拥有该小部件的所有权。 文档指出:

设置要在给定行和列的单元格中显示的给定小部件,将小部件的所有权传递给表格。

您也不需要在创建时指定父级,这将是由 tablewidget 进行相应设置。

The table widget takes ownership of the widget. The documentation states this:

Sets the given widget to be displayed in the cell in the given row and column, passing the ownership of the widget to the table.

You also don't need to specify a parent on creation, that will be set by the tablewidget accordingly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文