Qt - 更改 QWidget 布局
假设我们有一个 QWidget
和一个名为 general_layout
的 QLayout
,其中包含其他小部件和布局。 general_layout
设置为 QWidget
布局,如下所示:
setLayout(general_layout)
现在我应该更改 QWidget
的内容。我怎样才能做到这一点?我尝试删除并创建 QWidget
的新布局,并将该新布局设置为 QWidget
的布局,但无法成功完成我的意图。
这是我的代码:
delete general_layout;
general_layout = new QHBoxLayout;
general_layout->addLayout(some_layout);
myQWidget->setLayout(general_layout);
Let's consider we have a QWidget
and a QLayout
named general_layout
that contains other widgets and layouts. general_layout
is set as the QWidget
layout like this:
setLayout(general_layout)
Now I should to change the content of QWidget
. How can I do that? I have tried to delete and create a new layout for the QWidget
and that new layout set as a layout of the QWidget
, but could not complete my intentions successfully.
This is my code:
delete general_layout;
general_layout = new QHBoxLayout;
general_layout->addLayout(some_layout);
myQWidget->setLayout(general_layout);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是删除布局时布局的小部件不会被销毁。这会导致 myQWidget 的所有子窗口小部件仍然存在,尽管没有布局。
解决办法很简单:添加一个
after
The problem is that the widgets of a layout are not destroyed when deleting a layout. This results in all child widgets of myQWidget still being present, be it without a layout.
The solution is simple: add a
after