Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
589 views
in Technique[技术] by (71.8m points)

python - How to hide a layout in 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...