如何在 PyQt 中隐藏布局? [英] How to hide a layout in PyQt?

查看:51
本文介绍了如何在 PyQt 中隐藏布局?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

My code contains a vertical box layout which is a combination of a vertical box layout in left and one at right. I was wondering if there is a way to hide the left layout with all its widgets when a certain signal is emitted.

推荐答案

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

You could cheat and use a frame instead of a layout: It works exactly the same way, except for the fact you have to set a layout on the frame for it to work properly. You can then do the following:

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()

我正在寻找这样的解决方案,希望这会有所帮助:)

I was looking for a solution like this, hope this helps :)

这篇关于如何在 PyQt 中隐藏布局?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆