1 #!/usr/bin/env python2 #Coding:utf-83 4 ImportSYS5 fromPyqt5.qtwidgetsImport*6 fromPyqt5.qtcoreImportQt, Pyqtsignal7 8 classFinddialog (qdialog):9FindPrevious =pyqtsignal (str, qt.casesensitivity)TenFindNext =pyqtsignal (str, qt.casesensitivity) One A def __init__(Self, parent =None): -Qdialog.__init__(Self, parent =None) - theLabel = Qlabel ("Find &what:") -LineEdit =Qlineedit () - Label.setbuddy (LineEdit) - +Casecheckbox = Qcheckbox ("Match &case") -Backwardcheckbox = Qcheckbox ("Search &backward") +Findbutton = Qpushbutton ("&find") A Findbutton.setdefault (True) at findbutton.setenabled (False) - -CloseButton = Qpushbutton ("Close") - - LineEdit.textChanged.connect (Self.enablefindbutton) - FindButton.clicked.connect (self.findclicked) in CloseButton.clicked.connect (self.close) - toTopleftlayout =qhboxlayout () + topleftlayout.addwidget (label) - topleftlayout.addwidget (LineEdit) the *Leftlayout =qvboxlayout () $ leftlayout.addlayout (topleftlayout)Panax Notoginseng leftlayout.addwidget (Casecheckbox) - leftlayout.addwidget (Backwardcheckbox) the +Rightlayout =qvboxlayout () A rightlayout.addwidget (Findbutton) the rightlayout.addwidget (CloseButton) + Rightlayout.addstretch () - $Mainlayout =qhboxlayout () $ mainlayout.addlayout (leftlayout) - mainlayout.addlayout (rightlayout) - the self.setlayout (mainlayout) -Self.setwindowtitle ("Find")Wuyi Self.setfixedheight (Self.sizehint (). Height ()) the -Self.findbutton =Findbutton WuSelf.lineedit =LineEdit -Self.casecheckbox =Casecheckbox AboutSelf.backwardcheckbox =Backwardcheckbox $ - deffindclicked (self): -Text =Self.lineEdit.text () -CS = qt.casesensitiveifSelf.caseCheckBox.isChecked ()Elseqt.caseinsensitive A ifself.backwardCheckBox.isChecked (): + self.findPrevious.emit (text, CS) the Else: - self.findNext.emit (text, CS) $ the defEnablefindbutton (self, text): theSelf.findButton.setEnabled ( notText = ="') the the if __name__=='__main__': -App =qapplication (SYS.ARGV) inDialog =Finddialog () the dialog.show () theSys.exit (app.exec())
Pyqt5+python3 's Finddialog