首页 > 代码库 > PyQt5+python3的FindDialog

PyQt5+python3的FindDialog

 1 #!/usr/bin/env python 2 #coding: utf-8 3  4 import sys 5 from PyQt5.QtWidgets import * 6 from PyQt5.QtCore import Qt, pyqtSignal 7  8 class FindDialog(QDialog): 9     findPrevious = pyqtSignal(str, Qt.CaseSensitivity)10     findNext = pyqtSignal(str, Qt.CaseSensitivity)11     12     def __init__(self, parent = None):13         QDialog.__init__(self, parent = None)14         15         label = QLabel("Find &what:")16         lineEdit = QLineEdit()17         label.setBuddy(lineEdit)18 19         caseCheckBox = QCheckBox("Match &case")20         backwardCheckBox = QCheckBox("Search &backward")21         findButton = QPushButton("&Find")22         findButton.setDefault(True)23         findButton.setEnabled(False)24 25         closeButton = QPushButton("Close")26 27         lineEdit.textChanged.connect(self.enableFindButton)28         findButton.clicked.connect(self.findClicked)29         closeButton.clicked.connect(self.close)30 31         topLeftLayout = QHBoxLayout()32         topLeftLayout.addWidget(label)33         topLeftLayout.addWidget(lineEdit)34 35         leftLayout = QVBoxLayout()36         leftLayout.addLayout(topLeftLayout)37         leftLayout.addWidget(caseCheckBox)38         leftLayout.addWidget(backwardCheckBox)39 40         rightLayout = QVBoxLayout()41         rightLayout.addWidget(findButton)42         rightLayout.addWidget(closeButton)43         rightLayout.addStretch()44 45         mainLayout = QHBoxLayout()46         mainLayout.addLayout(leftLayout)47         mainLayout.addLayout(rightLayout)48         49         self.setLayout(mainLayout)50         self.setWindowTitle("Find")51         self.setFixedHeight(self.sizeHint().height())52 53         self.findButton = findButton54         self.lineEdit = lineEdit55         self.caseCheckBox = caseCheckBox56         self.backwardCheckBox = backwardCheckBox57         58     def findClicked(self):59         text = self.lineEdit.text()60         cs = Qt.CaseSensitive if self.caseCheckBox.isChecked() else Qt.CaseInsensitive61         if self.backwardCheckBox.isChecked():62             self.findPrevious.emit(text, cs)63         else:64             self.findNext.emit(text, cs)65 66     def enableFindButton(self, text):67         self.findButton.setEnabled(not text == ‘‘)68 69 if __name__ == __main__:70     app = QApplication(sys.argv)71     dialog = FindDialog()72     dialog.show()73     sys.exit(app.exec())

 

PyQt5+python3的FindDialog