I have an image as my label in a PyQt4 Program. This program also contains some push buttons. Now, when I maximize my window, though the label gets expanded but the push button retain their place. I want that the push buttons should maintain their relative position with respect to the label, even when maximized.
My code is as follows:
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
self.centralwidget = QtGui.QWidget(MainWindow)
MainWindow.setCentralWidget(self.centralwidget)
lay = QtGui.QVBoxLayout(self.centralwidget)
self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
self.label = QtGui.QLabel(self.centralwidget)
self.label.setText(_fromUtf8(""))
self.label.setPixmap(QtGui.QPixmap(_fromUtf8("Capture.PNG")))
self.label.setObjectName(_fromUtf8("label"))
self.label.setScaledContents(True)
lay.addWidget(self.label)
self.Langdon = QtGui.QPushButton(self.centralwidget)
self.Langdon.setGeometry(QtCore.QRect(290, 90, 75, 23))
self.Langdon.setObjectName(_fromUtf8("Langdon"))
self.ChainLakes = QtGui.QPushButton(self.centralwidget)
self.ChainLakes.setGeometry(QtCore.QRect(50, 290, 85, 23))
self.ChainLakes.setObjectName(_fromUtf8("ChainLakes"))
if __name__ == "__main__":
import sys
app = QtGui.QApplication(sys.argv)
MainWindow = QtGui.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
How shall I modify my code??
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…