简体   繁体   中英

Widgets auto positioning PyQt4

I have a layout in a class inherited from QtGui.QWidget window. Lets say I have three labels and a button , and when I click on a button , one of the Labels disappear. This spoils my QtGui.QWidget because the other two labels automatically resize. I wouldn't want that to happen. I want my labels to be placed as before , with only the third label disappearing. Any tips?

Simplified version of my code:

class a(QtGui.QWidget):
    def __init__(self):
        //Everything needed is done
        self.UI()

    def UI(self):
        layout = QtGui.QGridLayout(self)
        self.label1 = QtGui.QLabel('Label1')
        label2 = QtGui.QLabel('Label2')
        label3 = QtGui.QLabel('Label3')
        layout.addWidget(self.label1 , 0 , 0)
        layout.addWidget(label2 , 1 , 0) 
        layout.addWidget(label3 , 2 , 0)
        button = QtGui.QPushButton('Hide')
        button.clicked.connect(fun)

    def fun(self):
        self.label1.hide()

您可以将label1小部件放置在没有框架的QFrame内。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM