Let's take a look at the final:
Full code:
#! /Usr/bin/ENV pythonimport sysfrom pyside. qtcore import * From pyside. qtgui import * class finddialog (qdialog): def _ init _ (self, parent = none): qdialog. _ init _ (self, parent) # create a label & edit label = qlabel ('Find & what: ') lineedit = qlineedit () label. setbuddy (lineedit) # When Alt + W is pressed, the focus is on edit. # Create checkbox casecheckbox = qcheckbox ('match & case') backwardcheckbox = qcheckbox ('search & backward ') # create find button findbutton = qpushbutton (' & find ') findbutton. setdefault (true) # set as the default button findbutton. setenabled (false) # Set the button to disable closebutton = qpushbutton ('close') # topleftlayout = qhboxlayout () topleftlayout in the layout dialog box. addwidget (Label) topleftlayout. addwidget (lineedit) leftlayout = qvboxlayout () leftlayout. addlayout (topleftlayout) leftlayout. addwidget (casecheckbox) leftlayout. addwidget (backwardcheckbox) rightlayout = qvboxlayout () rightlayout. addwidget (findbutton) rightlayout. addwidget (closebutton) rightlayout. addstretch () mainlayout = qhboxlayout () mainlayout. addlayout (leftlayout) mainlayout. addlayout (rightlayout) self. setlayout (mainlayout) # Set the dialog box title self. setwindowtitle ('Find ') def main (): APP = qapplication (sys. argv) d = finddialog () d. show () sys.exit(app.exe C _ () If _ name _ = '_ main _': Main ()
There is no actual function code in this section. It mainly demonstrates how to build a "Search" dialog box user interface through qhboxlayout and qvboxlayout.
The following dialog box shows the layout and parent-child relationship diagram: