This example refers to an online blog, but it also adds a personal writing habit (no stretching of rows and columns here)
1 #demo_13 Integrated Layout2 ImportSYS3 fromPyqt5.qtwidgetsImportqformlayout, Qgroupbox, Qwidget,qtextedit,qapplication,qlabel,qgridlayout,qpushbutton,qlineedit,qhboxlayout, Qvboxlayout4 fromPyqt5.qtguiImportQicon,qpixmap5 classExample (qwidget):6 def __init__(self):7Super ().__init__()8 Self.creategridgroupbox ()9 Self.createvbox ()Ten Self.createformbox () OneSelf.mainlayout=qvboxlayout ()#main layout is vertical layout ASelf.mainLayout.setSpacing (20)#main layout Add filler - -Self.toplayout=qhboxlayout ()#Top Layout theSelf.bottomlayout=qgridlayout ()#Layout below - -Self.topLayout.addWidget (Self.gridgroupbox)#Top board adds a set of box -Self.topLayout.addWidget (Self.vbox)#Top layout Add another set of box + self.bottomLayout.addWidget (Self.forbox) - +Self.mainLayout.addLayout (Self.toplayout)#main layout Add top layout ASelf.mainLayout.addLayout (Self.bottomlayout)#You can also not create the lower layout above, the direct addwidget liquid effect is the same at - self.setlayout (self.mainlayout) -Self.setwindowtitle ('Integrated Layout') - self.show () - - defCreategridgroupbox (self): inSelf.gridgroupbox=qgroupbox ('Grid Layout') - toself.gridlayout=qgridlayout () +Self.label_1=qlabel ('Chinese name') -self.linetext_1=Qlineedit () theSelf.label_2=qlabel ('Launch Site') *Self.linetext_2=Qlineedit () $Self.label_3 = Qlabel ('Launch Time')Panax NotoginsengSelf.linetext_3 =Qlineedit () - theSelf.iconlabel=Qlabel () +Self.iconLabel.setPixmap (Qpixmap ("1.png")) A theSelf.gridLayout.addWidget (self.label_1,2, 0) +Self.gridLayout.addWidget (self.linetext_1,2,1) -Self.gridLayout.addWidget (self.label_2,3, 0) $Self.gridLayout.addWidget (self.linetext_2,3,1) $Self.gridLayout.addWidget (Self.label_3, 4, 0) -Self.gridLayout.addWidget (Self.linetext_3, 4, 1) -Self.gridLayout.addWidget (self.iconlabel,0,2,4,1)#column subscript, cross row, Kua the - self.gridGroupBox.setLayout (self.gridlayout)Wuyi the defCreatevbox (self): -Self.vbox=qgroupbox ('Vbox Layout') Wuself.vlayout=qvboxlayout () -Self.vlabel_1=qlabel ('Research Mission:') Aboutself.vtext_1=Qtextedit () $Self.vtext_1.setText ('It is equipped with 14 application loads such as space-cooled atomic clocks, as well as space medical experimental equipment such as weightlessness cardiovascular research . - "conducting space science and technology experiments') - self.vlayout.addWidget (Self.vlabel_1) - self.vlayout.addWidget (self.vtext_1) A self.vbox.setLayout (self.vlayout) + the - defCreateformbox (self): $Self.forbox=qgroupbox ('Form Box') theself.bottomlayout=qformlayout () theSelf.bottom_label1=qlabel ('Performance Features:') theSelf.bottom_linetext=qlineedit ('"The cabin design is more convenient for living in the Heavenly Palace"') theSelf.bottom_label2=qlabel ('emission rules:') -Self.bottom_edittext=qtextedit ('before 2020, China planned to complete the construction of space station preliminarily') in Self.bottomLayout.addRow (Self.bottom_label1,self.bottom_linetext) the Self.bottomLayout.addRow (Self.bottom_label2,self.bottom_edittext) the self.forbox.setLayout (self.bottomlayout) About the if __name__=='__main__': theapp=qapplication (SYS.ARGV) theE=Example () +Sys.exit (app.exec())
pyqt5-Layout Synthesis Example-12