简体   繁体   中英

How do I create a layout that can contain buttons in PyQt5?

I am trying to create a window that has a banner with two buttons underneath. I would like the layout to be like this:

图片

Where I could put buttons in the green and blue boxes and an image in the red box. How would you go about doing something like this?

I think the fastest and easiest way is to use Qt Designer .

Once there, basically, create your window ( QWidget for example) and define your layout QVBoxLayout or QHBoxLayout before adding your buttons QPushButton or images QImage or QIcon .

    self.verticalLayoutWidget = QtWidgets.QWidget(borreme)
    self.verticalLayoutWidget.setGeometry(QtCore.QRect(19, 30, 351, 111))
    self.verticalLayoutWidget.setObjectName("verticalLayoutWidget")
    self.verticalLayout = QtWidgets.QVBoxLayout(self.verticalLayoutWidget)
    self.verticalLayout.setObjectName("verticalLayout")
    self.label = QtWidgets.QLabel(self.verticalLayoutWidget)
    self.label.setObjectName("label")
    self.verticalLayout.addWidget(self.label)
    self.horizontalLayout = QtWidgets.QHBoxLayout()
    self.horizontalLayout.setObjectName("horizontalLayout")
    self.pushButton_2 = QtWidgets.QPushButton(self.verticalLayoutWidget)
    self.pushButton_2.setObjectName("pushButton_2")
    self.horizontalLayout.addWidget(self.pushButton_2)
    self.pushButton = QtWidgets.QPushButton(self.verticalLayoutWidget)
    self.pushButton.setObjectName("pushButton")
    self.horizontalLayout.addWidget(self.pushButton)
    self.verticalLayout.addLayout(self.horizontalLayout)

done by using qtdesigner and this

     pyuic5 borreme.ui -o borrreme.py

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