我的代码包含一个垂直框布局,它是左侧垂直框布局和右侧垂直框布局的组合。我想知道是否有一种方法可以在发出特定信号时隐藏左侧布局及其所有小部件。
最佳答案
您可以欺骗并使用框架而不是布局:它的工作方式完全相同,只是您必须在框架上设置布局才能正常工作。然后您可以执行以下操作:
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/