码迷,mamicode.com
首页 > 编程语言 > 详细

PyQt5+python3的FindDialog

时间:2014-10-07 22:26:34      阅读:283      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   io   os   ar   sp   div   c   

 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 = findButton
54         self.lineEdit = lineEdit
55         self.caseCheckBox = caseCheckBox
56         self.backwardCheckBox = backwardCheckBox
57         
58     def findClicked(self):
59         text = self.lineEdit.text()
60         cs = Qt.CaseSensitive if self.caseCheckBox.isChecked() else Qt.CaseInsensitive
61         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

标签:style   blog   color   io   os   ar   sp   div   c   

原文地址:http://www.cnblogs.com/eaxebx/p/4009808.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!