删除qt中的子布局?
在 PyQt 4.5 中,我在另一个布局中有一个布局。我想从其父级中删除子布局并隐藏它。我可以说 parent_layout.removeItem(child_layout)
从其父级中删除布局,但它仍然显示在小部件上。我找不到任何方法可以一步隐藏它,因为 QLayout
没有像 QWidget
那样的 hide()
方法。
In PyQt 4.5, I have a layout inside another layout. I'd like to remove the sublayout from its parent, and hide it. I can say parent_layout.removeItem(child_layout)
to remove the layout from its parent, but it still shows on the widget. I can't find any way to hide it in one step, as QLayout
doesn't have a hide()
method like QWidget
does.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
简单的解决方案是拥有一个内部小部件,而不是内部布局。您可以将所需的布局分配给小部件,然后在需要时删除/隐藏小部件。一个好的经验法则是,如果您只想安排小部件的显示方式,请使用布局;如果您想将它们隐藏/显示为一组,请使用小部件。
The easy solution would be to have an interior widget, not an interior layout. You could assign the layout you desire to the widget, then just remove/hide the widget when you want to do so. A good rule of thumb is if you just want to arrange how widgets appear, then use a layout; if you want to hide/show them as a group, use a widget.
在 flupke 对
#qt
的帮助下,我想出了:假设所有子布局的子项都是小部件。有更简单的解决方案吗?
With some help from flupke on
#qt
, I came up with:Which assumes all the child layout's children are widgets. Is there a simpler solution?