python - 如何在 PyQt 中隐藏布局?

标签 python layout pyqt pyqt4 signals-slots

我的代码包含一个垂直框布局,它是左侧垂直框布局和右侧垂直框布局的组合。我想知道是否有一种方法可以在发出特定信号时隐藏左侧布局及其所有小部件。

最佳答案

您可以欺骗并使用框架而不是布局:它的工作方式完全相同,只是您必须在框架上设置布局才能正常工作。然后您可以执行以下操作:

from PyQt5 import QtWidgets

# create the frame object.
frame = QtWidgets.QFrame()

# you can do this with any layout - vbox, grid, hbox... 
# There will not be more than one item in it anyway.
ly = QtWidgets.QVBoxLayout()
frame.setLayout(ly)

# we're assuming here that parent_layout is some outside layout object.
parent_layout.addWidget(frame)

# hide the frame and its contents
frame.hide()
# show the frame and its contents
frame.show()

我一直在寻找这样的解决方案,希望对您有所帮助:)

关于python - 如何在 PyQt 中隐藏布局?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29275319/

相关文章:

python - 写入文件时出现 IOError

java - 如何将Java选项卡式面板添加到自定义布局中?

python - 在 REAPER 内多次运行 PyQt4 脚本会导致 SIP 错误

python - 如何正确缩放 QGraphicsScene

python - Django1.4 : How to use order_by in template?

python - 如何使用QtWebKit设置浏览器的大小

python - AzureML 架构 "list index out of range"错误

java - 我怎样才能在 NestedScrollView 中有一个 ListView

java - 布局完成后调用的方法?

python - PyQt:使用 setRect() 控制 QGraphicsRectItem 的位置