y:
15 | print('x>y')
16 | elif x>z:
17 | print('x>z')
18 |
19 | #3
20 | print('\n#3,while')
21 | x=3
22 | while x>0:
23 | print(x)
24 | x-=1
25 |
26 | #4
27 | print('\n#4,for')
28 | xlst=['1','b','xxx']
29 | for x in xlst:
30 | print(x)
31 |
32 | #5
33 | print('\n#5,for')
34 | for x in range(3):
35 | print(x)
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/Chapter02/py208fun.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | def f01(a,b,c):
4 | print('a,b,c,',a,b,c)
5 | a2,b2,c2,=a+c,b*2,c*2
6 | return a2,b2,c2
7 |
8 | #1
9 | print('\n#1')
10 | x,y,z=f01(1,2,3)
11 | print('x,y,z,',x,y,z)
12 |
13 | #2
14 | print('\n#2')
15 | x,y,z=f01(x,y,z)
16 | print('x,y,z,',x,y,z)
17 |
18 |
--------------------------------------------------------------------------------
/Chapter02/py209fun.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | import functools
4 |
5 | def add(a, b):
6 | return a + b
7 |
8 | #1
9 | print('\n#1')
10 | rst1 = add(4, 2)
11 | print('add(4, 2)=' , rst1)
12 |
13 | plus3 = functools.partial(add, 3)
14 | plus5 = functools.partial(add, 5)
15 |
16 | #2
17 | print('\n#2')
18 | rst2 = plus3(4)
19 | print('plus3(4)=' , rst2)
20 |
21 | rst3 = plus3(7)
22 | print('plus3(7)=' , rst3)
23 |
24 | rst4 = plus5(10)
25 | print('plus5(10)=' , rst4)
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/Chapter02/py210fun.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | fun1 = lambda x,y : x + y
4 | print('fun1(2,3)=' , fun1(2,3))
5 |
6 | fun2 = lambda x: x*2
7 | print('fun2(4)=' , fun2(4) )
--------------------------------------------------------------------------------
/Chapter02/py211class.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | class MyClass:
4 | count = 0
5 | name = 'DefaultName'
6 |
7 | def __init__(self, name):
8 | self.name = name
9 | print('类的变量是%s\n对象的变量是:%s' % ( MyClass.name, self.name) )
10 |
11 | def setCount(self, count ):
12 | self.count = count
13 |
14 | def getCount(self):
15 | return self.count
16 |
17 | if __name__ == "__main__":
18 | cls = MyClass('lisi')
19 | cls.setCount(10)
20 | print('count=%d' % cls.getCount())
--------------------------------------------------------------------------------
/Chapter02/py212privateProperty.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | class MyCounter:
4 | __secretCount = 0 # 私有变量
5 | publicCount = 0 # 公开变量
6 |
7 | def __privateCountFun(self):
8 | print('这是私有方法')
9 | self.__secretCount += 1
10 | self.publicCount += 1
11 | #print (self.__secretCount)
12 |
13 | def publicCountFun(self):
14 | print('这是公共方法')
15 | self.__privateCountFun()
16 |
17 | if __name__ == "__main__":
18 | counter = MyCounter()
19 | counter.publicCountFun()
20 | counter.publicCountFun()
21 | print ('instance publicCount=%d' % counter.publicCount)
22 | print ('Class publicCount=%d' % MyCounter.publicCount)
23 |
24 | # 报错,实例不能访问私有变量
25 | # print (counter.__secretCount)
26 | # 报错,实例不能访问私有方法
27 | # counter.__privateCountFun()
--------------------------------------------------------------------------------
/Chapter02/py213property01.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | class MyClass(object):
4 | def __init__(self):
5 | self._param = None
6 |
7 | def getParam(self):
8 | print( "get param: %s" % self._param)
9 | return self._param
10 |
11 | def setParam(self, value):
12 | print( "set param: %s" % self._param )
13 | self._param = value
14 |
15 | def delParam(self):
16 | print( "del param: %s" % self._param)
17 | del self._param
18 |
19 | param = property(getParam, setParam, delParam)
20 |
21 | if __name__ == "__main__":
22 | cls = MyClass()
23 | cls.param = 10
24 | print("current param : %s " % cls.param )
25 | del cls.param
--------------------------------------------------------------------------------
/Chapter02/py213property02.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | class MyClass(object):
4 | def __init__(self):
5 | self._param = None
6 |
7 | @property
8 | def param(self):
9 | print( "get param: %s" % self._param)
10 | return self._param
11 |
12 | @param.setter
13 | def param(self, value):
14 | print( "set param: %s" % self._param )
15 | self._param = value
16 |
17 | @param.deleter
18 | def param(self):
19 | print( "del param: %s" % self._param)
20 | del self._param
21 |
22 | if __name__ == "__main__":
23 | cls = MyClass()
24 | cls.param = 10
25 | print("current param : %s " % cls.param )
26 | del cls.param
27 |
--------------------------------------------------------------------------------
/Chapter03/CallFirstMainWin.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | import sys
4 | from PyQt5.QtWidgets import QApplication , QMainWindow
5 | from firstMainWin import *
6 |
7 | class MyMainWindow(QMainWindow, Ui_MainWindow):
8 | def __init__(self, parent=None):
9 | super(MyMainWindow, self).__init__(parent)
10 | self.setupUi(self)
11 |
12 | if __name__=="__main__":
13 | app = QApplication(sys.argv)
14 | myWin = MyMainWindow()
15 | myWin.show()
16 | sys.exit(app.exec_())
17 |
--------------------------------------------------------------------------------
/Chapter03/CallMainWin02.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | import sys
4 | from PyQt5.QtWidgets import QApplication , QMainWindow
5 | from MainWin02 import Ui_Form
6 |
7 | class MyMainWindow(QMainWindow, Ui_Form):
8 | def __init__(self, parent=None):
9 | super(MyMainWindow, self).__init__(parent)
10 | self.setupUi(self)
11 |
12 | if __name__=="__main__":
13 | app = QApplication(sys.argv)
14 | myWin = MyMainWindow()
15 | myWin.show()
16 | sys.exit(app.exec_())
17 |
--------------------------------------------------------------------------------
/Chapter03/CallMainWinSignalSlog01.py:
--------------------------------------------------------------------------------
1 | import sys
2 | from PyQt5.QtWidgets import QApplication, QMainWindow
3 | from MainWinSignalSlog01 import Ui_Form
4 |
5 |
6 | class MyMainWindow(QMainWindow, Ui_Form):
7 | def __init__(self, parent=None):
8 | super(MyMainWindow, self).__init__(parent)
9 | self.setupUi(self)
10 |
11 |
12 | if __name__ == "__main__":
13 | app = QApplication(sys.argv)
14 | myWin = MyMainWindow()
15 | myWin.show()
16 | sys.exit(app.exec_())
--------------------------------------------------------------------------------
/Chapter03/CallMainWinSignalSlog03.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | import sys
4 | from PyQt5.QtWidgets import QApplication, QMainWindow
5 | from MainWinSignalSlog03 import Ui_MainWindow
6 | from PyQt5.QtCore import pyqtSignal, Qt
7 |
8 |
9 | class MyMainWindow(QMainWindow, Ui_MainWindow):
10 | def __init__(self, parent=None):
11 | super(MyMainWindow, self).__init__(parent)
12 | self.setupUi(self)
13 | self.checkBox.setChecked(True) # 设置checkBox默认的初始状态为选择
14 |
15 |
16 | if __name__ == "__main__":
17 | app = QApplication(sys.argv)
18 | win = MyMainWindow()
19 | win.show()
20 | sys.exit(app.exec_())
21 |
--------------------------------------------------------------------------------
/Chapter03/MainWin01.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | Form
4 |
5 |
6 |
7 | 0
8 | 0
9 | 511
10 | 443
11 |
12 |
13 |
14 | Form
15 |
16 |
17 |
18 |
19 | 50
20 | 40
21 | 273
22 | 30
23 |
24 |
25 |
26 | -
27 |
28 |
29 | -
30 |
31 |
32 | 确定
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/Chapter03/MainWin02.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | # Form implementation generated from reading ui file 'MainWin02.ui'
4 | #
5 | # Created by: PyQt5 UI code generator 5.6
6 | #
7 | # WARNING! All changes made in this file will be lost!
8 |
9 | from PyQt5 import QtCore, QtGui, QtWidgets
10 |
11 | class Ui_Form(object):
12 | def setupUi(self, Form):
13 | Form.setObjectName("Form")
14 | Form.resize(678, 431)
15 | self.label = QtWidgets.QLabel(Form)
16 | self.label.setGeometry(QtCore.QRect(80, 30, 531, 321))
17 | self.label.setText("")
18 | self.label.setPixmap(QtGui.QPixmap(":/pic/images/python.jpg"))
19 | self.label.setObjectName("label")
20 |
21 | self.retranslateUi(Form)
22 | QtCore.QMetaObject.connectSlotsByName(Form)
23 |
24 | def retranslateUi(self, Form):
25 | _translate = QtCore.QCoreApplication.translate
26 | Form.setWindowTitle(_translate("Form", "Form"))
27 |
28 | import apprcc_rc
29 |
--------------------------------------------------------------------------------
/Chapter03/MainWin02.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | Form
4 |
5 |
6 |
7 | 0
8 | 0
9 | 678
10 | 431
11 |
12 |
13 |
14 | Form
15 |
16 |
17 |
18 |
19 | 80
20 | 30
21 | 531
22 | 321
23 |
24 |
25 |
26 |
27 |
28 |
29 | :/pic/images/python.jpg
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/Chapter03/MainWinSignalSlog01.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | # Form implementation generated from reading ui file 'MainWinSignalSlog01.ui'
4 | #
5 | # Created by: PyQt5 UI code generator 5.8.1
6 | #
7 | # WARNING! All changes made in this file will be lost!
8 |
9 | from PyQt5 import QtCore, QtGui, QtWidgets
10 |
11 | class Ui_Form(object):
12 | def setupUi(self, Form):
13 | Form.setObjectName("Form")
14 | Form.resize(452, 296)
15 | self.closeWinBtn = QtWidgets.QPushButton(Form)
16 | self.closeWinBtn.setGeometry(QtCore.QRect(150, 80, 121, 31))
17 | self.closeWinBtn.setObjectName("closeWinBtn")
18 |
19 | self.retranslateUi(Form)
20 | self.closeWinBtn.clicked.connect(Form.close)
21 | QtCore.QMetaObject.connectSlotsByName(Form)
22 |
23 | def retranslateUi(self, Form):
24 | _translate = QtCore.QCoreApplication.translate
25 | Form.setWindowTitle(_translate("Form", "Form"))
26 | self.closeWinBtn.setText(_translate("Form", "关闭窗口"))
27 |
28 |
--------------------------------------------------------------------------------
/Chapter03/MainWinSignalSlog01.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | Form
4 |
5 |
6 |
7 | 0
8 | 0
9 | 452
10 | 296
11 |
12 |
13 |
14 | Form
15 |
16 |
17 |
18 |
19 | 150
20 | 80
21 | 121
22 | 31
23 |
24 |
25 |
26 | 关闭窗口
27 |
28 |
29 |
30 |
31 |
32 |
33 | closeWinBtn
34 | clicked()
35 | Form
36 | close()
37 |
38 |
39 | 205
40 | 89
41 |
42 |
43 | 224
44 | 199
45 |
46 |
47 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/Chapter03/MainWinSignalSlog04.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | """
4 | Module implementing MainWindow.
5 | """
6 |
7 | from PyQt5.QtCore import pyqtSlot
8 | from PyQt5.QtWidgets import QMainWindow,QApplication
9 |
10 | from Ui_MainWinSignalSlog04 import Ui_MainWindow
11 |
12 | #注:原代码为 from .Ui_MainWinSignalSlog04 import Ui_MainWindow,运行出错,需要去掉.
13 |
14 | class MainWindow(QMainWindow, Ui_MainWindow):
15 | """
16 | Class documentation goes here.
17 | """
18 | def __init__(self, parent=None):
19 | """
20 | Constructor
21 |
22 | @param parent reference to the parent widget
23 | @type QWidget
24 | """
25 | super(MainWindow, self).__init__(parent)
26 | self.setupUi(self)
27 | self.checkBox.setChecked(True) # 设置checkBox默认的初始状态为选择
28 |
29 |
30 | @pyqtSlot(bool)
31 | def on_checkBox_clicked(self, checked):
32 | """
33 | Slot documentation goes here.
34 |
35 | @param checked DESCRIPTION
36 | @type bool
37 | """
38 | self.label.setVisible(checked)
39 | self.lineEdit.setEnabled(checked)
40 |
41 |
42 |
43 | if __name__ == "__main__":
44 | import sys
45 | app = QApplication(sys.argv)
46 | myWin = MainWindow()
47 | myWin.show()
48 | sys.exit(app.exec_())
--------------------------------------------------------------------------------
/Chapter03/__pycache__/ChildrenForm.cpython-35.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter03/__pycache__/ChildrenForm.cpython-35.pyc
--------------------------------------------------------------------------------
/Chapter03/__pycache__/MainForm.cpython-35.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter03/__pycache__/MainForm.cpython-35.pyc
--------------------------------------------------------------------------------
/Chapter03/__pycache__/MainWin02.cpython-35.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter03/__pycache__/MainWin02.cpython-35.pyc
--------------------------------------------------------------------------------
/Chapter03/__pycache__/MainWinSignalSlog01.cpython-35.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter03/__pycache__/MainWinSignalSlog01.cpython-35.pyc
--------------------------------------------------------------------------------
/Chapter03/__pycache__/MainWinSignalSlog02.cpython-35.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter03/__pycache__/MainWinSignalSlog02.cpython-35.pyc
--------------------------------------------------------------------------------
/Chapter03/__pycache__/MainWinSignalSlog03.cpython-35.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter03/__pycache__/MainWinSignalSlog03.cpython-35.pyc
--------------------------------------------------------------------------------
/Chapter03/__pycache__/Ui_MainWinSignalSlog04.cpython-35.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter03/__pycache__/Ui_MainWinSignalSlog04.cpython-35.pyc
--------------------------------------------------------------------------------
/Chapter03/__pycache__/Ui_layout_demo_LayoutManage.cpython-35.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter03/__pycache__/Ui_layout_demo_LayoutManage.cpython-35.pyc
--------------------------------------------------------------------------------
/Chapter03/__pycache__/apprcc_rc.cpython-35.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter03/__pycache__/apprcc_rc.cpython-35.pyc
--------------------------------------------------------------------------------
/Chapter03/__pycache__/firstMainWin.cpython-35.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter03/__pycache__/firstMainWin.cpython-35.pyc
--------------------------------------------------------------------------------
/Chapter03/__pycache__/firstMainWin.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter03/__pycache__/firstMainWin.cpython-36.pyc
--------------------------------------------------------------------------------
/Chapter03/apprcc.qrc:
--------------------------------------------------------------------------------
1 |
2 |
3 | images/cartoon1.ico
4 | images/cartoon2.ico
5 | images/cartoon3.ico
6 | images/cartoon4.ico
7 | images/python.jpg
8 |
9 |
10 |
--------------------------------------------------------------------------------
/Chapter03/firstMainWin.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | MainWindow
4 |
5 |
6 |
7 | 0
8 | 0
9 | 726
10 | 592
11 |
12 |
13 |
14 | MainWindow
15 |
16 |
17 |
18 |
19 |
20 | 490
21 | 110
22 | 93
23 | 28
24 |
25 |
26 |
27 | 按钮
28 |
29 |
30 |
31 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/Chapter03/images/cartoon1.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter03/images/cartoon1.ico
--------------------------------------------------------------------------------
/Chapter03/images/cartoon2.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter03/images/cartoon2.ico
--------------------------------------------------------------------------------
/Chapter03/images/cartoon3.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter03/images/cartoon3.ico
--------------------------------------------------------------------------------
/Chapter03/images/cartoon4.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter03/images/cartoon4.ico
--------------------------------------------------------------------------------
/Chapter03/images/python.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter03/images/python.jpg
--------------------------------------------------------------------------------
/Chapter03/mainWin/CallMainWin01.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | import sys
4 | from PyQt5.QtWidgets import QApplication , QMainWindow, QWidget , QFileDialog
5 | from MainForm import Ui_MainWindow
6 |
7 | class MainForm( QMainWindow , Ui_MainWindow):
8 | def __init__(self):
9 | super(MainForm,self).__init__()
10 | self.setupUi(self)
11 | # 菜单的点击事件,当点击关闭菜单时连接槽函数 close()
12 | self.fileCloseAction.triggered.connect(self.close)
13 | # 菜单的点击事件,当点击打开菜单时连接槽函数 openMsg()
14 | self.fileOpenAction.triggered.connect(self.openMsg)
15 |
16 | def openMsg(self):
17 | file,ok= QFileDialog.getOpenFileName(self,"打开","C:/","All Files (*);;Text Files (*.txt)")
18 | # 在状态栏显示文件地址
19 | self.statusbar.showMessage(file)
20 |
21 | if __name__=="__main__":
22 | app = QApplication(sys.argv)
23 | win = MainForm()
24 | win.show()
25 | sys.exit(app.exec_())
26 |
--------------------------------------------------------------------------------
/Chapter03/mainWin/ChildrenForm.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | # Form implementation generated from reading ui file 'ChildrenForm.ui'
4 | #
5 | # Created by: PyQt5 UI code generator 5.8.1
6 | #
7 | # WARNING! All changes made in this file will be lost!
8 |
9 | from PyQt5 import QtCore, QtGui, QtWidgets
10 |
11 | class Ui_ChildrenForm(object):
12 | def setupUi(self, ChildrenForm):
13 | ChildrenForm.setObjectName("ChildrenForm")
14 | ChildrenForm.resize(435, 339)
15 | ChildrenForm.setStyleSheet("")
16 | self.textEdit = QtWidgets.QTextEdit(ChildrenForm)
17 | self.textEdit.setGeometry(QtCore.QRect(0, 0, 471, 391))
18 | self.textEdit.setObjectName("textEdit")
19 |
20 | self.retranslateUi(ChildrenForm)
21 | QtCore.QMetaObject.connectSlotsByName(ChildrenForm)
22 |
23 | def retranslateUi(self, ChildrenForm):
24 | _translate = QtCore.QCoreApplication.translate
25 | ChildrenForm.setWindowTitle(_translate("ChildrenForm", "Form"))
26 |
27 |
--------------------------------------------------------------------------------
/Chapter03/mainWin/ChildrenForm.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | ChildrenForm
4 |
5 |
6 |
7 | 0
8 | 0
9 | 454
10 | 380
11 |
12 |
13 |
14 | Form
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 | 10
23 | 10
24 | 431
25 | 361
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/Chapter03/mainWin/__pycache__/ChildrenForm.cpython-35.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter03/mainWin/__pycache__/ChildrenForm.cpython-35.pyc
--------------------------------------------------------------------------------
/Chapter03/mainWin/__pycache__/ChildrenForm2.cpython-35.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter03/mainWin/__pycache__/ChildrenForm2.cpython-35.pyc
--------------------------------------------------------------------------------
/Chapter03/mainWin/__pycache__/MainForm.cpython-35.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter03/mainWin/__pycache__/MainForm.cpython-35.pyc
--------------------------------------------------------------------------------
/Chapter03/mainWin/__pycache__/MainForm2.cpython-35.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter03/mainWin/__pycache__/MainForm2.cpython-35.pyc
--------------------------------------------------------------------------------
/Chapter03/qt03_i18n01.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | """
4 | 【简介】
5 | 国际化例子
6 |
7 |
8 | """
9 |
10 | import sys
11 | from PyQt5.QtWidgets import QApplication ,QWidget ,QVBoxLayout , QPushButton
12 |
13 | class Winform(QWidget):
14 | def __init__(self,parent=None):
15 | super(Winform,self).__init__(parent)
16 | self.setWindowTitle(self.tr('title'))
17 | self.resize(330, 130)
18 | vlayout = QVBoxLayout()
19 | vlayout.addWidget( QPushButton( self.tr('upload')) )
20 | vlayout.addWidget( QPushButton( self.tr('download')) )
21 | self.setLayout(vlayout)
22 |
23 | if __name__ == "__main__":
24 | app = QApplication(sys.argv)
25 | form = Winform()
26 | form.show()
27 | sys.exit(app.exec_())
28 |
29 |
--------------------------------------------------------------------------------
/Chapter03/qt03_i18n02.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | """
4 | 【简介】
5 | 国际化例子
6 |
7 |
8 | """
9 |
10 | import sys
11 | from PyQt5.QtWidgets import QApplication ,QWidget ,QVBoxLayout , QPushButton
12 | from PyQt5.QtCore import QTranslator
13 |
14 | class Winform(QWidget):
15 | def __init__(self,parent=None):
16 | super(Winform,self).__init__(parent)
17 | self.setWindowTitle(self.tr('title'))
18 | self.resize(330, 130)
19 | vlayout = QVBoxLayout()
20 | vlayout.addWidget( QPushButton( self.tr('upload') ) )
21 | vlayout.addWidget( QPushButton( self.tr('download')) )
22 | self.setLayout(vlayout)
23 |
24 | if __name__ == "__main__":
25 | app = QApplication(sys.argv)
26 | trans = QTranslator()
27 | # 没有后缀.qm
28 | trans.load("zh_CN")
29 | app.installTranslator(trans)
30 | form = Winform()
31 | form.show()
32 | sys.exit(app.exec_())
33 |
34 |
--------------------------------------------------------------------------------
/Chapter03/testCase/RunTestCase.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | """
4 | 【简介】
5 | 自动化测试用例
6 |
7 |
8 | """
9 |
10 | import unittest
11 | import HTMLTestRunner
12 | import time
13 | from MatrixWinTest import MatrixWinTest
14 |
15 | if __name__ == "__main__":
16 |
17 | now = time.strftime("%Y-%m-%d-%H_%M_%S", time.localtime(time.time()))
18 | print( now )
19 | testunit = unittest.TestSuite()
20 | testunit.addTest(unittest.makeSuite(MatrixWinTest ))
21 |
22 | htmlFile = ".\\"+now+"HTMLtemplate.html"
23 | print( 'htmlFile='+ htmlFile)
24 | fp = open(htmlFile,'wb')
25 | runner = HTMLTestRunner.HTMLTestRunner(
26 | stream=fp,
27 | title=u"PyQt5测试报告",
28 | description=u"用例测试情况")
29 | runner.run(testunit)
30 | fp.close()
31 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/Chapter03/testCase/__pycache__/CallMatrixWinUi.cpython-35.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter03/testCase/__pycache__/CallMatrixWinUi.cpython-35.pyc
--------------------------------------------------------------------------------
/Chapter03/testCase/__pycache__/HTMLTestRunner.cpython-35.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter03/testCase/__pycache__/HTMLTestRunner.cpython-35.pyc
--------------------------------------------------------------------------------
/Chapter03/testCase/__pycache__/MatrixWinTest.cpython-35.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter03/testCase/__pycache__/MatrixWinTest.cpython-35.pyc
--------------------------------------------------------------------------------
/Chapter03/testCase/__pycache__/MatrixWinUi.cpython-35.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter03/testCase/__pycache__/MatrixWinUi.cpython-35.pyc
--------------------------------------------------------------------------------
/Chapter03/testCase/reportLog.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter03/testCase/reportLog.txt
--------------------------------------------------------------------------------
/Chapter03/tool.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | '''
4 | 【简介】
5 | ui转换成py的转换工具
6 |
7 | '''
8 |
9 | import os
10 | import os.path
11 |
12 | # UI文件所在的路径
13 | dir = './'
14 |
15 | # 列出目录下的所有ui文件
16 | def listUiFile():
17 | list = []
18 | files = os.listdir(dir)
19 | for filename in files:
20 | #print( dir + os.sep + f )
21 | #print(filename)
22 | if os.path.splitext(filename)[1] == '.ui':
23 | list.append(filename)
24 |
25 | return list
26 |
27 | # 把后缀为ui的文件改成后缀为py的文件名
28 | def transPyFile(filename):
29 | return os.path.splitext(filename)[0] + '.py'
30 |
31 | # 调用系统命令把ui转换成py
32 | def runMain():
33 | list = listUiFile()
34 | for uifile in list :
35 | pyfile = transPyFile(uifile)
36 | cmd = 'pyuic5 -o {pyfile} {uifile}'.format(pyfile=pyfile,uifile=uifile)
37 | #print(cmd)
38 | os.system(cmd)
39 |
40 | ###### 程序的主入口
41 | if __name__ == "__main__":
42 | runMain()
43 |
--------------------------------------------------------------------------------
/Chapter03/zh_CN.qm:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter03/zh_CN.qm
--------------------------------------------------------------------------------
/Chapter03/zh_CN.ts:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Winform
5 |
6 |
7 | upload
8 | 上传
9 |
10 |
11 |
12 | download
13 | 下载
14 |
15 |
16 |
17 | title
18 | 国际化例子
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Chapter04/__pycache__/hello.cpython-35.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter04/__pycache__/hello.cpython-35.pyc
--------------------------------------------------------------------------------
/Chapter04/hello.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | def sayHello():
4 | str="hello"
5 | print('hello python');
6 |
7 | if __name__ == "__main__":
8 | print ('This is main of module "hello.py"')
9 | sayHello()
10 |
11 |
--------------------------------------------------------------------------------
/Chapter04/images/ajax-loading.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter04/images/ajax-loading.gif
--------------------------------------------------------------------------------
/Chapter04/images/cartoon1.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter04/images/cartoon1.ico
--------------------------------------------------------------------------------
/Chapter04/images/cartoon2.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter04/images/cartoon2.ico
--------------------------------------------------------------------------------
/Chapter04/images/cartoon3.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter04/images/cartoon3.ico
--------------------------------------------------------------------------------
/Chapter04/images/cartoon4.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter04/images/cartoon4.ico
--------------------------------------------------------------------------------
/Chapter04/images/cartoon5.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter04/images/cartoon5.ico
--------------------------------------------------------------------------------
/Chapter04/images/cartoon6.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter04/images/cartoon6.ico
--------------------------------------------------------------------------------
/Chapter04/images/cartoon7.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter04/images/cartoon7.ico
--------------------------------------------------------------------------------
/Chapter04/images/cartoon8.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter04/images/cartoon8.ico
--------------------------------------------------------------------------------
/Chapter04/images/close.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter04/images/close.ico
--------------------------------------------------------------------------------
/Chapter04/images/doc.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter04/images/doc.ico
--------------------------------------------------------------------------------
/Chapter04/images/new.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter04/images/new.png
--------------------------------------------------------------------------------
/Chapter04/images/open.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter04/images/open.png
--------------------------------------------------------------------------------
/Chapter04/images/printer.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter04/images/printer.png
--------------------------------------------------------------------------------
/Chapter04/images/python.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter04/images/python.jpg
--------------------------------------------------------------------------------
/Chapter04/images/python.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter04/images/python.png
--------------------------------------------------------------------------------
/Chapter04/images/save.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter04/images/save.png
--------------------------------------------------------------------------------
/Chapter04/images/screen.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter04/images/screen.png
--------------------------------------------------------------------------------
/Chapter04/images/win.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter04/images/win.png
--------------------------------------------------------------------------------
/Chapter04/qt0409_QRadio.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | '''
4 | 【简介】
5 | PyQt5中QRadio例子
6 |
7 |
8 | '''
9 |
10 | import sys
11 | from PyQt5.QtCore import *
12 | from PyQt5.QtGui import *
13 | from PyQt5.QtWidgets import *
14 |
15 | class Radiodemo(QWidget):
16 | def __init__(self, parent=None):
17 | super(Radiodemo, self).__init__(parent)
18 | layout = QHBoxLayout()
19 | self.btn1 = QRadioButton("Button1")
20 | self.btn1.setChecked(True)
21 | self.btn1.toggled.connect(lambda:self.btnstate(self.btn1))
22 | layout.addWidget(self.btn1)
23 |
24 | self.btn2 = QRadioButton("Button2")
25 | self.btn2.toggled.connect(lambda:self.btnstate(self.btn2))
26 | layout.addWidget(self.btn2)
27 | self.setLayout(layout)
28 | self.setWindowTitle("RadioButton demo")
29 |
30 | def btnstate(self,btn):
31 | if btn.text()=="Button1":
32 | if btn.isChecked() == True:
33 | print( btn.text() + " is selected" )
34 | else:
35 | print( btn.text() + " is deselected" )
36 |
37 | if btn.text()=="Button2":
38 | if btn.isChecked()== True :
39 | print( btn.text() + " is selected" )
40 | else:
41 | print( btn.text() + " is deselected" )
42 |
43 | if __name__ == '__main__':
44 | app = QApplication(sys.argv)
45 | radioDemo = Radiodemo()
46 | radioDemo.show()
47 | sys.exit(app.exec_())
48 |
--------------------------------------------------------------------------------
/Chapter04/qt0412_QSpinBox.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | '''
4 | 【简介】
5 | PyQt5中 QSpinBox 例子
6 |
7 |
8 | '''
9 |
10 | import sys
11 | from PyQt5.QtCore import *
12 | from PyQt5.QtGui import *
13 | from PyQt5.QtWidgets import *
14 |
15 | class spindemo(QWidget):
16 | def __init__(self, parent=None):
17 | super(spindemo, self).__init__(parent)
18 | self.setWindowTitle("SpinBox 例子")
19 | self.resize(300, 100)
20 |
21 | layout = QVBoxLayout()
22 | self.l1=QLabel("current value:")
23 | self.l1.setAlignment(Qt.AlignCenter)
24 | layout.addWidget(self.l1)
25 | self.sp = QSpinBox()
26 | layout.addWidget(self.sp)
27 | self.sp.valueChanged.connect(self.valuechange)
28 | self.setLayout(layout)
29 |
30 | def valuechange(self):
31 | self.l1.setText("current value:" + str(self.sp.value()) )
32 |
33 | if __name__ == '__main__':
34 | app = QApplication(sys.argv)
35 | ex = spindemo()
36 | ex.show()
37 | sys.exit(app.exec_())
38 |
--------------------------------------------------------------------------------
/Chapter04/qt0414_Qmenu.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | '''
4 | 【简介】
5 | PyQt5中 Qmenu 例子
6 |
7 |
8 | '''
9 |
10 | import sys
11 | from PyQt5.QtCore import *
12 | from PyQt5.QtGui import *
13 | from PyQt5.QtWidgets import *
14 |
15 | class MenuDemo(QMainWindow):
16 | def __init__(self, parent=None):
17 | super(MenuDemo, self).__init__(parent)
18 | layout = QHBoxLayout()
19 | bar = self.menuBar()
20 | file = bar.addMenu("File")
21 | file.addAction("New")
22 | save = QAction("Save",self)
23 | save.setShortcut("Ctrl+S")
24 | file.addAction(save)
25 | edit = file.addMenu("Edit")
26 | edit.addAction("copy")
27 | edit.addAction("paste")
28 | quit = QAction("Quit",self)
29 | file.addAction(quit)
30 | file.triggered[QAction].connect(self.processtrigger)
31 | self.setLayout(layout)
32 | self.setWindowTitle("menu 例子")
33 | self.resize(350,300)
34 |
35 | def processtrigger(self,q):
36 | print( q.text()+" is triggered" )
37 |
38 | if __name__ == '__main__':
39 | app = QApplication(sys.argv)
40 | demo = MenuDemo()
41 | demo.show()
42 | sys.exit(app.exec_())
43 |
--------------------------------------------------------------------------------
/Chapter04/qt0415_QToolBar.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | '''
4 | 【简介】
5 | PyQt5中 QToolBar 例子
6 |
7 |
8 | '''
9 |
10 | import sys
11 | from PyQt5.QtCore import *
12 | from PyQt5.QtGui import *
13 | from PyQt5.QtWidgets import *
14 |
15 | class ToolBarDemo( QMainWindow ):
16 |
17 | def __init__(self, parent=None):
18 | super(ToolBarDemo, self).__init__(parent)
19 | self.setWindowTitle("toolbar 例子")
20 | self.resize(300, 200)
21 |
22 | layout = QVBoxLayout()
23 | tb = self.addToolBar("File")
24 | new = QAction(QIcon("./images/new.png"),"new",self)
25 | tb.addAction(new)
26 | open = QAction(QIcon("./images/open.png"),"open",self)
27 | tb.addAction(open)
28 | save = QAction(QIcon("./images/save.png"),"save",self)
29 | tb.addAction(save)
30 | tb.actionTriggered[QAction].connect(self.toolbtnpressed)
31 | self.setLayout(layout)
32 |
33 | def toolbtnpressed(self,a):
34 | print("pressed tool button is",a.text() )
35 |
36 | if __name__ == '__main__':
37 | app = QApplication(sys.argv)
38 | demo = ToolBarDemo()
39 | demo.show()
40 | sys.exit(app.exec_())
41 |
--------------------------------------------------------------------------------
/Chapter04/qt0416_Dialog.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | '''
4 | 【简介】
5 | PyQt5中 QDialog 例子
6 |
7 |
8 | '''
9 |
10 | import sys
11 | from PyQt5.QtCore import *
12 | from PyQt5.QtGui import *
13 | from PyQt5.QtWidgets import *
14 |
15 | class DialogDemo( QMainWindow ):
16 |
17 | def __init__(self, parent=None):
18 | super(DialogDemo, self).__init__(parent)
19 | self.setWindowTitle("Dialog 例子")
20 | self.resize(350,300)
21 |
22 | self.btn = QPushButton( self)
23 | self.btn.setText("弹出对话框")
24 | self.btn.move(50,50)
25 | self.btn.clicked.connect(self.showdialog)
26 |
27 | def showdialog(self ):
28 | dialog = QDialog()
29 | btn = QPushButton("ok", dialog )
30 | btn.move(50,50)
31 | dialog.setWindowTitle("Dialog")
32 | dialog.setWindowModality(Qt.ApplicationModal)
33 | dialog.exec_()
34 |
35 | if __name__ == '__main__':
36 | app = QApplication(sys.argv)
37 | demo = DialogDemo()
38 | demo.show()
39 | sys.exit(app.exec_())
40 |
--------------------------------------------------------------------------------
/Chapter04/qt0426_QPainter.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | '''
4 | 【简介】
5 | PyQt5中 涂刷例子
6 |
7 |
8 | '''
9 |
10 | import sys
11 | from PyQt5.QtCore import *
12 | from PyQt5.QtGui import *
13 | from PyQt5.QtWidgets import *
14 | from PyQt5.QtCore import Qt
15 |
16 | class Example(QWidget):
17 | def __init__(self):
18 | super(Example, self).__init__()
19 | self.initUI()
20 | def initUI(self):
21 | self.text = "hello world"
22 | self.setGeometry(100,100, 400,300)
23 | self.setWindowTitle('Draw Demo')
24 | self.show()
25 |
26 | def paintEvent(self, event):
27 | qp = QPainter()
28 | qp.begin(self)
29 | qp.setPen(QColor(Qt.red))
30 | qp.setFont(QFont('Arial', 20))
31 | qp.drawText(10,50, "hello Python")
32 | qp.setPen(QColor(Qt.blue))
33 | qp.drawLine(10,100,100,100)
34 | qp.drawRect(10,150,150,100)
35 | qp.setPen(QColor(Qt.yellow))
36 | qp.drawEllipse(100,50,100,50)
37 | qp.drawPixmap(220,10,QPixmap("./images/python.png"))
38 | qp.fillRect(200,175,150,100,QBrush(Qt.SolidPattern))
39 | qp.end()
40 |
41 | if __name__ == '__main__':
42 | app = QApplication(sys.argv)
43 | ex = Example()
44 | sys.exit(app.exec_())
45 |
--------------------------------------------------------------------------------
/Chapter04/qt04_QCalendar.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | '''
4 | 【简介】
5 | PyQt5中 QCalendarWidget 例子
6 |
7 |
8 | '''
9 |
10 | import sys
11 | from PyQt5 import QtCore
12 | from PyQt5.QtGui import *
13 | from PyQt5.QtWidgets import *
14 | from PyQt5.QtCore import QDate
15 |
16 | class CalendarExample( QWidget):
17 | def __init__(self):
18 | super(CalendarExample, self).__init__()
19 | self.initUI()
20 |
21 | def initUI(self):
22 | self.cal = QCalendarWidget(self)
23 | self.cal.setMinimumDate(QDate(1980, 1, 1))
24 | self.cal.setMaximumDate(QDate(3000, 1, 1))
25 | self.cal.setGridVisible(True)
26 | self.cal.move(20, 20)
27 | self.cal.clicked[QtCore.QDate].connect(self.showDate)
28 | self.lbl = QLabel(self)
29 | date = self.cal.selectedDate()
30 | self.lbl.setText(date.toString("yyyy-MM-dd dddd"))
31 | self.lbl.move(20, 300)
32 | self.setGeometry(100,100,400,350)
33 | self.setWindowTitle('Calendar 例子')
34 |
35 | def showDate(self, date):
36 | self.lbl.setText(date.toString("yyyy-MM-dd dddd") )
37 |
38 | if __name__ == '__main__':
39 | app = QApplication(sys.argv)
40 | demo = CalendarExample()
41 | demo.show()
42 | sys.exit(app.exec_())
43 |
--------------------------------------------------------------------------------
/Chapter04/qt04_QDockWidget.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | '''
4 | 【简介】
5 | PyQt5中 QDockWidget 例子
6 |
7 |
8 | '''
9 |
10 | import sys
11 | from PyQt5.QtCore import *
12 | from PyQt5.QtGui import *
13 | from PyQt5.QtWidgets import *
14 |
15 | class DockDemo(QMainWindow):
16 | def __init__(self, parent=None):
17 | super(DockDemo, self).__init__(parent)
18 | layout = QHBoxLayout()
19 | bar=self.menuBar()
20 | file=bar.addMenu("File")
21 | file.addAction("New")
22 | file.addAction("save")
23 | file.addAction("quit")
24 | self.items = QDockWidget("Dockable", self)
25 | self.listWidget = QListWidget()
26 | self.listWidget.addItem("item1")
27 | self.listWidget.addItem("item2")
28 | self.listWidget.addItem("item3")
29 | self.items.setWidget(self.listWidget)
30 | self.items.setFloating(False)
31 | self.setCentralWidget(QTextEdit())
32 | self.addDockWidget(Qt.RightDockWidgetArea, self.items)
33 | self.setLayout(layout)
34 | self.setWindowTitle("Dock 例子")
35 |
36 | if __name__ == '__main__':
37 | app = QApplication(sys.argv)
38 | demo = DockDemo()
39 | demo.show()
40 | sys.exit(app.exec_())
41 |
--------------------------------------------------------------------------------
/Chapter04/qt04_QFontDialog.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | '''
4 | 【简介】
5 | PyQt5中 QFontDialog 例子
6 |
7 |
8 | '''
9 |
10 | import sys
11 | from PyQt5.QtCore import *
12 | from PyQt5.QtGui import *
13 | from PyQt5.QtWidgets import *
14 |
15 | class FontDialogDemo(QWidget):
16 | def __init__(self, parent=None):
17 | super(FontDialogDemo, self).__init__(parent)
18 | layout = QVBoxLayout()
19 | self.fontButton = QPushButton("choose font")
20 | self.fontButton .clicked.connect(self.getFont)
21 | layout.addWidget(self.fontButton )
22 | self.fontLineEdit = QLabel("Hello,测试字体例子")
23 | layout.addWidget(self.fontLineEdit )
24 | self.setLayout(layout)
25 | self.setWindowTitle("Font Dialog 例子")
26 |
27 | def getFont(self):
28 | font, ok = QFontDialog.getFont()
29 | if ok:
30 | self.fontLineEdit .setFont(font)
31 |
32 | if __name__ == '__main__':
33 | app = QApplication(sys.argv)
34 | demo = FontDialogDemo()
35 | demo.show()
36 | sys.exit(app.exec_())
37 |
--------------------------------------------------------------------------------
/Chapter04/qt04_QMessageBox.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | '''
4 | 【简介】
5 | PyQt5中 QMessage 例子
6 |
7 |
8 | '''
9 |
10 | import sys
11 | from PyQt5.QtCore import *
12 | from PyQt5.QtGui import *
13 | from PyQt5.QtWidgets import *
14 |
15 | class WinForm( QWidget):
16 | def __init__(self):
17 | super(WinForm,self).__init__()
18 | self.setWindowTitle("QMessageBox 例子")
19 | self.resize(300, 100)
20 | self.myButton = QPushButton(self)
21 | self.myButton.setText("点击弹出消息框")
22 | self.myButton.clicked.connect(self.msg)
23 |
24 | def msg(self):
25 | # 使用infomation信息框
26 | reply = QMessageBox.information(self, "标题", "对话框消息正文", QMessageBox.Yes | QMessageBox.No , QMessageBox.Yes )
27 | print( reply )
28 |
29 | if __name__ == '__main__':
30 | app= QApplication(sys.argv)
31 | demo = WinForm()
32 | demo.show()
33 | sys.exit(app.exec_())
34 |
--------------------------------------------------------------------------------
/Chapter04/qt04_QMultipleDoc.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | '''
4 | 【简介】
5 | PyQt5中 QMdiArea 例子
6 |
7 |
8 | '''
9 |
10 | import sys
11 | from PyQt5.QtCore import *
12 | from PyQt5.QtGui import *
13 | from PyQt5.QtWidgets import *
14 |
15 | class MainWindow(QMainWindow):
16 | count=0
17 | def __init__(self, parent=None):
18 | super(MainWindow, self).__init__(parent)
19 | self.mdi = QMdiArea()
20 | self.setCentralWidget(self.mdi)
21 | bar=self.menuBar()
22 | file=bar.addMenu("File")
23 | file.addAction("New")
24 | file.addAction("cascade")
25 | file.addAction("Tiled")
26 | file.triggered[QAction].connect(self.windowaction)
27 | self.setWindowTitle("MDI demo")
28 |
29 | def windowaction(self, q):
30 | print( "triggered")
31 |
32 | if q.text()=="New":
33 | MainWindow.count=MainWindow.count+1
34 | sub=QMdiSubWindow()
35 | sub.setWidget(QTextEdit())
36 | sub.setWindowTitle("subwindow"+str(MainWindow.count))
37 | self.mdi.addSubWindow(sub)
38 | sub.show()
39 | if q.text()=="cascade":
40 | self.mdi.cascadeSubWindows()
41 | if q.text()=="Tiled":
42 | self.mdi.tileSubWindows()
43 |
44 | if __name__ == '__main__':
45 | app = QApplication(sys.argv)
46 | demo = MainWindow()
47 | demo.show()
48 | sys.exit(app.exec_())
49 |
50 |
--------------------------------------------------------------------------------
/Chapter04/qt04_QPixmap.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | '''
4 | 【简介】
5 | PyQt5中 QPixmap 例子
6 |
7 |
8 | '''
9 |
10 | import sys
11 | from PyQt5.QtCore import *
12 | from PyQt5.QtGui import *
13 | from PyQt5.QtWidgets import *
14 |
15 | if __name__ == '__main__':
16 | app = QApplication(sys.argv)
17 | win = QWidget()
18 | lab1 = QLabel()
19 | lab1.setPixmap(QPixmap("./images/python.jpg"))
20 | vbox=QVBoxLayout()
21 | vbox.addWidget(lab1)
22 | win.setLayout(vbox)
23 | win.setWindowTitle("QPixmap 例子")
24 | win.show()
25 | sys.exit(app.exec_())
26 |
--------------------------------------------------------------------------------
/Chapter04/qt04_QSplitter.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | '''
4 | 【简介】
5 | PyQt5中 QSplitter 例子
6 |
7 |
8 | '''
9 |
10 | import sys
11 | from PyQt5.QtCore import *
12 | from PyQt5.QtGui import *
13 | from PyQt5.QtWidgets import *
14 |
15 | class SplitterExample(QWidget):
16 | def __init__(self):
17 | super(SplitterExample, self).__init__()
18 | self.initUI()
19 |
20 | def initUI(self):
21 | hbox = QHBoxLayout(self)
22 | self.setWindowTitle('QSplitter 例子')
23 | self.setGeometry(300, 300, 300, 200)
24 | topleft = QFrame()
25 | topleft.setFrameShape(QFrame.StyledPanel)
26 |
27 | bottom = QFrame()
28 | bottom.setFrameShape(QFrame.StyledPanel)
29 |
30 | splitter1 = QSplitter(Qt.Horizontal)
31 | textedit = QTextEdit()
32 | splitter1.addWidget(topleft)
33 | splitter1.addWidget(textedit)
34 | splitter1.setSizes([100,200])
35 | splitter2 = QSplitter(Qt.Vertical)
36 | splitter2.addWidget(splitter1)
37 | splitter2.addWidget(bottom)
38 | hbox.addWidget(splitter2)
39 | self.setLayout(hbox)
40 |
41 | if __name__ == '__main__':
42 | app = QApplication(sys.argv)
43 | demo = SplitterExample()
44 | demo.show()
45 | sys.exit(app.exec_())
46 |
47 |
--------------------------------------------------------------------------------
/Chapter04/qt04_QStatusBar.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | '''
4 | 【简介】
5 | PyQt5中 QStatusBar 例子
6 |
7 |
8 | '''
9 |
10 | import sys
11 | from PyQt5.QtCore import *
12 | from PyQt5.QtGui import *
13 | from PyQt5.QtWidgets import *
14 |
15 | class StatusDemo(QMainWindow):
16 | def __init__(self, parent=None):
17 | super(StatusDemo, self).__init__(parent)
18 | bar = self.menuBar()
19 | file = bar.addMenu("File")
20 | file.addAction("show")
21 | file.triggered[QAction].connect(self.processTrigger)
22 | self.setCentralWidget(QTextEdit())
23 | self.statusBar= QStatusBar()
24 | self.setWindowTitle("QStatusBar 例子")
25 | self.setStatusBar(self.statusBar)
26 |
27 | def processTrigger(self,q):
28 | if (q.text()=="show"):
29 | self.statusBar.showMessage(q.text()+" 菜单选项被点击了",5000)
30 |
31 | if __name__ == '__main__':
32 | app = QApplication(sys.argv)
33 | demo = StatusDemo()
34 | demo.show()
35 | sys.exit(app.exec_())
36 |
--------------------------------------------------------------------------------
/Chapter04/qt04_closeMainWin.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | '''
3 | 【简介】
4 | PyQT5中关闭窗体例子
5 |
6 |
7 | '''
8 |
9 | from PyQt5.QtWidgets import QMainWindow,QHBoxLayout, QPushButton , QApplication, QWidget
10 | import sys
11 |
12 | class WinForm(QMainWindow):
13 |
14 | def __init__(self, parent=None):
15 | super(WinForm, self).__init__(parent)
16 | self.resize(330, 100)
17 | self.setWindowTitle('关闭主窗口例子')
18 | self.button1 = QPushButton('关闭主窗口')
19 | self.button1.clicked.connect(self.onButtonClick)
20 |
21 | layout = QHBoxLayout()
22 | layout.addWidget(self.button1)
23 |
24 | main_frame = QWidget()
25 | main_frame.setLayout(layout)
26 | self.setCentralWidget(main_frame)
27 |
28 | def onButtonClick(self ):
29 | #sender 是发送信号的对象,此处发送信号的对象是button1按钮
30 | sender = self.sender()
31 | print( sender.text() + ' 被按下了' )
32 | qApp = QApplication.instance()
33 | qApp.quit()
34 |
35 | if __name__ == "__main__":
36 | app = QApplication(sys.argv)
37 | form = WinForm()
38 | form.show()
39 | sys.exit(app.exec_())
40 |
--------------------------------------------------------------------------------
/Chapter04/qt04_drag.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | '''
4 | 【简介】
5 | PyQt5中 Drag and Drop 例子
6 |
7 |
8 | '''
9 |
10 | import sys
11 | from PyQt5.QtCore import *
12 | from PyQt5.QtGui import *
13 | from PyQt5.QtWidgets import *
14 |
15 | class Combo(QComboBox):
16 |
17 | def __init__(self, title, parent):
18 | super(Combo, self).__init__( parent)
19 | self.setAcceptDrops(True)
20 |
21 | def dragEnterEvent(self, e):
22 | print( e)
23 | if e.mimeData().hasText():
24 | e.accept()
25 | else:
26 | e.ignore()
27 |
28 | def dropEvent(self, e):
29 | self.addItem(e.mimeData().text())
30 |
31 | class Example(QWidget):
32 | def __init__(self):
33 | super(Example, self).__init__()
34 | self.initUI()
35 |
36 | def initUI(self):
37 | lo = QFormLayout()
38 | lo.addRow(QLabel("请把左边的文本拖拽到右边的下拉菜单中"))
39 | edit = QLineEdit()
40 | edit.setDragEnabled(True)
41 | com = Combo("Button", self)
42 | lo.addRow(edit,com)
43 | self.setLayout(lo)
44 | self.setWindowTitle('简单拖拽例子')
45 |
46 | if __name__ == '__main__':
47 | app = QApplication(sys.argv)
48 | ex = Example()
49 | ex.show()
50 | sys.exit(app.exec_())
51 |
--------------------------------------------------------------------------------
/Chapter04/qt04_drawPoint.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | """
4 | 【简介】
5 | 在窗体中绘画点的例子
6 |
7 |
8 | """
9 |
10 | import sys, math
11 | from PyQt5.QtWidgets import *
12 | from PyQt5.QtGui import *
13 | from PyQt5.QtCore import Qt
14 |
15 | class Drawing(QWidget):
16 | def __init__(self, parent=None):
17 | super(Drawing, self).__init__(parent)
18 | self.resize(300, 200)
19 | self.setWindowTitle("在窗体中画点")
20 |
21 | def paintEvent(self, event):
22 | qp = QPainter()
23 | qp.begin(self)
24 | # 自定义画点方法
25 | self.drawPoints(qp)
26 | qp.end()
27 |
28 | def drawPoints(self, qp):
29 | qp.setPen( Qt.red)
30 | size = self.size()
31 |
32 | for i in range(1000):
33 | # [-100, 100]两个周期的正弦函数图像
34 | x = 100 *(-1+2.0*i/1000)+ size.width()/2.0
35 | y = -50 * math.sin((x - size.width()/2.0)*math.pi/50) + size.height()/2.0
36 | qp.drawPoint(x, y)
37 |
38 | if __name__ == '__main__':
39 | app = QApplication(sys.argv)
40 | demo = Drawing()
41 | demo.show()
42 | sys.exit(app.exec_())
43 |
--------------------------------------------------------------------------------
/Chapter04/qt04_drawText.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | """
4 | 【简介】
5 | 在窗体中绘画出文字的例子
6 |
7 |
8 | """
9 |
10 | import sys
11 | from PyQt5.QtWidgets import QApplication ,QWidget
12 | from PyQt5.QtGui import QPainter ,QColor ,QFont
13 | from PyQt5.QtCore import Qt
14 |
15 | class Drawing(QWidget):
16 | def __init__(self,parent=None):
17 | super(Drawing,self).__init__(parent)
18 | self.setWindowTitle("在窗体中绘画出文字例子")
19 | self.resize(300, 200)
20 | self.text = '欢迎学习 PyQt5'
21 |
22 | def paintEvent(self,event):
23 | painter = QPainter(self)
24 | painter.begin(self)
25 | # 自定义的绘画方法
26 | self.drawText(event, painter)
27 | painter.end()
28 |
29 | def drawText(self, event, qp):
30 | # 设置笔的颜色
31 | qp.setPen( QColor(168, 34, 3) )
32 | # 设置字体
33 | qp.setFont( QFont('SimSun', 20))
34 | # 画出文本
35 | qp.drawText(event.rect(), Qt.AlignCenter, self.text)
36 |
37 | if __name__ == "__main__":
38 | app = QApplication(sys.argv)
39 | demo = Drawing()
40 | demo.show()
41 | sys.exit(app.exec_())
42 |
--------------------------------------------------------------------------------
/Chapter04/qt04_textEdit.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | '''
4 | 【简介】
5 | PyQt5中 QTextEdit例子
6 |
7 | '''
8 |
9 | from PyQt5.QtWidgets import QApplication, QWidget , QTextEdit, QVBoxLayout , QPushButton
10 | import sys
11 |
12 | class TextEditDemo(QWidget):
13 | def __init__(self, parent=None):
14 | super(TextEditDemo, self).__init__(parent)
15 | self.setWindowTitle("QTextEdit 例子")
16 | self.resize(300, 270)
17 | self.textEdit = QTextEdit( )
18 | self.btnPress1 = QPushButton("显示文本")
19 | self.btnPress2 = QPushButton("显示HTML")
20 | layout = QVBoxLayout()
21 | layout.addWidget(self.textEdit)
22 | layout.addWidget(self.btnPress1)
23 | layout.addWidget(self.btnPress2)
24 | self.setLayout(layout)
25 | self.btnPress1.clicked.connect(self.btnPress1_Clicked)
26 | self.btnPress2.clicked.connect(self.btnPress2_Clicked)
27 |
28 | def btnPress1_Clicked(self):
29 | self.textEdit.setPlainText("Hello PyQt5!\n点击按钮")
30 |
31 | def btnPress2_Clicked(self):
32 | self.textEdit.setHtml("Hello PyQt5!\n点击按钮。")
33 |
34 | if __name__ == "__main__":
35 | app = QApplication(sys.argv)
36 | win = TextEditDemo()
37 | win.show()
38 | sys.exit(app.exec_())
39 |
--------------------------------------------------------------------------------
/Chapter04/qt402_FirstPyQt.py:
--------------------------------------------------------------------------------
1 | # -*- coding: UTF-8 -*-
2 |
3 | """
4 | 【简介】
5 |
6 |
7 | """
8 |
9 | import sys
10 | from PyQt5.QtWidgets import QApplication, QWidget
11 |
12 | app = QApplication(sys.argv)
13 | window = QWidget()
14 | window.resize(300, 200)
15 | window.move(250, 150)
16 | window.setWindowTitle('Hello PyQt5')
17 | window.show()
18 | sys.exit(app.exec_())
19 |
--------------------------------------------------------------------------------
/Chapter04/qt402_QMainWin.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | '''
4 | 【简介】
5 | PyQT5中主窗口例子
6 |
7 |
8 | '''
9 |
10 | import sys
11 | from PyQt5.QtWidgets import QMainWindow , QApplication
12 | from PyQt5.QtGui import QIcon
13 |
14 | class MainWidget(QMainWindow):
15 | def __init__(self,parent=None):
16 | super(MainWidget,self).__init__(parent)
17 | # 设置主窗体标签
18 | self.setWindowTitle("QMainWindow 例子")
19 | self.resize(400, 200)
20 | self.status = self.statusBar()
21 | self.status.showMessage("这是状态栏提示",5000)
22 |
23 |
24 | if __name__ == "__main__":
25 | app = QApplication(sys.argv)
26 | app.setWindowIcon(QIcon("./images/cartoon1.ico"))
27 | main = MainWidget()
28 | main.show()
29 | sys.exit(app.exec_())
30 |
--------------------------------------------------------------------------------
/Chapter04/qt403_QIcon.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | '''
4 | 【简介】
5 | 演示程序图标例子
6 |
7 | '''
8 |
9 |
10 | import sys
11 | from PyQt5.QtGui import QIcon
12 | from PyQt5.QtWidgets import QWidget , QApplication
13 |
14 | #1
15 | class Icon(QWidget):
16 | def __init__(self, parent = None):
17 | super(Icon,self).__init__(parent)
18 | self.initUI()
19 |
20 | #2
21 | def initUI(self):
22 | self.setGeometry(300, 300, 250, 150)
23 | self.setWindowTitle('演示程序图标例子')
24 | self.setWindowIcon(QIcon('./images/cartoon1.ico'))
25 |
26 | if __name__ == '__main__':
27 | app = QApplication(sys.argv)
28 | icon = Icon()
29 | icon.show()
30 | sys.exit(app.exec_())
31 |
--------------------------------------------------------------------------------
/Chapter04/qt404_QToolTip.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | '''
4 | 【简介】
5 | PyQT5中气泡提示
6 |
7 | '''
8 |
9 | import sys
10 | from PyQt5.QtWidgets import QWidget, QToolTip , QApplication
11 | from PyQt5.QtGui import QFont
12 |
13 | class Winform(QWidget):
14 | def __init__(self):
15 | super().__init__()
16 | self.initUI()
17 |
18 | def initUI(self):
19 | QToolTip.setFont(QFont('SansSerif', 10))
20 | self.setToolTip('这是一个气泡提示')
21 | self.setGeometry(200, 300, 400, 400)
22 | self.setWindowTitle('气泡提示demo')
23 |
24 | if __name__ == '__main__':
25 | app = QApplication(sys.argv)
26 | win = Winform()
27 | win.show()
28 | sys.exit(app.exec_())
29 |
--------------------------------------------------------------------------------
/Chapter04/qt405_center.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | '''
4 | 【简介】
5 | PyQT5将窗口放在屏幕中间例子
6 |
7 | '''
8 |
9 | from PyQt5.QtWidgets import QDesktopWidget, QApplication ,QMainWindow
10 | import sys
11 |
12 | class Winform( QMainWindow):
13 |
14 | def __init__(self, parent=None):
15 | super( Winform, self).__init__(parent)
16 |
17 | self.setWindowTitle('主窗口放在屏幕中间例子')
18 | self.resize(370, 250)
19 | self.center()
20 |
21 | def center(self):
22 | screen = QDesktopWidget().screenGeometry()
23 | size = self.geometry()
24 | self.move((screen.width() - size.width()) / 2, (screen.height() - size.height()) / 2)
25 |
26 | if __name__ == "__main__":
27 | app = QApplication(sys.argv)
28 | win = Winform()
29 | win.show()
30 | sys.exit(app.exec_())
31 |
--------------------------------------------------------------------------------
/Chapter05/MySharedObject.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | from PyQt5.QtCore import QObject
4 | from PyQt5.QtCore import pyqtProperty
5 | from PyQt5.QtWidgets import QWidget,QMessageBox
6 |
7 | class MySharedObject(QWidget):
8 |
9 | def __init__( self):
10 | super( MySharedObject, self).__init__()
11 |
12 | def _getStrValue( self):
13 | #
14 | return '100'
15 |
16 | def _setStrValue( self, str ):
17 | #
18 | print('获得页面参数 :%s'% str )
19 | QMessageBox.information(self,"Information", '获得页面参数 :%s'% str )
20 |
21 | #需要定义对外发布的方法
22 | strValue = pyqtProperty(str, fget=_getStrValue, fset=_setStrValue)
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/Chapter05/__pycache__/MySharedObject.cpython-35.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter05/__pycache__/MySharedObject.cpython-35.pyc
--------------------------------------------------------------------------------
/Chapter05/db/database.db:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter05/db/database.db
--------------------------------------------------------------------------------
/Chapter05/images/IOS.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter05/images/IOS.png
--------------------------------------------------------------------------------
/Chapter05/images/android.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter05/images/android.png
--------------------------------------------------------------------------------
/Chapter05/images/bao0.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter05/images/bao0.png
--------------------------------------------------------------------------------
/Chapter05/images/bao1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter05/images/bao1.png
--------------------------------------------------------------------------------
/Chapter05/images/bao10.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter05/images/bao10.png
--------------------------------------------------------------------------------
/Chapter05/images/bao11.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter05/images/bao11.png
--------------------------------------------------------------------------------
/Chapter05/images/bao12.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter05/images/bao12.png
--------------------------------------------------------------------------------
/Chapter05/images/bao13.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter05/images/bao13.png
--------------------------------------------------------------------------------
/Chapter05/images/bao14.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter05/images/bao14.png
--------------------------------------------------------------------------------
/Chapter05/images/bao2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter05/images/bao2.png
--------------------------------------------------------------------------------
/Chapter05/images/bao3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter05/images/bao3.png
--------------------------------------------------------------------------------
/Chapter05/images/bao4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter05/images/bao4.png
--------------------------------------------------------------------------------
/Chapter05/images/bao5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter05/images/bao5.png
--------------------------------------------------------------------------------
/Chapter05/images/bao6.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter05/images/bao6.png
--------------------------------------------------------------------------------
/Chapter05/images/bao7.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter05/images/bao7.png
--------------------------------------------------------------------------------
/Chapter05/images/bao8.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter05/images/bao8.png
--------------------------------------------------------------------------------
/Chapter05/images/bao9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter05/images/bao9.png
--------------------------------------------------------------------------------
/Chapter05/images/cartoon1.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter05/images/cartoon1.ico
--------------------------------------------------------------------------------
/Chapter05/images/flower.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter05/images/flower.png
--------------------------------------------------------------------------------
/Chapter05/images/hammer.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter05/images/hammer.png
--------------------------------------------------------------------------------
/Chapter05/images/music.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter05/images/music.png
--------------------------------------------------------------------------------
/Chapter05/images/root.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter05/images/root.png
--------------------------------------------------------------------------------
/Chapter05/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | Hello PyQt5
9 | Hello PyQt5
10 | hello PyQt5
11 | hello PyQt5
12 | hello PyQt5
13 | Hello PyQt5
14 |
15 |
16 |
--------------------------------------------------------------------------------
/Chapter05/qt05_QDockWidget.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | '''
4 | 【简介】
5 | PyQt5中 QDockWidget 例子
6 |
7 |
8 | '''
9 |
10 | import sys
11 | from PyQt5.QtCore import *
12 | from PyQt5.QtGui import *
13 | from PyQt5.QtWidgets import *
14 |
15 | class DockDemo(QMainWindow):
16 | def __init__(self, parent=None):
17 | super(DockDemo, self).__init__(parent)
18 | layout = QHBoxLayout()
19 | bar=self.menuBar()
20 | file=bar.addMenu("File")
21 | file.addAction("New")
22 | file.addAction("save")
23 | file.addAction("quit")
24 | self.items = QDockWidget("Dockable", self)
25 | self.listWidget = QListWidget()
26 | self.listWidget.addItem("item1")
27 | self.listWidget.addItem("item2")
28 | self.listWidget.addItem("item3")
29 | self.items.setWidget(self.listWidget)
30 | self.items.setFloating(False)
31 | self.setCentralWidget(QTextEdit())
32 | self.addDockWidget(Qt.RightDockWidgetArea, self.items)
33 | self.setLayout(layout)
34 | self.setWindowTitle("Dock 例子")
35 |
36 | if __name__ == '__main__':
37 | app = QApplication(sys.argv)
38 | demo = DockDemo()
39 | demo.show()
40 | sys.exit(app.exec_())
41 |
--------------------------------------------------------------------------------
/Chapter05/qt05_QListWidget.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | '''
4 | 【简介】
5 | PyQt5中 QListWidget 例子
6 |
7 |
8 | '''
9 |
10 | import sys
11 | from PyQt5.QtCore import *
12 | from PyQt5.QtGui import *
13 | from PyQt5.QtWidgets import *
14 |
15 | class ListWidget(QListWidget):
16 | def clicked(self,item):
17 | QMessageBox.information(self, "ListWidget", "你选择了: "+item.text())
18 |
19 | if __name__ == '__main__':
20 | app = QApplication(sys.argv)
21 | listWidget = ListWidget()
22 | listWidget.resize(300,120)
23 | listWidget.addItem("Item 1");
24 | listWidget.addItem("Item 2");
25 | listWidget.addItem("Item 3");
26 | listWidget.addItem("Item 4");
27 | listWidget.setWindowTitle('QListwidget 例子')
28 | listWidget.itemClicked.connect(listWidget.clicked)
29 | listWidget.show()
30 | sys.exit(app.exec_())
31 |
--------------------------------------------------------------------------------
/Chapter05/qt05_QMultipleDoc.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | '''
4 | 【简介】
5 | PyQt5中 QMdiArea 例子
6 |
7 |
8 | '''
9 |
10 | import sys
11 | from PyQt5.QtCore import *
12 | from PyQt5.QtGui import *
13 | from PyQt5.QtWidgets import *
14 |
15 | class MainWindow(QMainWindow):
16 | count=0
17 | def __init__(self, parent=None):
18 | super(MainWindow, self).__init__(parent)
19 | self.mdi = QMdiArea()
20 | self.setCentralWidget(self.mdi)
21 | bar=self.menuBar()
22 | file=bar.addMenu("File")
23 | file.addAction("New")
24 | file.addAction("cascade")
25 | file.addAction("Tiled")
26 | file.triggered[QAction].connect(self.windowaction)
27 | self.setWindowTitle("MDI demo")
28 |
29 | def windowaction(self, q):
30 | print( "triggered")
31 |
32 | if q.text()=="New":
33 | MainWindow.count=MainWindow.count+1
34 | sub=QMdiSubWindow()
35 | sub.setWidget(QTextEdit())
36 | sub.setWindowTitle("subwindow"+str(MainWindow.count))
37 | self.mdi.addSubWindow(sub)
38 | sub.show()
39 | if q.text()=="cascade":
40 | self.mdi.cascadeSubWindows()
41 | if q.text()=="Tiled":
42 | self.mdi.tileSubWindows()
43 |
44 | if __name__ == '__main__':
45 | app = QApplication(sys.argv)
46 | demo = MainWindow()
47 | demo.show()
48 | sys.exit(app.exec_())
49 |
50 |
--------------------------------------------------------------------------------
/Chapter05/qt05_db01.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | '''
4 | 【简介】
5 | PyQt5中 处理database 例子
6 |
7 |
8 | '''
9 |
10 | import sys
11 | from PyQt5.QtCore import *
12 | from PyQt5.QtGui import *
13 | from PyQt5.QtWidgets import *
14 | from PyQt5.QtSql import QSqlDatabase , QSqlQuery
15 |
16 | def createDB():
17 | db = QSqlDatabase.addDatabase('QSQLITE')
18 | db.setDatabaseName('./db/database.db')
19 |
20 | if not db.open():
21 | QMessageBox.critical(None, ("无法打开数据库"),
22 | ( "无法建立到数据库的连接,这个例子需要SQLite 支持,请检查数据库配置。\n\n"
23 | "点击取消按钮退出应用。"),
24 | QMessageBox.Cancel )
25 | return False
26 |
27 | query = QSqlQuery()
28 | query.exec_("create table people(id int primary key, "
29 | "name varchar(20), address varchar(30))")
30 | query.exec_("insert into people values(1, 'zhangsan1', 'BeiJing')")
31 | query.exec_("insert into people values(2, 'lisi1', 'TianJing')")
32 | query.exec_("insert into people values(3, 'wangwu1', 'HenNan')")
33 | query.exec_("insert into people values(4, 'lisi2', 'HeBei')")
34 | query.exec_("insert into people values(5, 'wangwu2', 'shanghai')")
35 | return True
36 |
37 | if __name__ == '__main__':
38 | app = QApplication(sys.argv)
39 | createDB()
40 | sys.exit(app.exec_())
41 |
42 |
--------------------------------------------------------------------------------
/Chapter05/qt05_freshUi.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | '''
3 | 【简介】
4 | PyQT5中实时刷新界面例子
5 |
6 |
7 | '''
8 |
9 | from PyQt5.QtWidgets import QWidget, QPushButton , QApplication ,QListWidget, QGridLayout
10 | import sys
11 | import time
12 |
13 | class WinForm(QWidget):
14 |
15 | def __init__(self,parent=None):
16 | super(WinForm,self).__init__(parent)
17 | self.setWindowTitle("实时刷新界面例子")
18 | self.listFile= QListWidget()
19 | self.btnStart = QPushButton('开始')
20 | layout = QGridLayout(self)
21 | layout.addWidget(self.listFile,0,0,1,2)
22 | layout.addWidget(self.btnStart,1,1)
23 | self.btnStart.clicked.connect( self.slotAdd)
24 | self.setLayout(layout)
25 |
26 | def slotAdd(self):
27 | for n in range(10):
28 | str_n='File index {0}'.format(n)
29 | self.listFile.addItem(str_n)
30 | QApplication.processEvents()
31 | time.sleep(1)
32 |
33 | if __name__ == "__main__":
34 | app = QApplication(sys.argv)
35 | form = WinForm()
36 | form.show()
37 | sys.exit(app.exec_())
38 |
--------------------------------------------------------------------------------
/Chapter05/qt05_listView.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | '''
4 | 【简介】
5 | PyQt5中 QListView 例子
6 |
7 | '''
8 |
9 | from PyQt5.QtWidgets import QApplication, QWidget , QVBoxLayout , QListView, QMessageBox
10 | from PyQt5.QtCore import QStringListModel
11 | import sys
12 |
13 | class ListViewDemo(QWidget):
14 | def __init__(self, parent=None):
15 | super(ListViewDemo, self).__init__(parent)
16 | self.setWindowTitle("QListView 例子")
17 | self.resize(300, 270)
18 | layout = QVBoxLayout()
19 |
20 | listView = QListView()
21 | slm = QStringListModel();
22 | self.qList = ['Item 1','Item 2','Item 3','Item 4' ]
23 | slm.setStringList(self.qList)
24 | listView.setModel(slm )
25 | listView.clicked.connect(self.clicked)
26 | layout.addWidget( listView )
27 | self.setLayout(layout)
28 |
29 | def clicked(self, qModelIndex):
30 | QMessageBox.information(self, "QListView", "你选择了: "+ self.qList[qModelIndex.row()])
31 |
32 | if __name__ == "__main__":
33 | app = QApplication(sys.argv)
34 | win = ListViewDemo()
35 | win.show()
36 | sys.exit(app.exec_())
37 |
--------------------------------------------------------------------------------
/Chapter05/qt05_property.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | from PyQt5.QtCore import QObject, pyqtProperty
4 |
5 | class MyObject(QObject):
6 | def __init__(self, inVal=20):
7 | self.val = inVal
8 |
9 | def readVal(self):
10 | print('readVal=%s' % self.val )
11 | return self.val
12 |
13 | def setVal(self,val):
14 | print('setVal=%s' % val )
15 | self.val = val
16 |
17 | ppVal = pyqtProperty(int, readVal, setVal )
18 |
19 | if __name__ == '__main__':
20 | obj = MyObject()
21 | print('\n#1')
22 | obj.ppVal = 10
23 | print('\n#2')
24 | print( 'obj.ppVal=%s' % obj.ppVal )
25 | print( 'obj.readVal()=%s' % obj.readVal() )
26 |
27 |
--------------------------------------------------------------------------------
/Chapter05/qt05_tblHeader.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | '''
3 | 【简介】
4 | PyQT5中表格头为自适应模式例子
5 |
6 |
7 | '''
8 |
9 | import sys
10 | from PyQt5.QtWidgets import (QWidget, QTableWidget, QHBoxLayout, QApplication , QTableWidgetItem, QHeaderView)
11 |
12 | class Table(QWidget):
13 | def __init__(self):
14 | super().__init__()
15 | self.initUI()
16 |
17 | def initUI(self):
18 | self.setWindowTitle("QTableWidget demo")
19 | self.resize(500,300);
20 | conLayout = QHBoxLayout()
21 | tableWidget= QTableWidget()
22 | tableWidget.setRowCount(4)
23 | tableWidget.setColumnCount(3)
24 | conLayout.addWidget(tableWidget )
25 |
26 | tableWidget.setHorizontalHeaderLabels(['姓名','性别','体重(kg)'])
27 | #tableWidget.setVerticalHeaderLabels(['行1','行2','行3','行4' ])
28 | tableWidget.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
29 |
30 | newItem = QTableWidgetItem("张三")
31 | tableWidget.setItem(0, 0, newItem)
32 |
33 | newItem = QTableWidgetItem("男")
34 | tableWidget.setItem(0, 1, newItem)
35 |
36 | newItem = QTableWidgetItem("160")
37 | tableWidget.setItem(0, 2, newItem)
38 |
39 | self.setLayout(conLayout)
40 |
41 | if __name__ == '__main__':
42 | app = QApplication(sys.argv)
43 | example = Table()
44 | example.show()
45 | sys.exit(app.exec_())
46 |
--------------------------------------------------------------------------------
/Chapter05/qt05_tblViewModel.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | '''
3 | 【简介】
4 | PyQT5中QTableView表格视图控件的例子
5 |
6 |
7 | '''
8 |
9 | from PyQt5.QtWidgets import *
10 | from PyQt5.QtGui import *
11 | from PyQt5.QtCore import *
12 | import sys
13 |
14 | class Table(QWidget):
15 |
16 | def __init__(self, arg=None):
17 | super(Table, self).__init__(arg)
18 | self.setWindowTitle("QTableView表格视图控件的例子")
19 | self.resize(500,300);
20 | self.model=QStandardItemModel(4,4);
21 | self.model.setHorizontalHeaderLabels(['标题1','标题2','标题3','标题4'])
22 |
23 | for row in range(4):
24 | for column in range(4):
25 | item = QStandardItem("row %s, column %s"%(row,column))
26 | self.model.setItem(row, column, item)
27 |
28 | self.tableView=QTableView()
29 | self.tableView.setModel(self.model)
30 | #下面代码让表格100填满窗口
31 | #self.tableView.horizontalHeader().setStretchLastSection(True)
32 | #self.tableView.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
33 | dlgLayout=QVBoxLayout();
34 | dlgLayout.addWidget(self.tableView)
35 | self.setLayout(dlgLayout)
36 |
37 | if __name__ == '__main__':
38 | app = QApplication(sys.argv)
39 | table = Table()
40 | table.show()
41 | sys.exit(app.exec_())
42 |
--------------------------------------------------------------------------------
/Chapter05/qt05_thread01.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | '''
3 | 【简介】
4 | PyQT5中 QThread 例子
5 |
6 |
7 | '''
8 |
9 | import sys
10 | from PyQt5.QtCore import *
11 | from PyQt5.QtGui import *
12 | from PyQt5.QtWidgets import *
13 |
14 | global sec
15 | sec=0
16 |
17 | def setTime():
18 | global sec
19 | sec+=1
20 | # LED显示数字+1
21 | lcdNumber.display(sec)
22 |
23 | def work():
24 | # 计时器每秒计数
25 | timer.start(1000)
26 | for i in range(2000000000):
27 | pass
28 |
29 | timer.stop()
30 |
31 | if __name__ == "__main__":
32 | app = QApplication(sys.argv)
33 | top = QWidget()
34 | top.resize(300,120)
35 |
36 | # 垂直布局类QVBoxLayout
37 | layout = QVBoxLayout(top)
38 | # 加个显示屏
39 | lcdNumber = QLCDNumber()
40 | layout.addWidget(lcdNumber)
41 | button=QPushButton("测试")
42 | layout.addWidget(button)
43 |
44 | timer = QTimer()
45 | # 每次计时结束,触发setTime
46 | timer.timeout.connect(setTime)
47 | button.clicked.connect(work)
48 |
49 | top.show()
50 | sys.exit(app.exec_())
51 |
--------------------------------------------------------------------------------
/Chapter05/qt05_timer02.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | '''
3 | 【简介】
4 | PyQT5中关闭应用例子
5 |
6 |
7 | '''
8 |
9 | import sys
10 | from PyQt5.QtWidgets import *
11 | from PyQt5.QtGui import *
12 | from PyQt5.QtCore import *
13 |
14 | if __name__ == '__main__':
15 | app = QApplication(sys.argv)
16 | label = QLabel("Hello PyQT,窗口会在10秒后消失!")
17 | label.setWindowFlags(Qt.SplashScreen|Qt.FramelessWindowHint)
18 | label.show()
19 |
20 | # 设置10s后自动退出
21 | QTimer.singleShot(10000, app.quit)
22 | sys.exit(app.exec_())
23 |
--------------------------------------------------------------------------------
/Chapter05/qt05_treeview.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | '''
4 | 【简介】
5 | PyQT5中 QTreeView 例子
6 |
7 |
8 | '''
9 |
10 | import sys
11 | from PyQt5.QtWidgets import *
12 | from PyQt5.QtGui import *
13 |
14 | if __name__ == '__main__':
15 | app = QApplication(sys.argv)
16 | #Window系统提供的模式
17 | model = QDirModel()
18 | #创建一个QtreeView部件
19 | tree = QTreeView()
20 | #为部件添加模式
21 | tree.setModel(model)
22 | tree.setWindowTitle( "QTreeView 例子" )
23 | tree.resize(640, 480)
24 | tree.show()
25 | sys.exit(app.exec_())
26 |
--------------------------------------------------------------------------------
/Chapter05/qt05_webview01.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | '''
4 | 【简介】
5 | QWebView打开网页例子
6 |
7 | '''
8 |
9 | from PyQt5.QtCore import *
10 | from PyQt5.QtGui import *
11 | from PyQt5.QtWidgets import *
12 | from PyQt5.QtWebEngineWidgets import *
13 | import sys
14 |
15 | class MainWindow(QMainWindow):
16 |
17 | def __init__(self ):
18 | super(QMainWindow, self).__init__()
19 | self.setWindowTitle('打开外部网页例子')
20 | self.setGeometry(5, 30, 1355, 730)
21 | self.browser = QWebEngineView()
22 | # 加载外部页面
23 | self.browser.load(QUrl('http://www.cnblogs.com/wangshuo1'))
24 | self.setCentralWidget(self.browser)
25 |
26 | if __name__ == '__main__':
27 | app = QApplication(sys.argv)
28 | win = MainWindow()
29 | win.show()
30 | sys.exit(app.exec_())
31 |
--------------------------------------------------------------------------------
/Chapter05/qt05_webview02.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | '''
4 | 【简介】
5 | QWebEngineView 打开本地网页例子
6 |
7 | '''
8 |
9 | from PyQt5.QtCore import *
10 | from PyQt5.QtGui import *
11 | from PyQt5.QtWidgets import *
12 | from PyQt5.QtWebEngineWidgets import *
13 | import sys
14 |
15 | class MainWindow(QMainWindow):
16 |
17 | def __init__(self ):
18 | super(QMainWindow, self).__init__()
19 | self.setWindowTitle('加载并显示本地页面例子')
20 | self.setGeometry(5, 30, 755, 530)
21 | self.browser = QWebEngineView()
22 | # 加载本地页面
23 | url = r'E:/quant/PyQt5/Chapter05/index.html'
24 | self.browser.load( QUrl( url ))
25 | self.setCentralWidget(self.browser)
26 |
27 | if __name__ == '__main__':
28 | app = QApplication(sys.argv)
29 | win = MainWindow()
30 | win.show()
31 | sys.exit(app.exec_())
32 |
--------------------------------------------------------------------------------
/Chapter05/qt05_webview03.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | '''
4 | 【简介】
5 | QWebView打开网页例子
6 |
7 | '''
8 |
9 | from PyQt5.QtCore import *
10 | from PyQt5.QtGui import *
11 | from PyQt5.QtWidgets import *
12 | from PyQt5.QtWebEngineWidgets import *
13 | import sys
14 |
15 | class MainWindow(QMainWindow):
16 |
17 | def __init__(self ):
18 | super(QMainWindow, self).__init__()
19 | self.setWindowTitle('QWebView打开网页例子')
20 | self.setGeometry(5, 30, 1355, 730)
21 | self.browser = QWebEngineView()
22 | #1 加载html代码
23 | self.browser = QWebEngineView()
24 | self.browser.setHtml('''
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 | Hello PyQt5
33 | Hello PyQt5
34 | hello PyQt5
35 | hello PyQt5
36 | hello PyQt5
37 | Hello PyQt5
38 |
39 |
40 |
41 |
42 | '''
43 | )
44 |
45 | self.setCentralWidget(self.browser)
46 |
47 | if __name__ == '__main__':
48 | app = QApplication(sys.argv)
49 |
50 | win = MainWindow()
51 | win.show()
52 | sys.exit(app.exec_())
53 |
--------------------------------------------------------------------------------
/Chapter05/qt502_webviewJs02.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | '''
4 | 【简介】
5 | QWebView中网页调用JavaScript
6 |
7 | '''
8 |
9 | from PyQt5.QtWidgets import QApplication , QWidget , QVBoxLayout
10 | from PyQt5.QtWebEngineWidgets import QWebEngineView
11 | from PyQt5.QtCore import QUrl
12 | from MySharedObject import MySharedObject
13 | from PyQt5.QtWebChannel import QWebChannel
14 | import sys
15 |
16 |
17 | # 创建一个 application实例
18 | app = QApplication(sys.argv)
19 | win = QWidget()
20 | win.setWindowTitle('Web页面中的JavaScript与 QWebEngineView交互例子')
21 |
22 | # 创建一个垂直布局器
23 | layout = QVBoxLayout()
24 | win.setLayout(layout)
25 |
26 | # 创建一个 QWebEngineView 对象
27 | view = QWebEngineView()
28 | htmlUrl = 'http://127.0.0.1:8020/web/index.html'
29 | view.load( QUrl( htmlUrl ))
30 |
31 | # 创建一个 QWebChannel对象,用来传递pyqt参数到JavaScript
32 | channel = QWebChannel( )
33 | myObj = MySharedObject()
34 | channel.registerObject( "bridge", myObj )
35 | view.page().setWebChannel(channel)
36 |
37 | # 把QWebView和button加载到layout布局中
38 | layout.addWidget(view)
39 |
40 | # 显示窗口和运行app
41 | win.show()
42 | sys.exit(app.exec_())
43 |
--------------------------------------------------------------------------------
/Chapter05/web/index2.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
18 |
19 |
20 |
21 | 字段1:
22 | 字段2:
23 |
24 |
25 |
26 | 在按钮点击时触发函数。函数将字段1的文字信息复制到字段2。
27 |
28 |
29 |
--------------------------------------------------------------------------------
/Chapter06/qt06_QSplitter.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | '''
4 | 【简介】
5 | PyQt5中 QSplitter 例子
6 |
7 |
8 | '''
9 |
10 | import sys
11 | from PyQt5.QtCore import *
12 | from PyQt5.QtGui import *
13 | from PyQt5.QtWidgets import *
14 |
15 | class SplitterExample(QWidget):
16 | def __init__(self):
17 | super(SplitterExample, self).__init__()
18 | self.initUI()
19 |
20 | def initUI(self):
21 | hbox = QHBoxLayout(self)
22 | self.setWindowTitle('QSplitter 例子')
23 | self.setGeometry(300, 300, 300, 200)
24 | topleft = QFrame()
25 | topleft.setFrameShape(QFrame.StyledPanel)
26 |
27 | bottom = QFrame()
28 | bottom.setFrameShape(QFrame.StyledPanel)
29 |
30 | splitter1 = QSplitter(Qt.Horizontal)
31 | textedit = QTextEdit()
32 | splitter1.addWidget(topleft)
33 | splitter1.addWidget(textedit)
34 | splitter1.setSizes([100,200])
35 | splitter2 = QSplitter(Qt.Vertical)
36 | splitter2.addWidget(splitter1)
37 | splitter2.addWidget(bottom)
38 | hbox.addWidget(splitter2)
39 | self.setLayout(hbox)
40 |
41 | if __name__ == '__main__':
42 | app = QApplication(sys.argv)
43 | demo = SplitterExample()
44 | demo.show()
45 | sys.exit(app.exec_())
46 |
47 |
--------------------------------------------------------------------------------
/Chapter06/qt06_absoPosition .py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | '''
4 | 【简介】
5 | PyQT5中Absolute positioning(绝对定位)例子
6 |
7 | '''
8 |
9 | import sys
10 | from PyQt5.QtWidgets import QWidget, QLabel, QApplication
11 |
12 | class Example(QWidget):
13 | def __init__(self):
14 | super().__init__()
15 | self.initUI()
16 |
17 | def initUI(self):
18 | lbl1 = QLabel('欢迎', self)
19 | lbl1.move(15, 10)
20 |
21 | lbl2 = QLabel('学习', self)
22 | lbl2.move(35, 40)
23 |
24 | lbl3 = QLabel('PyQt5 !', self)
25 | lbl3.move(55, 70)
26 |
27 | self.setGeometry(300, 300, 320, 120)
28 | self.setWindowTitle('绝对位置布局例子')
29 |
30 | if __name__ == '__main__':
31 | app = QApplication(sys.argv)
32 | demo = Example()
33 | demo.show()
34 | sys.exit(app.exec_())
35 |
--------------------------------------------------------------------------------
/Chapter06/qt06_boxLayout01.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | """
4 | 【简介】
5 | 水平布局管理例子
6 |
7 | """
8 |
9 | import sys
10 | from PyQt5.QtWidgets import QApplication ,QWidget ,QHBoxLayout , QPushButton
11 | from PyQt5.QtCore import Qt
12 |
13 | class Winform(QWidget):
14 | def __init__(self,parent=None):
15 | super(Winform,self).__init__(parent)
16 | self.setWindowTitle("水平布局管理例子")
17 |
18 | # 水平布局按照从左到右的顺序进行添加按钮部件。
19 | hlayout = QHBoxLayout()
20 |
21 | hlayout.addWidget( QPushButton(str(1)) )
22 | hlayout.addWidget( QPushButton(str(2)) )
23 | hlayout.addWidget( QPushButton(str(3)))
24 | hlayout.addWidget( QPushButton(str(4)) )
25 | hlayout.addWidget( QPushButton(str(5)))
26 |
27 | #设置控件间的间距
28 | hlayout.setSpacing( 0 )
29 | self.setLayout(hlayout)
30 |
31 | if __name__ == "__main__":
32 | app = QApplication(sys.argv)
33 | form = Winform()
34 | form.show()
35 | sys.exit(app.exec_())
36 |
--------------------------------------------------------------------------------
/Chapter06/qt06_boxLayout02.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | """
4 | 【简介】
5 | 水平布局管理例子
6 |
7 | """
8 |
9 | import sys
10 | from PyQt5.QtWidgets import QApplication ,QWidget ,QHBoxLayout , QPushButton
11 | from PyQt5.QtCore import Qt
12 |
13 | class Winform(QWidget):
14 | def __init__(self,parent=None):
15 | super(Winform,self).__init__(parent)
16 | self.setWindowTitle("水平布局管理例子")
17 | self.resize(800, 200)
18 |
19 | # 水平布局按照从左到右的顺序进行添加按钮部件。
20 | hlayout = QHBoxLayout()
21 |
22 | #水平居左 垂直居上
23 | hlayout.addWidget( QPushButton(str(1)) , 0 , Qt.AlignLeft | Qt.AlignTop)
24 | hlayout.addWidget( QPushButton(str(2)) , 0 , Qt.AlignLeft | Qt.AlignTop)
25 | hlayout.addWidget( QPushButton(str(3)))
26 | #水平居左 垂直居下
27 | hlayout.addWidget( QPushButton(str(4)) , 0 , Qt.AlignLeft | Qt.AlignBottom )
28 | hlayout.addWidget( QPushButton(str(5)), 0 , Qt.AlignLeft | Qt.AlignBottom)
29 |
30 |
31 |
32 | self.setLayout(hlayout)
33 |
34 | if __name__ == "__main__":
35 | app = QApplication(sys.argv)
36 | form = Winform()
37 | form.show()
38 | sys.exit(app.exec_())
39 |
--------------------------------------------------------------------------------
/Chapter06/qt06_formLayout.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | """
4 | 【简介】
5 | 垂直布局管理例子
6 |
7 |
8 | """
9 |
10 | import sys
11 | from PyQt5.QtWidgets import QApplication ,QWidget ,QFormLayout , QLineEdit, QLabel
12 |
13 | class Winform(QWidget):
14 | def __init__(self,parent=None):
15 | super(Winform,self).__init__(parent)
16 | self.setWindowTitle("窗体布局管理例子")
17 | self.resize(400, 100)
18 |
19 | fromlayout = QFormLayout()
20 | labl1 = QLabel("标签1")
21 | lineEdit1 = QLineEdit()
22 | labl2 = QLabel("标签2")
23 | lineEdit2 = QLineEdit()
24 | labl3 = QLabel("标签3")
25 | lineEdit3 = QLineEdit()
26 |
27 | fromlayout.addRow(labl1, lineEdit1)
28 | fromlayout.addRow(labl2, lineEdit2)
29 | fromlayout.addRow(labl3, lineEdit3)
30 |
31 | self.setLayout(fromlayout)
32 |
33 | if __name__ == "__main__":
34 | app = QApplication(sys.argv)
35 | form = Winform()
36 | form.show()
37 | sys.exit(app.exec_())
38 |
--------------------------------------------------------------------------------
/Chapter06/qt06_gridLayout01.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | """
4 | 【简介】
5 | 网格布局管理例子
6 |
7 |
8 | """
9 |
10 | import sys
11 | from PyQt5.QtWidgets import QApplication ,QWidget , QGridLayout, QPushButton
12 |
13 | class Winform(QWidget):
14 | def __init__(self,parent=None):
15 | super(Winform,self).__init__(parent)
16 | self.initUI()
17 |
18 | def initUI(self):
19 | #1
20 | grid = QGridLayout()
21 | self.setLayout(grid)
22 |
23 | #2
24 | names = ['Cls', 'Back', '', 'Close',
25 | '7', '8', '9', '/',
26 | '4', '5', '6', '*',
27 | '1', '2', '3', '-',
28 | '0', '.', '=', '+']
29 |
30 | #3
31 | positions = [(i,j) for i in range(5) for j in range(4)]
32 |
33 | #4
34 | for position, name in zip(positions, names):
35 | if name == '':
36 | continue
37 |
38 | button = QPushButton(name)
39 | grid.addWidget(button, *position)
40 |
41 | self.move(300, 150)
42 | self.setWindowTitle('网格布局管理例子')
43 |
44 | if __name__ == "__main__":
45 | app = QApplication(sys.argv)
46 | form = Winform()
47 | form.show()
48 | sys.exit(app.exec_())
49 |
--------------------------------------------------------------------------------
/Chapter06/qt06_gridLayout02.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | """
4 | 【简介】
5 | 网格布局管理例子
6 |
7 |
8 | """
9 |
10 | import sys
11 | from PyQt5.QtWidgets import (QWidget, QLabel, QLineEdit, QTextEdit, QGridLayout, QApplication)
12 |
13 | class Winform(QWidget):
14 | def __init__(self,parent=None):
15 | super(Winform,self).__init__(parent)
16 | self.initUI()
17 |
18 | def initUI(self):
19 | titleLabel = QLabel('标题')
20 | authorLabel = QLabel('提交人')
21 | contentLabel = QLabel('申告内容')
22 |
23 | titleEdit = QLineEdit()
24 | authorEdit = QLineEdit()
25 | contentEdit = QTextEdit()
26 |
27 | grid = QGridLayout()
28 | grid.setSpacing(10)
29 |
30 | grid.addWidget(titleLabel, 1, 0)
31 | grid.addWidget(titleEdit, 1, 1)
32 |
33 | grid.addWidget(authorLabel, 2, 0)
34 | grid.addWidget(authorEdit, 2, 1)
35 |
36 | grid.addWidget(contentLabel, 3, 0)
37 | grid.addWidget(contentEdit, 3, 1, 5, 1)
38 |
39 | self.setLayout(grid)
40 |
41 | self.setGeometry(300, 300, 350, 300)
42 | self.setWindowTitle('故障申告')
43 |
44 | if __name__ == "__main__":
45 | app = QApplication(sys.argv)
46 | form = Winform()
47 | form.show()
48 | sys.exit(app.exec_())
49 |
--------------------------------------------------------------------------------
/Chapter06/qt06_hboxLayout.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | """
4 | 【简介】
5 | 水平布局管理例子
6 |
7 |
8 | """
9 |
10 | import sys
11 | from PyQt5.QtWidgets import QApplication ,QWidget ,QHBoxLayout , QPushButton
12 |
13 | class Winform(QWidget):
14 | def __init__(self,parent=None):
15 | super(Winform,self).__init__(parent)
16 | self.setWindowTitle("水平布局管理例子")
17 |
18 | # 水平布局按照从左到右的顺序进行添加按钮部件。
19 | hlayout = QHBoxLayout()
20 | hlayout.addWidget( QPushButton(str(1)))
21 | hlayout.addWidget( QPushButton(str(2)))
22 | hlayout.addWidget( QPushButton(str(3)))
23 | hlayout.addWidget( QPushButton(str(4)))
24 | hlayout.addWidget( QPushButton(str(5)))
25 | self.setLayout(hlayout)
26 |
27 | if __name__ == "__main__":
28 | app = QApplication(sys.argv)
29 | form = Winform()
30 | form.show()
31 | sys.exit(app.exec_())
32 |
--------------------------------------------------------------------------------
/Chapter06/qt06_layoutAddStretch01.py:
--------------------------------------------------------------------------------
1 | 2# -*- coding: utf-8 -*-
2 |
3 | '''
4 | 【简介】
5 | 布局中用到的addStretch函数例子
6 |
7 | '''
8 |
9 | from PyQt5.QtWidgets import QApplication ,QWidget, QVBoxLayout , QHBoxLayout ,QPushButton
10 | import sys
11 |
12 | class WindowDemo(QWidget):
13 | def __init__(self ):
14 | super().__init__()
15 |
16 | btn1 = QPushButton(self)
17 | btn2 = QPushButton(self)
18 | btn3 = QPushButton(self)
19 | btn1.setText('button 1')
20 | btn2.setText('button 2')
21 | btn3.setText('button 3')
22 |
23 | hbox = QHBoxLayout()
24 | # 设置伸缩量为1
25 | hbox.addStretch(1)
26 | hbox.addWidget( btn1 )
27 | # 设置伸缩量为1
28 | hbox.addStretch(1)
29 | hbox.addWidget( btn2 )
30 | # 设置伸缩量为1
31 | hbox.addStretch(1)
32 | hbox.addWidget( btn3 )
33 | # 设置伸缩量为1
34 | hbox.addStretch(1 )
35 |
36 | self.setLayout(hbox)
37 | self.setWindowTitle("addStretch 例子")
38 |
39 | if __name__ == "__main__":
40 | app = QApplication(sys.argv)
41 | win = WindowDemo()
42 | win.show()
43 | sys.exit(app.exec_())
44 |
45 |
46 |
--------------------------------------------------------------------------------
/Chapter06/qt06_layoutAddStretch02.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | """
4 | 【简介】
5 | 水平布局管理例子
6 |
7 | """
8 |
9 | import sys
10 | from PyQt5.QtWidgets import QApplication ,QWidget ,QHBoxLayout , QPushButton
11 |
12 | class Winform(QWidget):
13 | def __init__(self,parent=None):
14 | super(Winform,self).__init__(parent)
15 | self.setWindowTitle("水平布局管理例子")
16 | self.resize(800, 50)
17 |
18 | # 水平布局按照从左到右的顺序进行添加按钮部件。
19 | hlayout = QHBoxLayout()
20 | # 添加伸缩
21 | hlayout.addStretch(0)
22 |
23 | hlayout.addWidget( QPushButton(str(1)) )
24 | hlayout.addWidget( QPushButton(str(2)) )
25 | hlayout.addWidget( QPushButton(str(3)))
26 | hlayout.addWidget( QPushButton(str(4)) )
27 | hlayout.addWidget( QPushButton(str(5)) )
28 | # 添加伸缩
29 | #hlayout.addStretch(1)
30 |
31 | self.setLayout(hlayout)
32 |
33 | if __name__ == "__main__":
34 | app = QApplication(sys.argv)
35 | form = Winform()
36 | form.show()
37 | sys.exit(app.exec_())
38 |
--------------------------------------------------------------------------------
/Chapter06/qt06_layoutAddStretch03.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | """
4 | 【简介】
5 | 水平布局管理例子
6 |
7 | """
8 |
9 | import sys
10 | from PyQt5.QtWidgets import QApplication ,QWidget ,QHBoxLayout , QPushButton
11 |
12 | class Winform(QWidget):
13 | def __init__(self,parent=None):
14 | super(Winform,self).__init__(parent)
15 | self.setWindowTitle("水平布局管理例子")
16 | self.resize(800, 50)
17 |
18 | # 水平布局按照从左到右的顺序进行添加按钮部件。
19 | hlayout = QHBoxLayout()
20 |
21 | hlayout.addWidget( QPushButton(str(1)) )
22 | hlayout.addWidget( QPushButton(str(2)) )
23 | hlayout.addWidget( QPushButton(str(3)))
24 | hlayout.addWidget( QPushButton(str(4)) )
25 | hlayout.addWidget( QPushButton(str(5)))
26 | # 添加伸缩控件
27 | hlayout.addStretch(0)
28 |
29 | #设置间距
30 | #hlayout.setSpacing( 10 )
31 |
32 |
33 | self.setLayout(hlayout)
34 |
35 | if __name__ == "__main__":
36 | app = QApplication(sys.argv)
37 | form = Winform()
38 | form.show()
39 | sys.exit(app.exec_())
40 |
--------------------------------------------------------------------------------
/Chapter06/qt06_vboxLayout.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | """
4 | 【简介】
5 | 垂直布局管理例子
6 |
7 |
8 | """
9 |
10 | import sys
11 | from PyQt5.QtWidgets import QApplication ,QWidget ,QVBoxLayout , QPushButton
12 |
13 | class Winform(QWidget):
14 | def __init__(self,parent=None):
15 | super(Winform,self).__init__(parent)
16 | self.setWindowTitle("垂直布局管理例子")
17 | self.resize(330, 150)
18 | # 垂直布局按照从上到下的顺序进行添加按钮部件。
19 | vlayout = QVBoxLayout()
20 | vlayout.addWidget( QPushButton(str(1)))
21 | vlayout.addWidget( QPushButton(str(2)))
22 | vlayout.addWidget( QPushButton(str(3)))
23 | vlayout.addWidget( QPushButton(str(4)))
24 | vlayout.addWidget( QPushButton(str(5)))
25 | self.setLayout(vlayout)
26 |
27 | if __name__ == "__main__":
28 | app = QApplication(sys.argv)
29 | form = Winform()
30 | form.show()
31 | sys.exit(app.exec_())
32 |
--------------------------------------------------------------------------------
/Chapter07/__pycache__/MainWinSignalSlog02.cpython-35.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter07/__pycache__/MainWinSignalSlog02.cpython-35.pyc
--------------------------------------------------------------------------------
/Chapter07/__pycache__/MainWinSignalSlog02.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter07/__pycache__/MainWinSignalSlog02.cpython-36.pyc
--------------------------------------------------------------------------------
/Chapter07/__pycache__/ui_calc.cpython-35.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter07/__pycache__/ui_calc.cpython-35.pyc
--------------------------------------------------------------------------------
/Chapter07/calc.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | """
4 | 【简介】信号/槽的装饰器实现方式
5 |
6 |
7 |
8 | """
9 |
10 | import sys
11 | from PyQt5.QtCore import pyqtSlot
12 | from PyQt5.QtWidgets import QApplication, QWidget
13 | from ui_calc import Ui_Calc
14 |
15 | class MyCalc(QWidget):
16 | def __init__(self, parent=None):
17 | super().__init__(parent)
18 | self.ui = Ui_Calc()
19 | self.ui.setupUi(self)
20 |
21 | @pyqtSlot(int)
22 | def on_inputSpinBox1_valueChanged(self, value):
23 | self.ui.outputWidget.setText(str(value + self.ui.inputSpinBox2.value()))
24 |
25 | @pyqtSlot(int)
26 | def on_inputSpinBox2_valueChanged(self, value):
27 | self.ui.outputWidget.setText(str(value + self.ui.inputSpinBox1.value()))
28 |
29 |
30 | if __name__ == '__main__':
31 | app = QApplication(sys.argv)
32 | win = MyCalc()
33 | win.show()
34 | sys.exit(app.exec_())
--------------------------------------------------------------------------------
/Chapter07/images/cartoon1.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter07/images/cartoon1.ico
--------------------------------------------------------------------------------
/Chapter07/images/cartoon2.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter07/images/cartoon2.ico
--------------------------------------------------------------------------------
/Chapter07/images/cartoon3.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter07/images/cartoon3.ico
--------------------------------------------------------------------------------
/Chapter07/images/cartoon4.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter07/images/cartoon4.ico
--------------------------------------------------------------------------------
/Chapter07/images/python.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter07/images/python.jpg
--------------------------------------------------------------------------------
/Chapter07/qt07_buildInSignalSlot01.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | """
4 | 【简介】
5 | 内置的信号/槽示例
6 |
7 |
8 | """
9 |
10 | from PyQt5.QtWidgets import *
11 | import sys
12 |
13 | class Winform(QWidget):
14 | def __init__(self,parent=None):
15 | super().__init__(parent)
16 | self.setWindowTitle('内置的信号/槽示例')
17 | self.resize(330, 50 )
18 | btn = QPushButton('关闭', self)
19 | btn.clicked.connect(self.close)
20 |
21 | if __name__ == '__main__':
22 | app = QApplication(sys.argv)
23 | win = Winform()
24 | win.show()
25 | sys.exit(app.exec_())
26 |
--------------------------------------------------------------------------------
/Chapter07/qt07_buildInSignalSlot02.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | """
4 | 【简介】
5 | 内置的信号,自定义槽函数示例
6 |
7 |
8 | """
9 |
10 | from PyQt5.QtWidgets import *
11 | import sys
12 |
13 | class Winform(QWidget):
14 | def __init__(self,parent=None):
15 | super().__init__(parent)
16 | self.setWindowTitle('内置的信号和自定义槽函数示例')
17 | self.resize(330, 50 )
18 | btn = QPushButton('关闭', self)
19 | btn.clicked.connect(self.btn_close)
20 |
21 | def btn_close(self):
22 | # 自定义槽函数
23 | self.close()
24 |
25 | if __name__ == '__main__':
26 | app = QApplication(sys.argv)
27 | win = Winform()
28 | win.show()
29 | sys.exit(app.exec_())
30 |
--------------------------------------------------------------------------------
/Chapter07/qt07_buildInSignalSlot03.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | """
4 | 【简介】
5 | 自定义信号和内置槽函数 示例
6 |
7 |
8 | """
9 |
10 | from PyQt5.QtWidgets import *
11 | from PyQt5.QtCore import pyqtSignal
12 | import sys
13 |
14 | class Winform(QWidget):
15 | # 自定义信号,不带参数
16 | button_clicked_signal = pyqtSignal()
17 |
18 | def __init__(self,parent=None):
19 | super().__init__(parent)
20 | self.setWindowTitle('自定义信号和内置槽函数示例')
21 | self.resize(330, 50 )
22 | btn = QPushButton('关闭', self)
23 | # 连接 信号和槽
24 | btn.clicked.connect(self.btn_clicked)
25 | # 接收信号,连接到槽
26 | self.button_clicked_signal.connect(self.close)
27 |
28 | def btn_clicked(self):
29 | # 发送自定义信号,无参数
30 | self.button_clicked_signal.emit()
31 |
32 | if __name__ == '__main__':
33 | app = QApplication(sys.argv)
34 | win = Winform()
35 | win.show()
36 | sys.exit(app.exec_())
37 |
--------------------------------------------------------------------------------
/Chapter07/qt07_buildInSignalSlot04.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | """
4 | 【简介】
5 | 自定义信号和槽函数 示例
6 |
7 |
8 | """
9 |
10 | from PyQt5.QtWidgets import *
11 | from PyQt5.QtCore import pyqtSignal
12 | import sys
13 |
14 | class Winform(QWidget):
15 | # 自定义信号,不带参数
16 | button_clicked_signal = pyqtSignal()
17 |
18 | def __init__(self,parent=None):
19 | super().__init__(parent)
20 | self.setWindowTitle('自定义信号和槽函数示例')
21 | self.resize(330, 50 )
22 | btn = QPushButton('关闭', self)
23 | # 连接 信号和槽
24 | btn.clicked.connect(self.btn_clicked)
25 | # 接收信号,连接到自定义槽函数
26 | self.button_clicked_signal.connect(self.btn_close)
27 |
28 | def btn_clicked(self):
29 | # 发送自定义信号,无参数
30 | self.button_clicked_signal.emit()
31 |
32 | def btn_close(self):
33 | self.close()
34 |
35 | if __name__ == '__main__':
36 | app = QApplication(sys.argv)
37 | win = Winform()
38 | win.show()
39 | sys.exit(app.exec_())
40 |
--------------------------------------------------------------------------------
/Chapter07/qt07_connSlotsByName.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | """
4 | 【简介】
5 | 信号和槽的自动连接例子
6 |
7 |
8 | """
9 |
10 | from PyQt5 import QtCore
11 | from PyQt5.QtWidgets import QApplication ,QWidget ,QHBoxLayout , QPushButton
12 | import sys
13 |
14 | class CustWidget( QWidget ):
15 |
16 | def __init__(self, parent=None):
17 | super(CustWidget, self).__init__(parent)
18 |
19 | self.okButton = QPushButton("OK", self)
20 | #使用setObjectName设置对象名称
21 | self.okButton.setObjectName("okButton")
22 | layout = QHBoxLayout()
23 | layout.addWidget(self.okButton)
24 | self.setLayout(layout)
25 | QtCore.QMetaObject.connectSlotsByName(self)
26 |
27 | @QtCore.pyqtSlot()
28 | def on_okButton_clicked(self):
29 | print( "点击了OK按钮")
30 |
31 |
32 | if __name__ == "__main__":
33 | app = QApplication(sys.argv)
34 | win = CustWidget()
35 | win.show()
36 | sys.exit(app.exec_())
37 |
--------------------------------------------------------------------------------
/Chapter07/qt07_connSlotsByName_2.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | """
4 | 【简介】
5 | 信号和槽的自动连接例子
6 | """
7 |
8 | from PyQt5 import QtCore
9 | from PyQt5.QtWidgets import QApplication ,QWidget ,QHBoxLayout , QPushButton
10 | import sys
11 |
12 | class CustWidget( QWidget ):
13 |
14 | def __init__(self, parent=None):
15 | super(CustWidget, self).__init__(parent)
16 |
17 | self.okButton = QPushButton("OK", self)
18 | #使用setObjectName设置对象名称
19 | self.okButton.setObjectName("okButton")
20 | layout = QHBoxLayout()
21 | layout.addWidget(self.okButton)
22 | self.setLayout(layout)
23 | QtCore.QMetaObject.connectSlotsByName(self)
24 | self.okButton.clicked.connect(self.okButton_clicked)
25 |
26 | def okButton_clicked(self):
27 | print( "点击了OK按钮")
28 |
29 |
30 | if __name__ == "__main__":
31 | app = QApplication(sys.argv)
32 | win = CustWidget()
33 | win.show()
34 | sys.exit(app.exec_())
35 |
--------------------------------------------------------------------------------
/Chapter07/qt07_pysignalSlot.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | """
4 | 【简介】
5 | 内置信号槽示例
6 |
7 |
8 | """
9 |
10 | from PyQt5.QtCore import QObject, pyqtSignal
11 |
12 |
13 | # 信号对象
14 | class QTypeSignal(QObject):
15 | # 定义一个信号
16 | sendmsg = pyqtSignal(object)
17 |
18 | def __init__(self):
19 | super(QTypeSignal, self).__init__()
20 |
21 | def run(self):
22 | # 发射信号
23 | self.sendmsg.emit('Hello Pyqt5')
24 |
25 |
26 | # 槽对象
27 | class QTypeSlot(QObject):
28 | def __init__(self):
29 | super(QTypeSlot, self).__init__()
30 |
31 | # 槽对象里的槽函数
32 |
33 | def get(self, msg):
34 | print("QSlot get msg => " + msg)
35 |
36 |
37 | if __name__ == '__main__':
38 | send = QTypeSignal()
39 | slot = QTypeSlot()
40 | # 1
41 | print('--- 把信号绑定到槽函数 ---')
42 | send.sendmsg.connect(slot.get)
43 | send.run()
44 |
45 | # 2
46 | print('--- 把信号断开槽函数 ---')
47 | send.sendmsg.disconnect(slot.get)
48 | send.run()
49 |
--------------------------------------------------------------------------------
/Chapter07/qt07_pysignalSlot_2.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 |
4 | from PyQt5.QtCore import QObject , pyqtSignal
5 |
6 | #信号对象
7 | class QTypeSignal(QObject):
8 | #定义一个信号
9 | sendmsg = pyqtSignal( str,str)
10 |
11 | def __init__( self):
12 | super( QTypeSignal, self).__init__()
13 |
14 | def run( self):
15 | # 发射信号
16 | self.sendmsg.emit('第一个参数','第二个参数')
17 |
18 | # 槽对象
19 | class QTypeSlot(QObject):
20 | def __init__( self):
21 | super( QTypeSlot, self).__init__()
22 |
23 | # 槽对象里的槽函数
24 | def get(self, msg1, msg2):
25 | print("QSlot get msg => " + msg1 + ' ' + msg2)
26 |
27 |
28 | if __name__ == '__main__':
29 | send = QTypeSignal()
30 | slot = QTypeSlot()
31 | #1
32 | print('--- 把信号绑定到槽函数 ---')
33 | send.sendmsg.connect( slot.get)
34 | send.run()
35 |
36 | #2
37 | print('--- 把信号断开槽函数 ---')
38 | send.sendmsg.disconnect( slot.get )
39 | send.run()
40 |
41 |
--------------------------------------------------------------------------------
/Chapter07/qt07_signalSlot01.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | """
4 | 【简介】
5 | 内置信号、自定义槽的演示程序
6 |
7 |
8 | """
9 |
10 | import sys
11 | from PyQt5.QtWidgets import QWidget,QPushButton, QApplication
12 |
13 | class Winform(QWidget):
14 | def __init__(self):
15 | super(Winform, self).__init__()
16 | self.setGeometry(200,300,350,50)
17 | self.setWindowTitle("内置信号、自定义槽的例子")
18 |
19 | self.btn = QPushButton("按钮文本",self)
20 | self.btn.clicked.connect(self.changeBtnText)
21 |
22 | def changeBtnText(self):
23 | self.btn.setText("按钮内容和宽度改变了")
24 | self.btn.setStyleSheet("QPushButton{max-width:200px; min-width:200px}")
25 |
26 | if __name__ == '__main__':
27 | app = QApplication(sys.argv)
28 | qb = Winform()
29 | qb.show()
30 | sys.exit(app.exec_())
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/Chapter07/qt07_signalSlot03.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | """
4 | 【简介】
5 | 信号槽N对N连接、断开连接示例
6 |
7 |
8 | """
9 |
10 | from PyQt5.QtCore import QObject , pyqtSignal
11 |
12 | class SignalClass(QObject):
13 |
14 | # 声明一个无参数的信号
15 | signal1 = pyqtSignal()
16 |
17 | # 声明带一个int类型参数的信号
18 | signal2 = pyqtSignal(int)
19 |
20 | def __init__(self,parent=None):
21 | super(SignalClass,self).__init__(parent)
22 |
23 | # 信号sin1连接到sin1Call和sin2Call这两个槽
24 | self.signal1.connect(self.sin1Call)
25 | self.signal1.connect(self.sin2Call)
26 |
27 | # 信号sin2连接到信号sin1
28 | self.signal2.connect(self.signal1)
29 |
30 | # 信号发射
31 | self.signal1.emit()
32 | self.signal2.emit(1)
33 |
34 | # 断开sin1、sin2信号与各槽的连接
35 | self.signal1.disconnect(self.sin1Call)
36 | self.signal1.disconnect(self.sin2Call)
37 | self.signal2.disconnect(self.signal1)
38 |
39 | # 信号sin1和sin2连接同一个槽sin1Call
40 | self.signal1.connect(self.sin1Call)
41 | self.signal2.connect(self.sin1Call)
42 |
43 | # 信号再次发射
44 | self.signal1.emit()
45 | self.signal2.emit(1)
46 |
47 | def sin1Call(self):
48 | print("signal-1 emit")
49 |
50 | def sin2Call(self):
51 | print("signal-2 emit")
52 |
53 | if __name__ == '__main__':
54 | signal = SignalClass()
55 |
--------------------------------------------------------------------------------
/Chapter07/qt07_signalSlot04.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | """
4 | 【简介】
5 | 多线程信号槽通信示例
6 |
7 |
8 | """
9 |
10 | from PyQt5.QtWidgets import QApplication ,QWidget
11 | from PyQt5.QtCore import QThread , pyqtSignal
12 | import sys
13 |
14 | class Main(QWidget):
15 | def __init__(self, parent = None):
16 | super(Main,self).__init__(parent)
17 |
18 | # 创建一个线程实例并设置名称、变量、信号槽
19 | self.thread = MyThread()
20 | self.thread.setIdentity("thread1")
21 | self.thread.sinOut.connect(self.outText)
22 | self.thread.setVal(6)
23 |
24 | def outText(self,text):
25 | print(text)
26 |
27 | class MyThread(QThread):
28 | sinOut = pyqtSignal(str)
29 |
30 | def __init__(self,parent=None):
31 | super(MyThread,self).__init__(parent)
32 | self.identity = None
33 |
34 | def setIdentity(self,text):
35 | self.identity = text
36 |
37 | def setVal(self,val):
38 | self.times = int(val)
39 | #执行线程的run方法
40 | self.start()
41 |
42 | def run(self):
43 | while self.times > 0 and self.identity:
44 | # 发射信号
45 | self.sinOut.emit(self.identity+"==>"+str(self.times))
46 | self.times -= 1
47 |
48 | if __name__ == '__main__':
49 | app = QApplication(sys.argv)
50 | main = Main()
51 | main.show()
52 | sys.exit(app.exec_())
53 |
--------------------------------------------------------------------------------
/Chapter07/qt07_signalSlot05.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | """
4 | 【简介】
5 | 自定义信号和内置槽示例
6 |
7 |
8 | """
9 |
10 | from PyQt5.QtWidgets import QApplication ,QWidget, QPushButton
11 | from PyQt5.QtCore import pyqtSignal
12 | import sys
13 |
14 | class WinForm(QWidget):
15 | button_clicked_signal = pyqtSignal() # 自定义信号,不带参
16 |
17 | def __init__(self, parent = None):
18 | super(WinForm,self).__init__(parent)
19 | self.resize(330, 50 )
20 | self.setWindowTitle('自定义信号和内置槽示例')
21 |
22 | btn = QPushButton('关闭', self)
23 | # 连接信号/槽
24 | btn.clicked.connect(self.btn_clicked)
25 | # 接收信号,连接到槽
26 | self.button_clicked_signal.connect(self.close)
27 |
28 | def btn_clicked(self):
29 | # 发送无参数的自定义信号
30 | self.button_clicked_signal.emit()
31 |
32 | if __name__ == '__main__':
33 | app = QApplication(sys.argv)
34 | win = WinForm()
35 | win.show()
36 | sys.exit(app.exec_())
37 |
--------------------------------------------------------------------------------
/Chapter07/qt07_winSignalSlot01.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | 【简介】
4 | 信号和槽例子
5 |
6 |
7 | """
8 |
9 | from PyQt5.QtWidgets import QPushButton , QApplication, QWidget
10 | from PyQt5.QtWidgets import QMessageBox
11 | import sys
12 |
13 | app = QApplication(sys.argv)
14 | widget = QWidget()
15 |
16 | def showMsg():
17 | QMessageBox.information(widget, "信息提示框", "ok,弹出测试信息")
18 | btn = QPushButton( "测试点击按钮", widget)
19 | btn.clicked.connect( showMsg)
20 | widget.show()
21 | sys.exit(app.exec_())
22 |
--------------------------------------------------------------------------------
/Chapter07/qt07_winSignalSlot02.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | """
4 | 【简介】
5 | 部件中的信号槽通信示例
6 |
7 |
8 | """
9 |
10 |
11 | from PyQt5.QtWidgets import QMainWindow,QHBoxLayout, QPushButton , QApplication, QWidget
12 | import sys
13 |
14 | class WinForm(QMainWindow):
15 |
16 | def __init__(self, parent=None):
17 | super(WinForm, self).__init__(parent)
18 | self.setWindowTitle('控件中的信号槽通信')
19 |
20 | self.button1 = QPushButton('Button 1')
21 | #
22 | self.button1.clicked.connect(self.onButtonClick)
23 |
24 | layout = QHBoxLayout()
25 | layout.addWidget(self.button1)
26 |
27 | main_frame = QWidget()
28 | main_frame.setLayout(layout)
29 | self.setCentralWidget(main_frame)
30 |
31 | def onButtonClick(self ):
32 | #sender 是发送信号的对象
33 | sender = self.sender()
34 | print( sender.text() + ' 被按下了' )
35 |
36 |
37 | if __name__ == "__main__":
38 | app = QApplication(sys.argv)
39 | form = WinForm()
40 | form.show()
41 | sys.exit(app.exec_())
42 |
--------------------------------------------------------------------------------
/Chapter07/qt07_winSignalSlot03.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | """
4 | 【简介】
5 | 部件中的信号槽通信示例
6 |
7 |
8 | """
9 |
10 | from PyQt5.QtCore import pyqtSignal
11 | from PyQt5.QtWidgets import QMainWindow,QHBoxLayout, QPushButton , QApplication, QWidget , QMessageBox
12 | import sys
13 |
14 | class WinForm(QMainWindow):
15 | btnlickedSignal = pyqtSignal(int)
16 |
17 | def __init__(self, parent=None):
18 | super(WinForm, self).__init__(parent)
19 | self.setWindowTitle('控件中的信号槽通信')
20 | # 声明自定义的信号
21 | self.btnlickedSignal.connect(self.getSignal)
22 | self.button1 = QPushButton('Button 1')
23 | # 使用信号连接槽函数,槽函数不用加括号
24 | self.button1.clicked.connect(self.onButtonClick )
25 |
26 | layout = QHBoxLayout()
27 | layout.addWidget(self.button1)
28 | main_frame = QWidget()
29 | main_frame.setLayout(layout)
30 | self.setCentralWidget(main_frame)
31 |
32 | def onButtonClick(self ):
33 | print('The button1 被按下了' )
34 | self.btnlickedSignal.emit(10)
35 |
36 | def getSignal(self, intVal ):
37 | QMessageBox.information(self, "信息提示框", '收到信号传过来的值:' + str(intVal) )
38 |
39 | if __name__ == "__main__":
40 | app = QApplication(sys.argv)
41 | form = WinForm()
42 | form.show()
43 | sys.exit(app.exec_())
44 |
--------------------------------------------------------------------------------
/Chapter07/qt07_winSignalSlot04.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | """
4 | 【简介】
5 | 部件中的信号槽传递,使用lambda表达式传参数示例
6 |
7 |
8 | """
9 |
10 | from PyQt5.QtWidgets import QMainWindow, QPushButton , QWidget , QMessageBox, QApplication, QHBoxLayout
11 | import sys
12 |
13 | class WinForm(QMainWindow):
14 | def __init__(self, parent=None):
15 | super(WinForm, self).__init__(parent)
16 | self.setWindowTitle("信号和槽传递额外参数例子")
17 | button1 = QPushButton('Button 1')
18 | button2 = QPushButton('Button 2')
19 |
20 | button1.clicked.connect(lambda: self.onButtonClick(1))
21 | button2.clicked.connect(lambda: self.onButtonClick(2))
22 |
23 | layout = QHBoxLayout()
24 | layout.addWidget(button1)
25 | layout.addWidget(button2)
26 |
27 | main_frame = QWidget()
28 | main_frame.setLayout(layout)
29 | self.setCentralWidget(main_frame)
30 |
31 | def onButtonClick(self, n):
32 | print('Button {0} 被按下了'.format(n))
33 | QMessageBox.information(self, "信息提示框", 'Button {0} clicked'.format(n))
34 |
35 | if __name__ == "__main__":
36 | app = QApplication(sys.argv)
37 | form = WinForm()
38 | form.show()
39 | sys.exit(app.exec_())
40 |
--------------------------------------------------------------------------------
/Chapter07/qt07_winSignalSlot05.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | """
4 | 【简介】
5 | 部件中的信号槽传递,使用partial函数传参数示例
6 |
7 |
8 | """
9 |
10 | from PyQt5.QtWidgets import QMainWindow, QPushButton , QWidget , QMessageBox, QApplication, QHBoxLayout
11 | import sys
12 | from functools import partial
13 |
14 | class WinForm(QMainWindow):
15 | def __init__(self, parent=None):
16 | super(WinForm, self).__init__(parent)
17 | self.setWindowTitle("信号和槽传递额外参数例子")
18 | button1 = QPushButton('Button 1')
19 | button2 = QPushButton('Button 2')
20 |
21 | button1.clicked.connect(partial(self.onButtonClick, 1))
22 | button2.clicked.connect(partial(self.onButtonClick, 2))
23 |
24 | layout = QHBoxLayout()
25 | layout.addWidget(button1)
26 | layout.addWidget(button2)
27 |
28 | main_frame = QWidget()
29 | main_frame.setLayout(layout)
30 | self.setCentralWidget(main_frame)
31 |
32 | def onButtonClick(self, n):
33 | print('Button {0} 被按下了'.format(n))
34 | QMessageBox.information(self, "信息提示框", 'Button {0} clicked'.format(n))
35 |
36 | if __name__ == "__main__":
37 | app = QApplication(sys.argv)
38 | form = WinForm()
39 | form.show()
40 | sys.exit(app.exec_())
41 |
--------------------------------------------------------------------------------
/Chapter07/qt07_winSignalSlot06.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | 【简介】
4 | 信号槽连接滑块LCD示例
5 |
6 |
7 | """
8 |
9 | import sys
10 | from PyQt5.QtWidgets import QWidget,QLCDNumber,QSlider,QVBoxLayout,QApplication
11 | from PyQt5.QtCore import Qt
12 |
13 | class WinForm(QWidget):
14 | def __init__(self):
15 | super().__init__()
16 | self.initUI()
17 |
18 | def initUI(self):
19 | #1 先创建滑块和 LCD 部件
20 | lcd = QLCDNumber(self)
21 | slider = QSlider(Qt.Horizontal, self)
22 |
23 | #2 通过QVboxLayout来设置布局
24 | vBox = QVBoxLayout()
25 | vBox.addWidget(lcd)
26 | vBox.addWidget(slider)
27 |
28 | self.setLayout(vBox)
29 | #3 valueChanged()是Qslider的一个信号函数,只要slider的值发生改变,它就会发射一个信号,然后通过connect连接信号的接收部件,也就是lcd。
30 | slider.valueChanged.connect(lcd.display)
31 |
32 | self.setGeometry(300,300,350,150)
33 | self.setWindowTitle("信号与槽:连接滑块LCD")
34 |
35 | if __name__ == '__main__':
36 | app = QApplication(sys.argv)
37 | form = WinForm()
38 | form.show()
39 | sys.exit(app.exec_())
40 |
--------------------------------------------------------------------------------
/Chapter07/qt07_winSignalSlot07.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | 【简介】
4 | 重新实现信号槽函数 示例
5 |
6 |
7 | """
8 |
9 | import sys
10 | from PyQt5.QtWidgets import *
11 | from PyQt5.QtCore import Qt
12 |
13 | class WinForm(QWidget):
14 | def __init__(self):
15 | super().__init__()
16 | self.initUI()
17 |
18 | def initUI(self):
19 | self.setGeometry(300, 300, 400, 300)
20 | self.setWindowTitle('重新实现信号槽函数例子')
21 |
22 | # 重新实现信号槽函数
23 | def keyPressEvent(self, e):
24 | if e.key() == Qt.Key_Escape:
25 | self.close()
26 |
27 | elif e.key() == Qt.Key_Alt:
28 | self.setWindowTitle('按下Alt键')
29 |
30 | if __name__ == '__main__':
31 | app = QApplication(sys.argv)
32 | form = WinForm()
33 | form.show()
34 | sys.exit(app.exec_())
35 |
--------------------------------------------------------------------------------
/Chapter07/transParam/__pycache__/DateDialog.cpython-35.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter07/transParam/__pycache__/DateDialog.cpython-35.pyc
--------------------------------------------------------------------------------
/Chapter07/transParam/__pycache__/DateDialog2.cpython-35.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter07/transParam/__pycache__/DateDialog2.cpython-35.pyc
--------------------------------------------------------------------------------
/Chapter07/ui_calc.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | """
4 | 【简介】信号/槽的装饰器实现方式
5 |
6 |
7 |
8 | """
9 |
10 | from PyQt5 import QtCore, QtGui, QtWidgets
11 |
12 | class Ui_Calc(object):
13 |
14 | def setupUi(self, Form):
15 | self.inputSpinBox1 = QtWidgets.QSpinBox(Form)
16 | self.inputSpinBox1.setGeometry(QtCore.QRect(1, 26, 46, 25))
17 | self.inputSpinBox1.setObjectName("inputSpinBox1") # 必须
18 |
19 | self.inputSpinBox2 = QtWidgets.QSpinBox(Form)
20 | self.inputSpinBox2.setGeometry(QtCore.QRect(70, 26, 46, 25))
21 | self.inputSpinBox2.setObjectName("inputSpinBox2") # 必须
22 |
23 | self.outputWidget = QtWidgets.QLabel(Form)
24 | self.outputWidget.setGeometry(QtCore.QRect(140, 24, 36, 27))
25 | self.outputWidget.setObjectName("outputWidget") # 必须
26 |
27 | QtCore.QMetaObject.connectSlotsByName(Form) # 必须
--------------------------------------------------------------------------------
/Chapter08/CommonHelper.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | class CommonHelper :
4 | def __init__(self ) :
5 | pass
6 |
7 | @staticmethod
8 | def readQss( style):
9 | with open( style , 'r') as f:
10 | return f.read()
11 |
12 |
--------------------------------------------------------------------------------
/Chapter08/QDarkStyleSheet-master/.gitignore:
--------------------------------------------------------------------------------
1 | *.pyc
2 | /style.rcc
3 | /style_pyside_rc.py
4 | ./.idea
5 | /.idea/
6 | /dist/
7 | /QDarkStyle.egg-info/
8 | /build/
9 | __pycache__
10 | *.tar
11 | *.tar.*
12 | *.log
13 | *.log.*
14 | *.sig
15 | pkg/
16 | src/
17 |
18 | # stdeb files
19 | *.tar.gz
20 | deb_dist
21 | /gpg_key
22 |
23 | # gedit temp files
24 | *~
25 |
26 | # hackedit project files
27 | .hackedit
28 |
29 |
--------------------------------------------------------------------------------
/Chapter08/QDarkStyleSheet-master/.travis.yml:
--------------------------------------------------------------------------------
1 | language: python
2 | python:
3 | - "2.7"
4 | - "3.2"
5 | virtualenv:
6 | system_site_packages: true
7 | before_install:
8 | - sudo apt-get update
9 | - sudo apt-get install -qq python-pyside --fix-missing
10 | - sudo apt-get install -qq python-qt4 --fix-missing
11 | - sudo apt-get install -qq python3-pyside --fix-missing
12 | - sudo apt-get install -qq python3-pyqt4 --fix-missing
13 | - "export DISPLAY=:99.0"
14 | - "sh -e /etc/init.d/xvfb start"
15 | before_script:
16 | - cd example
17 | script:
18 | - python example_pyqt.py --travis
19 | - python example_pyside.py --travis
20 |
--------------------------------------------------------------------------------
/Chapter08/QDarkStyleSheet-master/COPYING:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) <2013-2017>
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in
13 | all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | THE SOFTWARE.
22 |
--------------------------------------------------------------------------------
/Chapter08/QDarkStyleSheet-master/MANIFEST.in:
--------------------------------------------------------------------------------
1 | #
2 | # MANIFEST.in
3 | #
4 | # Manifest template for creating the PyLudic source distribution.
5 |
6 | include MANIFEST.in
7 | include setup.py
8 | include COPYING
9 | include README.md
10 | include qdarkstyle/style.qss
11 | include qdarkstyle/style.qrc
12 | include qdarkstyle/rc/*.png
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/Chapter08/QDarkStyleSheet-master/example/ui/__init__.py:
--------------------------------------------------------------------------------
1 | """
2 | This package contains the qt designer files and ui scripts.
3 | """
--------------------------------------------------------------------------------
/Chapter08/QDarkStyleSheet-master/example/ui/compile_ui.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | # Compile example.ui for PyQt and PySide.
3 | pyuic4 --from-imports example.ui > example_pyqt_ui.py
4 | pyuic5 --from-imports example.ui > example_pyqt5_ui.py
5 | pyside-uic --from-imports example.ui > example_pyside_ui.py
6 |
--------------------------------------------------------------------------------
/Chapter08/QDarkStyleSheet-master/makeppa.sh:
--------------------------------------------------------------------------------
1 | #! /bin/bash
2 |
3 | # package info
4 | ppa="ppa:colin-duquesnoy/stable"
5 | name="qdarkstyle"
6 | version="2.0"
7 |
8 | # read pgp key from gpg_key file
9 | gpg_key=`cat gpg_key`
10 |
11 | # generate debian source package and .orig.tar.gz
12 | python3 setup.py --command-packages=stdeb.command sdist_dsc
13 |
14 | date=`date -R`
15 |
16 | # clean pyc files
17 | find . -name "*.pyc" -exec rm -rf {} \;
18 |
19 |
20 | for suite in 'trusty' 'utopic' 'vivid'
21 | do
22 | # sign our package and prepare it for ppa upload
23 | pushd deb_dist
24 | pushd ${name}-${version}
25 |
26 | # update changelog to include ubuntu release
27 | changelog="${name} (${version}-1ppa1~${suite}1) ${suite}; urgency=low
28 | * Initial release
29 | -- Colin Duquesnoy ${date}
30 | "
31 | echo "$changelog" > debian/changelog
32 | cat debian/changelog
33 |
34 | debuild -S -sa -k${gpg_key}
35 | popd
36 |
37 | # upload to ppa
38 | dput ${ppa} *.changes
39 | rm -rf *.dsc *.changes
40 |
41 | popd
42 | done
43 |
44 | # cleanup
45 | rm -rf *.tar.gz deb_dist/ dist/
46 |
--------------------------------------------------------------------------------
/Chapter08/QDarkStyleSheet-master/qdarkstyle/.gitignore:
--------------------------------------------------------------------------------
1 | /*.pyc
2 |
--------------------------------------------------------------------------------
/Chapter08/QDarkStyleSheet-master/qdarkstyle/rc/Hmovetoolbar.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/QDarkStyleSheet-master/qdarkstyle/rc/Hmovetoolbar.png
--------------------------------------------------------------------------------
/Chapter08/QDarkStyleSheet-master/qdarkstyle/rc/Hsepartoolbar.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/QDarkStyleSheet-master/qdarkstyle/rc/Hsepartoolbar.png
--------------------------------------------------------------------------------
/Chapter08/QDarkStyleSheet-master/qdarkstyle/rc/Vmovetoolbar.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/QDarkStyleSheet-master/qdarkstyle/rc/Vmovetoolbar.png
--------------------------------------------------------------------------------
/Chapter08/QDarkStyleSheet-master/qdarkstyle/rc/Vsepartoolbar.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/QDarkStyleSheet-master/qdarkstyle/rc/Vsepartoolbar.png
--------------------------------------------------------------------------------
/Chapter08/QDarkStyleSheet-master/qdarkstyle/rc/branch_closed-on.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/QDarkStyleSheet-master/qdarkstyle/rc/branch_closed-on.png
--------------------------------------------------------------------------------
/Chapter08/QDarkStyleSheet-master/qdarkstyle/rc/branch_closed.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/QDarkStyleSheet-master/qdarkstyle/rc/branch_closed.png
--------------------------------------------------------------------------------
/Chapter08/QDarkStyleSheet-master/qdarkstyle/rc/branch_open-on.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/QDarkStyleSheet-master/qdarkstyle/rc/branch_open-on.png
--------------------------------------------------------------------------------
/Chapter08/QDarkStyleSheet-master/qdarkstyle/rc/branch_open.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/QDarkStyleSheet-master/qdarkstyle/rc/branch_open.png
--------------------------------------------------------------------------------
/Chapter08/QDarkStyleSheet-master/qdarkstyle/rc/checkbox_checked.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/QDarkStyleSheet-master/qdarkstyle/rc/checkbox_checked.png
--------------------------------------------------------------------------------
/Chapter08/QDarkStyleSheet-master/qdarkstyle/rc/checkbox_checked_disabled.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/QDarkStyleSheet-master/qdarkstyle/rc/checkbox_checked_disabled.png
--------------------------------------------------------------------------------
/Chapter08/QDarkStyleSheet-master/qdarkstyle/rc/checkbox_checked_focus.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/QDarkStyleSheet-master/qdarkstyle/rc/checkbox_checked_focus.png
--------------------------------------------------------------------------------
/Chapter08/QDarkStyleSheet-master/qdarkstyle/rc/checkbox_indeterminate.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/QDarkStyleSheet-master/qdarkstyle/rc/checkbox_indeterminate.png
--------------------------------------------------------------------------------
/Chapter08/QDarkStyleSheet-master/qdarkstyle/rc/checkbox_indeterminate_disabled.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/QDarkStyleSheet-master/qdarkstyle/rc/checkbox_indeterminate_disabled.png
--------------------------------------------------------------------------------
/Chapter08/QDarkStyleSheet-master/qdarkstyle/rc/checkbox_indeterminate_focus.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/QDarkStyleSheet-master/qdarkstyle/rc/checkbox_indeterminate_focus.png
--------------------------------------------------------------------------------
/Chapter08/QDarkStyleSheet-master/qdarkstyle/rc/checkbox_unchecked.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/QDarkStyleSheet-master/qdarkstyle/rc/checkbox_unchecked.png
--------------------------------------------------------------------------------
/Chapter08/QDarkStyleSheet-master/qdarkstyle/rc/checkbox_unchecked_disabled.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/QDarkStyleSheet-master/qdarkstyle/rc/checkbox_unchecked_disabled.png
--------------------------------------------------------------------------------
/Chapter08/QDarkStyleSheet-master/qdarkstyle/rc/checkbox_unchecked_focus.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/QDarkStyleSheet-master/qdarkstyle/rc/checkbox_unchecked_focus.png
--------------------------------------------------------------------------------
/Chapter08/QDarkStyleSheet-master/qdarkstyle/rc/close-hover.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/QDarkStyleSheet-master/qdarkstyle/rc/close-hover.png
--------------------------------------------------------------------------------
/Chapter08/QDarkStyleSheet-master/qdarkstyle/rc/close-pressed.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/QDarkStyleSheet-master/qdarkstyle/rc/close-pressed.png
--------------------------------------------------------------------------------
/Chapter08/QDarkStyleSheet-master/qdarkstyle/rc/close.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/QDarkStyleSheet-master/qdarkstyle/rc/close.png
--------------------------------------------------------------------------------
/Chapter08/QDarkStyleSheet-master/qdarkstyle/rc/down_arrow.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/QDarkStyleSheet-master/qdarkstyle/rc/down_arrow.png
--------------------------------------------------------------------------------
/Chapter08/QDarkStyleSheet-master/qdarkstyle/rc/down_arrow_disabled.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/QDarkStyleSheet-master/qdarkstyle/rc/down_arrow_disabled.png
--------------------------------------------------------------------------------
/Chapter08/QDarkStyleSheet-master/qdarkstyle/rc/left_arrow.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/QDarkStyleSheet-master/qdarkstyle/rc/left_arrow.png
--------------------------------------------------------------------------------
/Chapter08/QDarkStyleSheet-master/qdarkstyle/rc/left_arrow_disabled.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/QDarkStyleSheet-master/qdarkstyle/rc/left_arrow_disabled.png
--------------------------------------------------------------------------------
/Chapter08/QDarkStyleSheet-master/qdarkstyle/rc/radio_checked.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/QDarkStyleSheet-master/qdarkstyle/rc/radio_checked.png
--------------------------------------------------------------------------------
/Chapter08/QDarkStyleSheet-master/qdarkstyle/rc/radio_checked_disabled.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/QDarkStyleSheet-master/qdarkstyle/rc/radio_checked_disabled.png
--------------------------------------------------------------------------------
/Chapter08/QDarkStyleSheet-master/qdarkstyle/rc/radio_checked_focus.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/QDarkStyleSheet-master/qdarkstyle/rc/radio_checked_focus.png
--------------------------------------------------------------------------------
/Chapter08/QDarkStyleSheet-master/qdarkstyle/rc/radio_unchecked.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/QDarkStyleSheet-master/qdarkstyle/rc/radio_unchecked.png
--------------------------------------------------------------------------------
/Chapter08/QDarkStyleSheet-master/qdarkstyle/rc/radio_unchecked_disabled.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/QDarkStyleSheet-master/qdarkstyle/rc/radio_unchecked_disabled.png
--------------------------------------------------------------------------------
/Chapter08/QDarkStyleSheet-master/qdarkstyle/rc/radio_unchecked_focus.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/QDarkStyleSheet-master/qdarkstyle/rc/radio_unchecked_focus.png
--------------------------------------------------------------------------------
/Chapter08/QDarkStyleSheet-master/qdarkstyle/rc/right_arrow.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/QDarkStyleSheet-master/qdarkstyle/rc/right_arrow.png
--------------------------------------------------------------------------------
/Chapter08/QDarkStyleSheet-master/qdarkstyle/rc/right_arrow_disabled.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/QDarkStyleSheet-master/qdarkstyle/rc/right_arrow_disabled.png
--------------------------------------------------------------------------------
/Chapter08/QDarkStyleSheet-master/qdarkstyle/rc/sizegrip.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/QDarkStyleSheet-master/qdarkstyle/rc/sizegrip.png
--------------------------------------------------------------------------------
/Chapter08/QDarkStyleSheet-master/qdarkstyle/rc/stylesheet-branch-end.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/QDarkStyleSheet-master/qdarkstyle/rc/stylesheet-branch-end.png
--------------------------------------------------------------------------------
/Chapter08/QDarkStyleSheet-master/qdarkstyle/rc/stylesheet-branch-more.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/QDarkStyleSheet-master/qdarkstyle/rc/stylesheet-branch-more.png
--------------------------------------------------------------------------------
/Chapter08/QDarkStyleSheet-master/qdarkstyle/rc/stylesheet-vline.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/QDarkStyleSheet-master/qdarkstyle/rc/stylesheet-vline.png
--------------------------------------------------------------------------------
/Chapter08/QDarkStyleSheet-master/qdarkstyle/rc/transparent.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/QDarkStyleSheet-master/qdarkstyle/rc/transparent.png
--------------------------------------------------------------------------------
/Chapter08/QDarkStyleSheet-master/qdarkstyle/rc/undock.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/QDarkStyleSheet-master/qdarkstyle/rc/undock.png
--------------------------------------------------------------------------------
/Chapter08/QDarkStyleSheet-master/qdarkstyle/rc/up_arrow.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/QDarkStyleSheet-master/qdarkstyle/rc/up_arrow.png
--------------------------------------------------------------------------------
/Chapter08/QDarkStyleSheet-master/qdarkstyle/rc/up_arrow_disabled.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/QDarkStyleSheet-master/qdarkstyle/rc/up_arrow_disabled.png
--------------------------------------------------------------------------------
/Chapter08/QDarkStyleSheet-master/screenshots/01.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/QDarkStyleSheet-master/screenshots/01.png
--------------------------------------------------------------------------------
/Chapter08/QDarkStyleSheet-master/screenshots/QDarkStyle example 1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/QDarkStyleSheet-master/screenshots/QDarkStyle example 1.png
--------------------------------------------------------------------------------
/Chapter08/QDarkStyleSheet-master/screenshots/QDarkStyle example 2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/QDarkStyleSheet-master/screenshots/QDarkStyle example 2.png
--------------------------------------------------------------------------------
/Chapter08/QDarkStyleSheet-master/setup.cfg:
--------------------------------------------------------------------------------
1 | [bdist_wheel]
2 | universal = 1
3 |
--------------------------------------------------------------------------------
/Chapter08/QDarkStyleSheet-master/stdeb.cfg:
--------------------------------------------------------------------------------
1 | [DEFAULT]
2 | Copyright-File: COPYING
3 |
--------------------------------------------------------------------------------
/Chapter08/__pycache__/CommonHelper.cpython-35.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/__pycache__/CommonHelper.cpython-35.pyc
--------------------------------------------------------------------------------
/Chapter08/images/Cloudy_72px.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/images/Cloudy_72px.png
--------------------------------------------------------------------------------
/Chapter08/images/add.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/images/add.png
--------------------------------------------------------------------------------
/Chapter08/images/addhover.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/images/addhover.png
--------------------------------------------------------------------------------
/Chapter08/images/boy.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/images/boy.png
--------------------------------------------------------------------------------
/Chapter08/images/cartoon1.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/images/cartoon1.ico
--------------------------------------------------------------------------------
/Chapter08/images/cartoon2.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/images/cartoon2.ico
--------------------------------------------------------------------------------
/Chapter08/images/cartoon3.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/images/cartoon3.ico
--------------------------------------------------------------------------------
/Chapter08/images/cartoon4.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/images/cartoon4.ico
--------------------------------------------------------------------------------
/Chapter08/images/dog.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/images/dog.jpg
--------------------------------------------------------------------------------
/Chapter08/images/dog2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/images/dog2.jpg
--------------------------------------------------------------------------------
/Chapter08/images/down.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/images/down.png
--------------------------------------------------------------------------------
/Chapter08/images/down2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/images/down2.png
--------------------------------------------------------------------------------
/Chapter08/images/down3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/images/down3.png
--------------------------------------------------------------------------------
/Chapter08/images/dropdown.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/images/dropdown.png
--------------------------------------------------------------------------------
/Chapter08/images/left.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/images/left.png
--------------------------------------------------------------------------------
/Chapter08/images/left2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/images/left2.png
--------------------------------------------------------------------------------
/Chapter08/images/left3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/images/left3.png
--------------------------------------------------------------------------------
/Chapter08/images/leftHover.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/images/leftHover.png
--------------------------------------------------------------------------------
/Chapter08/images/leftPressed.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/images/leftPressed.png
--------------------------------------------------------------------------------
/Chapter08/images/leftdown.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/images/leftdown.png
--------------------------------------------------------------------------------
/Chapter08/images/leftdown2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/images/leftdown2.png
--------------------------------------------------------------------------------
/Chapter08/images/leftdown3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/images/leftdown3.png
--------------------------------------------------------------------------------
/Chapter08/images/leftup.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/images/leftup.png
--------------------------------------------------------------------------------
/Chapter08/images/leftup2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/images/leftup2.png
--------------------------------------------------------------------------------
/Chapter08/images/leftup3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/images/leftup3.png
--------------------------------------------------------------------------------
/Chapter08/images/loading.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/images/loading.gif
--------------------------------------------------------------------------------
/Chapter08/images/mask.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/images/mask.png
--------------------------------------------------------------------------------
/Chapter08/images/mask2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/images/mask2.png
--------------------------------------------------------------------------------
/Chapter08/images/python.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/images/python.jpg
--------------------------------------------------------------------------------
/Chapter08/images/right.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/images/right.png
--------------------------------------------------------------------------------
/Chapter08/images/right2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/images/right2.png
--------------------------------------------------------------------------------
/Chapter08/images/right3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/images/right3.png
--------------------------------------------------------------------------------
/Chapter08/images/rightdown.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/images/rightdown.png
--------------------------------------------------------------------------------
/Chapter08/images/rightdown2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/images/rightdown2.png
--------------------------------------------------------------------------------
/Chapter08/images/rightdown3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/images/rightdown3.png
--------------------------------------------------------------------------------
/Chapter08/images/rightup.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/images/rightup.png
--------------------------------------------------------------------------------
/Chapter08/images/rightup2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/images/rightup2.png
--------------------------------------------------------------------------------
/Chapter08/images/rightup3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/images/rightup3.png
--------------------------------------------------------------------------------
/Chapter08/images/screen1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/images/screen1.jpg
--------------------------------------------------------------------------------
/Chapter08/images/screen2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/images/screen2.jpg
--------------------------------------------------------------------------------
/Chapter08/images/square_add.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/images/square_add.png
--------------------------------------------------------------------------------
/Chapter08/images/up.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/images/up.png
--------------------------------------------------------------------------------
/Chapter08/images/up2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/images/up2.png
--------------------------------------------------------------------------------
/Chapter08/images/up3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter08/images/up3.png
--------------------------------------------------------------------------------
/Chapter08/qt08_WindowOpacity.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | '''
4 | 【简介】
5 | 设置窗口的透明度
6 |
7 | '''
8 |
9 | from PyQt5.QtWidgets import QApplication, QMainWindow
10 | import sys
11 |
12 | if __name__ == "__main__":
13 | app = QApplication(sys.argv)
14 | win = QMainWindow()
15 | win.setWindowTitle("窗口的透明度设置")
16 | win.setWindowOpacity(0.5)
17 |
18 | win.resize(350, 250)
19 | win.show()
20 | sys.exit(app.exec_())
21 |
22 |
--------------------------------------------------------------------------------
/Chapter08/qt08_animation02.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | """
4 | 【简介】
5 |
6 |
7 |
8 | """
9 |
10 | from PyQt5.QtGui import *
11 | from PyQt5.QtCore import *
12 | from PyQt5.QtWidgets import *
13 | import sys
14 |
15 | app = QApplication(sys.argv)
16 |
17 | window = QMainWindow()
18 | window.show()
19 | animation = QPropertyAnimation(window, b"geometry")
20 | animation.setDuration(10000)
21 | animation.setStartValue(QRect(0, 0, 100, 30))
22 | #animation.setKeyValueAt(0.5, QRect(240, 240, 100, 30));
23 | animation.setEndValue(QRect(250, 250, 100, 30))
24 | # animation.setEasingCurve(QEasingCurve.OutBounce)
25 | animation.start()
26 |
27 | sys.exit(app.exec_())
28 |
--------------------------------------------------------------------------------
/Chapter08/qt08_animation03.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | """
4 | 【简介】
5 | 动画分组
6 |
7 |
8 | """
9 |
10 | from PyQt5.QtGui import *
11 | from PyQt5.QtCore import *
12 | from PyQt5.QtWidgets import *
13 | import sys
14 |
15 | app = QApplication(sys.argv)
16 |
17 | window = QMainWindow()
18 | window.show()
19 | window2 = QMainWindow()
20 | window2.show()
21 |
22 | animation = QPropertyAnimation(window, b"geometry")
23 | animation2 = QPropertyAnimation(window2, b"geometry")
24 |
25 | group = QParallelAnimationGroup()
26 |
27 | animation.setDuration(10000)
28 | animation.setStartValue(QRect(0, 0, 100, 30))
29 | animation.setEndValue(QRect(250, 250, 100, 30))
30 | animation.setEasingCurve(QEasingCurve.OutBounce)
31 |
32 | animation2.setDuration(10000)
33 | animation2.setStartValue(QRect(250, 150, 100, 30))
34 | animation2.setEndValue(QRect(850, 250, 100, 30))
35 | animation2.setEasingCurve(QEasingCurve.CosineCurve)
36 |
37 | group.addAnimation(animation)
38 | group.addAnimation(animation2)
39 | group.start()
40 |
41 | sys.exit(app.exec_())
42 |
--------------------------------------------------------------------------------
/Chapter08/qt08_imgScaled.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | '''
4 | 【简介】
5 | 图片大小缩放
6 |
7 | '''
8 |
9 | from PyQt5.QtWidgets import QApplication, QLabel ,QWidget, QVBoxLayout
10 | from PyQt5.QtGui import QImage , QPixmap
11 | from PyQt5.QtCore import Qt
12 | import sys
13 |
14 | class WindowDemo(QWidget):
15 | def __init__(self ):
16 | super().__init__()
17 | filename = r".\images\Cloudy_72px.png"
18 | img = QImage( filename )
19 |
20 | label1 = QLabel(self)
21 | label1.setFixedWidth(120)
22 | label1.setFixedHeight(120)
23 |
24 | result = img.scaled(label1.width(), label1.height(),Qt.IgnoreAspectRatio, Qt.SmoothTransformation);
25 | label1.setPixmap(QPixmap.fromImage(result))
26 |
27 | #3
28 | vbox=QVBoxLayout()
29 | vbox.addWidget(label1)
30 |
31 | self.setLayout(vbox)
32 | self.setWindowTitle("图片大小缩放例子")
33 |
34 | if __name__ == "__main__":
35 | app = QApplication(sys.argv)
36 | win = WindowDemo()
37 | win.show()
38 | sys.exit(app.exec_())
39 |
40 |
--------------------------------------------------------------------------------
/Chapter08/qt08_loadGif.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | '''
4 | 【简介】
5 | 加载Gif动画效果
6 |
7 | '''
8 |
9 | import sys
10 | from PyQt5.QtWidgets import QApplication, QLabel ,QWidget
11 | from PyQt5.QtCore import Qt
12 | from PyQt5.QtGui import QMovie
13 |
14 | class LoadingGifWin( QWidget):
15 | def __init__(self,parent=None):
16 | super(LoadingGifWin, self).__init__(parent)
17 | self.label = QLabel('', self)
18 | self.setFixedSize(128,128)
19 | self.setWindowFlags( Qt.Dialog| Qt.CustomizeWindowHint)
20 | self.movie = QMovie("./images/loading.gif")
21 | self.label.setMovie(self.movie)
22 | self.movie.start()
23 |
24 | if __name__ == '__main__':
25 | app = QApplication(sys.argv)
26 | loadingGitWin = LoadingGifWin()
27 | loadingGitWin.show()
28 | sys.exit(app.exec_())
29 |
--------------------------------------------------------------------------------
/Chapter08/qt08_loadQss.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | 【简介】
4 | 加载QSS文件
5 |
6 | """
7 | import sys
8 | from PyQt5.QtWidgets import QMainWindow , QApplication, QVBoxLayout , QPushButton
9 | from CommonHelper import CommonHelper
10 |
11 | class MainWindow(QMainWindow):
12 | def __init__(self,parent=None):
13 | super(MainWindow,self).__init__(parent)
14 | self.resize(477, 258)
15 | self.setWindowTitle("加载QSS文件")
16 | btn1 = QPushButton( self)
17 | btn1.setText('添加')
18 | btn1.setToolTip('测试提示')
19 | vbox = QVBoxLayout()
20 | vbox.addWidget( btn1 )
21 |
22 | self.setLayout(vbox)
23 |
24 | if __name__ == "__main__":
25 | app = QApplication(sys.argv)
26 | win = MainWindow()
27 |
28 | styleFile = './style.qss'
29 | qssStyle = CommonHelper.readQss( styleFile )
30 | win.setStyleSheet( qssStyle )
31 | win.show()
32 | sys.exit(app.exec_())
33 |
--------------------------------------------------------------------------------
/Chapter08/qt08_paint01.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | """
4 | 【简介】
5 | 不规则窗体的实现
6 |
7 |
8 | """
9 |
10 | import sys
11 | from PyQt5.QtWidgets import QApplication ,QWidget
12 | from PyQt5.QtGui import QPixmap, QPainter , QBitmap
13 |
14 | class Winform(QWidget):
15 | def __init__(self,parent=None):
16 | super(Winform,self).__init__(parent)
17 | self.setWindowTitle("不规则窗体的实现例子")
18 | self.resize(600, 400)
19 |
20 | def paintEvent(self,event):
21 | painter = QPainter(self)
22 | painter.drawPixmap(0,0,280,390,QPixmap(r"./images/dog.jpg"))
23 | painter.drawPixmap(300,0,280,390,QBitmap(r"./images/dog.jpg"))
24 |
25 | if __name__ == "__main__":
26 | app = QApplication(sys.argv)
27 | form = Winform()
28 | form.show()
29 | sys.exit(app.exec_())
30 |
--------------------------------------------------------------------------------
/Chapter08/qt08_paint02.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | """
4 | 【简介】
5 | 不规则窗体的实现
6 |
7 |
8 | """
9 |
10 | import sys
11 | from PyQt5.QtWidgets import QApplication ,QWidget
12 | from PyQt5.QtGui import QPixmap, QPainter , QBitmap
13 |
14 | class Winform(QWidget):
15 | def __init__(self,parent=None):
16 | super(Winform,self).__init__(parent)
17 | self.setWindowTitle("不规则窗体的实现例子")
18 |
19 | self.pix = QBitmap("./images/mask.png")
20 | self.resize(self.pix.size())
21 | self.setMask(self.pix)
22 |
23 | def paintEvent(self,event):
24 | painter = QPainter(self)
25 | #在指定区域直接绘制窗口背景
26 | painter.drawPixmap(0,0,self.pix.width(),self.pix.height(),QPixmap("./images/screen1.jpg"))
27 | #绘制窗口背景,平铺到整个窗口,随着窗口改变而改变
28 | #painter.drawPixmap(0,0,self.width(),self.height(),QPixmap("./images/screen1.jpg"))
29 |
30 | if __name__ == "__main__":
31 | app = QApplication(sys.argv)
32 | form = Winform()
33 | form.show()
34 | sys.exit(app.exec_())
35 |
--------------------------------------------------------------------------------
/Chapter08/qt08_qssStyle01.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | '''
4 | 【简介】
5 | QSS样式
6 |
7 | '''
8 |
9 | from PyQt5.QtWidgets import *
10 | import sys
11 |
12 | class WindowDemo(QWidget):
13 | def __init__(self ):
14 | super().__init__()
15 |
16 | btn1 = QPushButton(self )
17 | btn1.setText('按钮1')
18 |
19 | btn2 = QPushButton(self )
20 | btn2.setText('按钮2')
21 |
22 | vbox=QVBoxLayout()
23 | vbox.addWidget(btn1)
24 | vbox.addWidget(btn2)
25 | self.setLayout(vbox)
26 | self.setWindowTitle("QSS样式")
27 |
28 | if __name__ == "__main__":
29 | app = QApplication(sys.argv)
30 | win = WindowDemo()
31 | qssStyle = '''
32 | QPushButton {
33 | background-color: red
34 | }
35 |
36 | '''
37 | win.setStyleSheet( qssStyle )
38 | win.show()
39 | sys.exit(app.exec_())
40 |
41 |
--------------------------------------------------------------------------------
/Chapter08/qt08_qssStyle02.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | '''
4 | 【简介】
5 | QSS样式
6 |
7 | '''
8 |
9 | from PyQt5.QtWidgets import *
10 | import sys
11 |
12 | class WindowDemo(QWidget):
13 | def __init__(self ):
14 | super().__init__()
15 |
16 | btn1 = QPushButton(self )
17 | btn1.setText('按钮1')
18 |
19 | btn2 = QPushButton(self )
20 | btn2.setProperty( 'name' , 'myBtn' )
21 | btn2.setText('按钮2')
22 |
23 | vbox=QVBoxLayout()
24 | vbox.addWidget(btn1)
25 | vbox.addWidget(btn2)
26 | self.setLayout(vbox)
27 | self.setWindowTitle("QSS样式")
28 |
29 | if __name__ == "__main__":
30 | app = QApplication(sys.argv)
31 | win = WindowDemo()
32 | qssStyle = '''
33 | QPushButton[name="myBtn"] {
34 | background-color: red
35 | }
36 |
37 | '''
38 | win.setStyleSheet( qssStyle )
39 | win.show()
40 | sys.exit(app.exec_())
41 |
42 |
--------------------------------------------------------------------------------
/Chapter08/qt08_qssStyle03.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | '''
4 | 【简介】
5 | QSS样式
6 |
7 | '''
8 |
9 | from PyQt5.QtWidgets import *
10 | import sys
11 |
12 | class WindowDemo(QWidget):
13 | def __init__(self):
14 | super(WindowDemo, self).__init__();
15 | self.InitUI();
16 |
17 | def InitUI(self):
18 | combo = QComboBox(self)
19 | combo.setObjectName('myQComboBox')
20 | combo.addItem('Window')
21 | combo.addItem('Ubuntu')
22 | combo.addItem('Red Hat')
23 | combo.move(50,50)
24 | self.setGeometry(250,200,320,150)
25 | self.setWindowTitle('QComboBox样式')
26 |
27 | if __name__ == "__main__":
28 | app = QApplication(sys.argv)
29 | win = WindowDemo()
30 | qssStyle = '''
31 | QComboBox#myQComboBox::drop-down {
32 | image: url( ./images/dropdown.png)
33 | }
34 |
35 | '''
36 | win.setStyleSheet( qssStyle )
37 | win.show()
38 | sys.exit(app.exec_())
39 |
40 |
--------------------------------------------------------------------------------
/Chapter08/qt08_winBkground01.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | '''
4 | 【简介】
5 | 界面背景图片设置
6 |
7 | '''
8 |
9 | import sys
10 | from PyQt5.QtWidgets import QMainWindow , QApplication
11 |
12 | app = QApplication(sys.argv)
13 | win = QMainWindow()
14 | win.setWindowTitle("界面背景图片设置")
15 | win.resize(350, 250)
16 | win.setObjectName("MainWindow")
17 | win.setStyleSheet("#MainWindow{border-image:url(./images/python.jpg);}")
18 | #win.setStyleSheet("#MainWindow{background-color: yellow}")
19 | win.show()
20 | sys.exit(app.exec_())
21 |
22 |
--------------------------------------------------------------------------------
/Chapter08/qt08_winBkground02.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | '''
4 | 【简介】
5 | 界面背景图片设置
6 |
7 | '''
8 |
9 | import sys
10 | from PyQt5.QtWidgets import QMainWindow , QApplication
11 | from PyQt5.QtGui import QPalette , QBrush , QPixmap
12 |
13 |
14 | app = QApplication(sys.argv)
15 | win = QMainWindow()
16 | win.setWindowTitle("界面背景图片设置")
17 | palette = QPalette()
18 | palette.setBrush(QPalette.Background,QBrush(QPixmap("./images/python.jpg")))
19 | win.setPalette(palette)
20 | #当背景图片的宽度和高度大于窗口的宽度和高度时
21 | #win.resize(460, 255 )
22 |
23 | #当背景图片的宽度和高度小于窗口的宽度和高度时
24 | win.resize(800, 600 )
25 | win.show()
26 | sys.exit(app.exec_())
27 |
--------------------------------------------------------------------------------
/Chapter08/qt08_winBkground03.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | '''
4 | 【简介】
5 | 界面背景颜色设置
6 |
7 | '''
8 |
9 | from PyQt5.QtWidgets import QApplication, QLabel ,QWidget, QVBoxLayout , QPushButton, QMainWindow
10 | from PyQt5.QtGui import QPalette , QBrush , QPixmap
11 | from PyQt5.QtCore import Qt
12 | import sys
13 |
14 | app = QApplication(sys.argv)
15 | win = QMainWindow()
16 | win.setWindowTitle("界面背景颜色设置")
17 | win.resize(350, 250)
18 | palette = QPalette()
19 | palette.setColor(QPalette.Background , Qt.red )
20 | win.setPalette(palette)
21 | win.show()
22 | sys.exit(app.exec_())
23 |
24 |
--------------------------------------------------------------------------------
/Chapter08/qt08_winBkground04.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | """
4 | 【简介】
5 | 使用paintEvent设置窗口背景颜色
6 |
7 |
8 | """
9 |
10 | import sys
11 | from PyQt5.QtWidgets import QApplication ,QWidget
12 | from PyQt5.QtGui import QPainter
13 | from PyQt5.QtCore import Qt
14 |
15 | class Winform(QWidget):
16 | def __init__(self,parent=None):
17 | super(Winform,self).__init__(parent)
18 | self.setWindowTitle("paintEvent设置背景颜色")
19 |
20 | def paintEvent(self,event):
21 | painter = QPainter(self)
22 | painter.setBrush(Qt.yellow );
23 | # 设置背景颜色
24 | painter.drawRect( self.rect());
25 |
26 | if __name__ == "__main__":
27 | app = QApplication(sys.argv)
28 | form = Winform()
29 | form.show()
30 | sys.exit(app.exec_())
31 |
--------------------------------------------------------------------------------
/Chapter08/qt08_winBkground05.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | """
4 | 【简介】
5 | 使用paintEvent设置窗口背景图片
6 |
7 |
8 | """
9 |
10 | import sys
11 | from PyQt5.QtWidgets import QApplication ,QWidget
12 | from PyQt5.QtGui import QPixmap, QPainter
13 |
14 | class Winform(QWidget):
15 | def __init__(self,parent=None):
16 | super(Winform,self).__init__(parent)
17 | self.setWindowTitle("paintEvent设置背景图片")
18 |
19 | def paintEvent(self,event):
20 | painter = QPainter(self)
21 | pixmap = QPixmap("./images/screen1.jpg")
22 | #绘制窗口背景,平铺到整个窗口,随着窗口改变而改变
23 | painter.drawPixmap(self.rect(),pixmap)
24 |
25 | if __name__ == "__main__":
26 | app = QApplication(sys.argv)
27 | form = Winform()
28 | form.show()
29 | sys.exit(app.exec_())
30 |
--------------------------------------------------------------------------------
/Chapter08/qt08_winStyle01.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | 【简介】
4 | 设置窗口样式
5 |
6 | """
7 | from PyQt5.QtCore import Qt
8 | import sys
9 | from PyQt5.QtWidgets import QMainWindow , QApplication
10 |
11 | class MainWindow(QMainWindow):
12 | def __init__(self,parent=None):
13 | super(MainWindow,self).__init__(parent)
14 | self.resize(477, 258)
15 | self.setWindowTitle("设置窗口样式例子")
16 | #设置窗口样式为窗口无边框化
17 | self.setWindowFlags( Qt.SubWindow )
18 | self.setObjectName("MainWindow")
19 | self.setStyleSheet("#MainWindow{border-image:url(images/python.jpg);}")
20 |
21 | if __name__ == "__main__":
22 | app = QApplication(sys.argv)
23 | win = MainWindow()
24 | win.show()
25 | sys.exit(app.exec_())
26 |
--------------------------------------------------------------------------------
/Chapter08/qt08_winStyle02.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | # 导入模块
4 | import sys
5 | from PyQt5.QtWidgets import QMainWindow , QApplication
6 | from PyQt5.QtCore import Qt
7 |
8 | ### 自定义窗口类
9 | class MyWindow( QMainWindow):
10 | '''自定义窗口类'''
11 | ### 构造函数
12 | def __init__(self,parent=None):
13 | '''构造函数'''
14 | # 调用父类构造函数
15 | super(MyWindow,self).__init__(parent)
16 |
17 | # 设置窗口标记(无边框 )
18 | self.setWindowFlags( Qt.FramelessWindowHint)
19 |
20 | # 便于显示,设置窗口背景颜色(采用QSS)
21 | self.setStyleSheet('''background-color:blue; ''')
22 | ###覆盖函数
23 | def showMaximized(self):
24 | '''最大化'''
25 | # 得到桌面控件
26 | desktop = QApplication.desktop()
27 | # 得到屏幕可显示尺寸
28 | rect = desktop.availableGeometry()
29 | # 设置窗口尺寸
30 | self.setGeometry(rect)
31 | # 设置窗口显示
32 | self.show()
33 |
34 | ### 主函数
35 | if __name__ == "__main__":
36 | '''主函数'''
37 | # 声明变量
38 | app = QApplication(sys.argv)
39 | # 创建窗口
40 | window = MyWindow()
41 | # 调用最大化显示
42 | window.showMaximized()
43 | # 应用程序事件循环
44 | sys.exit(app.exec_())
45 |
--------------------------------------------------------------------------------
/Chapter08/style.qss:
--------------------------------------------------------------------------------
1 | QMainWindow{
2 | border-image:url(./images/python.jpg);
3 |
4 | }
5 |
6 | QToolTip{
7 | border: 1px solid rgb(45, 45, 45);
8 | background: white;
9 | color: red;
10 | }
11 |
--------------------------------------------------------------------------------
/Chapter09/Call_Plotly_PyQt5.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | import sys
4 | from PyQt5.QtCore import *
5 | from PyQt5.QtGui import *
6 | from PyQt5.QtWidgets import *
7 | from PyQt5.QtWebEngineWidgets import *
8 | from Plotly_PyQt5 import Plotly_PyQt5
9 |
10 |
11 | class MainWindow(QMainWindow ):
12 |
13 | def __init__(self ):
14 | super(QMainWindow, self).__init__()
15 | self.plotly_pyqt5 = Plotly_PyQt5()
16 | self.qwebengine = QWebEngineView()
17 | self.qwebengine.setGeometry(QRect(50, 20, 1200, 600))
18 | print( self.plotly_pyqt5.get_plotly_path_if_hs300_bais() )
19 | self.qwebengine.load(QUrl.fromLocalFile(self.plotly_pyqt5.get_plotly_path_if_hs300_bais()))
20 |
21 | if __name__ == '__main__':
22 | app = QApplication(sys.argv)
23 | win = MainWindow()
24 | win.showMaximized()
25 | app.exec_()
26 |
--------------------------------------------------------------------------------
/Chapter09/__pycache__/MatplotlibWidget.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter09/__pycache__/MatplotlibWidget.cpython-36.pyc
--------------------------------------------------------------------------------
/Chapter09/__pycache__/Plotly_PyQt5.cpython-35.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter09/__pycache__/Plotly_PyQt5.cpython-35.pyc
--------------------------------------------------------------------------------
/Chapter09/__pycache__/Plotly_PyQt5.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter09/__pycache__/Plotly_PyQt5.cpython-36.pyc
--------------------------------------------------------------------------------
/Chapter09/__pycache__/Ui_matplotlib_pyqt.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter09/__pycache__/Ui_matplotlib_pyqt.cpython-36.pyc
--------------------------------------------------------------------------------
/Chapter09/__pycache__/Ui_pandas_pyqt.cpython-35.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter09/__pycache__/Ui_pandas_pyqt.cpython-35.pyc
--------------------------------------------------------------------------------
/Chapter09/__pycache__/Ui_plotly_matplotlib_pyqt.cpython-35.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter09/__pycache__/Ui_plotly_matplotlib_pyqt.cpython-35.pyc
--------------------------------------------------------------------------------
/Chapter09/__pycache__/Ui_plotly_pyqt.cpython-35.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter09/__pycache__/Ui_plotly_pyqt.cpython-35.pyc
--------------------------------------------------------------------------------
/Chapter09/data/fund_data.xlsx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter09/data/fund_data.xlsx
--------------------------------------------------------------------------------
/Chapter09/data/fund_data_new.xlsx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter09/data/fund_data_new.xlsx
--------------------------------------------------------------------------------
/Chapter09/db/database.db:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter09/db/database.db
--------------------------------------------------------------------------------
/Chapter09/demo_plotly_pyqt.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | """
4 | Module implementing MainWindow.
5 | """
6 |
7 | from PyQt5.QtCore import *
8 | from PyQt5.QtGui import *
9 | from PyQt5.QtWidgets import *
10 | import sys
11 | from PyQt5.QtWebEngineWidgets import QWebEngineView
12 |
13 |
14 | class Window(QWidget):
15 | def __init__(self):
16 | QWidget.__init__(self)
17 | self.qwebengine = QWebEngineView(self)
18 | self.qwebengine.setGeometry(QRect(50, 20, 1200, 600))
19 | self.qwebengine.load(QUrl.fromLocalFile('\plotly_html\if_hs300_bais.html'))
20 |
21 |
22 | app = QApplication(sys.argv)
23 | screen = Window()
24 | screen.showMaximized()
25 | sys.exit(app.exec_())
26 |
--------------------------------------------------------------------------------
/Chapter09/example/colorDialog.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | from PyQt5.QtWidgets import QApplication, QPushButton, QColorDialog , QWidget
4 | from PyQt5.QtCore import Qt
5 | from PyQt5.QtGui import QColor
6 | import sys
7 |
8 | class ColorDialog ( QWidget):
9 | def __init__(self ):
10 | super().__init__()
11 | color = QColor(0, 0, 0)
12 | self.setGeometry(300, 300, 350, 280)
13 | self.setWindowTitle('颜色选择')
14 | self.button = QPushButton('Dialog', self)
15 | self.button.setFocusPolicy(Qt.NoFocus)
16 | self.button.move(20, 20)
17 | self.button.clicked.connect(self.showDialog)
18 | self.setFocus()
19 | self.widget = QWidget(self)
20 | self.widget.setStyleSheet('QWidget{background-color:%s} '%color.name())
21 | self.widget.setGeometry(130, 22, 100, 100)
22 |
23 | def showDialog(self):
24 | col = QColorDialog.getColor()
25 | if col.isValid():
26 | self.widget.setStyleSheet('QWidget {background-color:%s}'%col.name())
27 |
28 | if __name__ == "__main__":
29 | app = QApplication(sys.argv)
30 | qb = ColorDialog()
31 | qb.show()
32 | sys.exit(app.exec_())
33 |
--------------------------------------------------------------------------------
/Chapter09/if_index_bais.xlsx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter09/if_index_bais.xlsx
--------------------------------------------------------------------------------
/Chapter09/plotly_matplotlib_pyqt.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | """
4 | Module implementing MainWindow.
5 | """
6 |
7 | from PyQt5.QtCore import pyqtSlot
8 | from PyQt5.QtWidgets import QMainWindow
9 |
10 | from Ui_plotly_matplotlib_pyqt import Ui_MainWindow
11 |
12 | from PyQt5.QtCore import *
13 | from PyQt5.QtGui import *
14 | from PyQt5.QtWidgets import *
15 | import sys
16 | from Plotly_PyQt5 import Plotly_PyQt5
17 |
18 |
19 | class MainWindow(QMainWindow, Ui_MainWindow):
20 | """
21 | Class documentation goes here.
22 | """
23 |
24 | def __init__(self, parent=None):
25 | """
26 | Constructor
27 |
28 | @param parent reference to the parent widget
29 | @type QWidget
30 | """
31 | super(MainWindow, self).__init__(parent)
32 | self.setupUi(self)
33 | self.plotly_pyqt5 = Plotly_PyQt5()
34 | self.webView.setGeometry(QRect(50, 20, 1200, 600))
35 | self.webView.load(QUrl.fromLocalFile(self.plotly_pyqt5.get_plot_path_matplotlib_plotly()))
36 |
37 |
38 | app = QApplication(sys.argv)
39 | win = MainWindow()
40 | win.showMaximized()
41 | app.exec_()
42 |
--------------------------------------------------------------------------------
/Chapter09/plotly_pyqt.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | """
4 | Module implementing MainWindow.
5 | """
6 |
7 | from PyQt5.QtCore import pyqtSlot
8 | from PyQt5.QtWidgets import QMainWindow
9 |
10 | from Ui_plotly_pyqt import Ui_MainWindow
11 |
12 | from PyQt5.QtCore import *
13 | from PyQt5.QtGui import *
14 | from PyQt5.QtWidgets import *
15 | import sys
16 | from Plotly_PyQt5 import Plotly_PyQt5
17 |
18 |
19 | class MainWindow(QMainWindow, Ui_MainWindow):
20 | """
21 | Class documentation goes here.
22 | """
23 |
24 | def __init__(self, parent=None):
25 | """
26 | Constructor
27 |
28 | @param parent reference to the parent widget
29 | @type QWidget
30 | """
31 | super(MainWindow, self).__init__(parent)
32 | self.setupUi(self)
33 | self.plotly_pyqt5 = Plotly_PyQt5()
34 | self.qwebengine.setGeometry(QRect(50, 20, 1200, 600))
35 | self.qwebengine.load(QUrl.fromLocalFile(self.plotly_pyqt5.get_plotly_path_if_hs300_bais()))
36 |
37 |
38 | app = QApplication(sys.argv)
39 | win = MainWindow()
40 | win.showMaximized()
41 | app.exec_()
42 |
--------------------------------------------------------------------------------
/Chapter09/qt09_db01.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | '''
4 | 【简介】
5 | PyQt5中 处理database 例子
6 |
7 |
8 | '''
9 |
10 | import sys
11 | from PyQt5.QtCore import *
12 | from PyQt5.QtGui import *
13 | from PyQt5.QtWidgets import *
14 | from PyQt5.QtSql import QSqlDatabase , QSqlQuery
15 |
16 | def createDB():
17 | db = QSqlDatabase.addDatabase('QSQLITE')
18 | db.setDatabaseName('./db/database.db')
19 |
20 | if not db.open():
21 | QMessageBox.critical(None, ("无法打开数据库"),
22 | ( "无法建立到数据库的连接,这个例子需要SQLite 支持,请检查数据库配置。\n\n"
23 | "点击取消按钮退出应用。"),
24 | QMessageBox.Cancel )
25 | return False
26 |
27 | query = QSqlQuery()
28 | query.exec_("create table people(id int primary key, name varchar(20), address varchar(30))")
29 | query.exec_("insert into people values(1, 'zhangsan1', 'BeiJing')")
30 | query.exec_("insert into people values(2, 'lisi1', 'TianJing')")
31 | query.exec_("insert into people values(3, 'wangwu1', 'HenNan')")
32 | query.exec_("insert into people values(4, 'lisi2', 'HeBei')")
33 | query.exec_("insert into people values(5, 'wangwu2', 'shanghai')")
34 | db.close()
35 | return True
36 |
37 | if __name__ == '__main__':
38 | app = QApplication(sys.argv)
39 | createDB()
40 | sys.exit(app.exec_())
41 |
42 |
--------------------------------------------------------------------------------
/Chapter09/qt09_db02.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | '''
4 | 【简介】
5 | PyQt5中 处理database 例子
6 |
7 |
8 | '''
9 |
10 | import sys
11 | from PyQt5.QtCore import *
12 | from PyQt5.QtGui import *
13 | from PyQt5.QtWidgets import *
14 | from PyQt5.QtSql import QSqlDatabase
15 |
16 | class ExecDatabaseDemo(QWidget):
17 |
18 | def __init__(self, parent=None):
19 | super(ExecDatabaseDemo , self).__init__(parent)
20 |
21 | self.db = QSqlDatabase.addDatabase('QSQLITE')
22 | self.db.setDatabaseName('./db/database.db')
23 | # 打开数据库
24 | self.db.open()
25 |
26 |
27 | def closeEvent(self, event):
28 | # 关闭数据库
29 | self.db.close()
30 |
31 | if __name__ == '__main__':
32 | app = QApplication(sys.argv)
33 | demo = ExecDatabaseDemo()
34 | demo.show()
35 | sys.exit(app.exec_())
36 |
37 |
--------------------------------------------------------------------------------
/Chapter10/example1/__pycache__/WeatherWin.cpython-35.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter10/example1/__pycache__/WeatherWin.cpython-35.pyc
--------------------------------------------------------------------------------
/Chapter10/example1/__pycache__/WeatherWin.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter10/example1/__pycache__/WeatherWin.cpython-36.pyc
--------------------------------------------------------------------------------
/Chapter10/example1/getWeatherInfo.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | '''
3 | 【简介】
4 | 查询城市天气数据
5 |
6 | '''
7 |
8 | import requests
9 |
10 | rep = requests.get('http://www.weather.com.cn/data/sk/101010100.html')
11 | rep.encoding = 'utf-8'
12 |
13 | print('返回结果: %s' % rep.json() )
14 | print('城市: %s' % rep.json()['weatherinfo']['city'] )
15 | print('风向: %s' % rep.json()['weatherinfo']['WD'] )
16 | print('温度: %s' % rep.json()['weatherinfo']['temp'] + " 度")
17 | print('风力: %s' % rep.json()['weatherinfo']['WS'] )
18 | print('湿度: %s' % rep.json()['weatherinfo']['SD'] )
19 |
20 |
21 |
--------------------------------------------------------------------------------
/Chapter10/example3/CallOpenWeb.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | import time
4 | import os
5 |
6 | if __name__ == '__main__' :
7 | for i in range(5):
8 | os.system("python openweb.py")
9 | print("正在刷新页面. 次数 =>" , i)
10 | time.sleep(10)
11 |
12 |
13 |
--------------------------------------------------------------------------------
/Chapter10/example3/openweb.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | import sys
4 | import time
5 |
6 | from PyQt5.QtWebEngineWidgets import QWebEngineView
7 | from PyQt5.QtCore import *
8 | from PyQt5.QtWidgets import *
9 |
10 | class WebView(QWebEngineView):
11 | def __init__(self ):
12 | super(WebView, self).__init__()
13 | url = 'http://www.cnblogs.com/wangshuo1/p/6707631.html'
14 | self.load( QUrl( url ) )
15 | self.show()
16 | QTimer.singleShot(1000*5 , self.close)
17 |
18 |
19 | if __name__ == '__main__':
20 | app = QApplication(sys.argv)
21 | web = WebView()
22 | print('### exec succeed !')
23 | sys.exit(app.exec_())
24 |
--------------------------------------------------------------------------------
/Chapter11/__pycache__/Plotly_PyQt5.cpython-35.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter11/__pycache__/Plotly_PyQt5.cpython-35.pyc
--------------------------------------------------------------------------------
/Chapter11/__pycache__/Ui_combination.cpython-35.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter11/__pycache__/Ui_combination.cpython-35.pyc
--------------------------------------------------------------------------------
/Chapter11/__pycache__/Ui_fundFOF.cpython-35.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter11/__pycache__/Ui_fundFOF.cpython-35.pyc
--------------------------------------------------------------------------------
/Chapter11/__pycache__/Ui_test_table2.cpython-35.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter11/__pycache__/Ui_test_table2.cpython-35.pyc
--------------------------------------------------------------------------------
/Chapter11/__pycache__/mypyqtgraph.cpython-35.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter11/__pycache__/mypyqtgraph.cpython-35.pyc
--------------------------------------------------------------------------------
/Chapter11/__pycache__/opt_fund.cpython-35.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter11/__pycache__/opt_fund.cpython-35.pyc
--------------------------------------------------------------------------------
/Chapter11/__pycache__/ui_test_table.cpython-35.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter11/__pycache__/ui_test_table.cpython-35.pyc
--------------------------------------------------------------------------------
/Chapter11/__pycache__/ui_test_table.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter11/__pycache__/ui_test_table.cpython-36.pyc
--------------------------------------------------------------------------------
/Chapter11/data/fund_data.xlsx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter11/data/fund_data.xlsx
--------------------------------------------------------------------------------
/Chapter11/data/fund_data_new.xlsx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter11/data/fund_data_new.xlsx
--------------------------------------------------------------------------------
/Chapter11/data/和聚光明1号_hs300_merge.xlsx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter11/data/和聚光明1号_hs300_merge.xlsx
--------------------------------------------------------------------------------
/Chapter11/data/时时安稳健1号.csv:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter11/data/时时安稳健1号.csv
--------------------------------------------------------------------------------
/Chapter11/data/昆仑信托-昆仑三十六号.csv:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter11/data/昆仑信托-昆仑三十六号.csv
--------------------------------------------------------------------------------
/Chapter11/data/组合.xlsx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter11/data/组合.xlsx
--------------------------------------------------------------------------------
/Chapter11/data/长城国瑞证券恒通23号.csv:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter11/data/长城国瑞证券恒通23号.csv
--------------------------------------------------------------------------------
/Chapter11/juchao/__pycache__/Ui_run.cpython-35.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter11/juchao/__pycache__/Ui_run.cpython-35.pyc
--------------------------------------------------------------------------------
/Chapter11/juchao/__pycache__/craw.cpython-35.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter11/juchao/__pycache__/craw.cpython-35.pyc
--------------------------------------------------------------------------------
/Chapter11/juchao/下载/2017-08-25_吉电股份:国家电投集团财务有限公司风险评估说明.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter11/juchao/下载/2017-08-25_吉电股份:国家电投集团财务有限公司风险评估说明.pdf
--------------------------------------------------------------------------------
/Chapter11/juchao/下载/2017-08-25_粤 水 电:2017年第四次临时股东大会法律意见书.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter11/juchao/下载/2017-08-25_粤 水 电:2017年第四次临时股东大会法律意见书.pdf
--------------------------------------------------------------------------------
/Chapter11/juchao/下载/2017-08-26_百大集团:1-6月审计报告.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter11/juchao/下载/2017-08-26_百大集团:1-6月审计报告.pdf
--------------------------------------------------------------------------------
/Chapter11/juchao/下载/[临时公告]欧林生物:北京德恒(成都)律师事务所关于成都欧林生物科技股份有限公司2016年年度股东大会法律意见书.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter11/juchao/下载/[临时公告]欧林生物:北京德恒(成都)律师事务所关于成都欧林生物科技股份有限公司2016年年度股东大会法律意见书.pdf
--------------------------------------------------------------------------------
/Chapter11/juchao/下载/中储股份:关于为成都中储发展物流有限责任公司提供担保的公告.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter11/juchao/下载/中储股份:关于为成都中储发展物流有限责任公司提供担保的公告.pdf
--------------------------------------------------------------------------------
/Chapter11/juchao/下载/吉电股份:国家电投集团财务有限公司风险评估说明.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter11/juchao/下载/吉电股份:国家电投集团财务有限公司风险评估说明.pdf
--------------------------------------------------------------------------------
/Chapter11/juchao/下载/百大集团:1-6月审计报告.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter11/juchao/下载/百大集团:1-6月审计报告.pdf
--------------------------------------------------------------------------------
/Chapter11/juchao/下载/粤 水 电:2017年第四次临时股东大会法律意见书.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter11/juchao/下载/粤 水 电:2017年第四次临时股东大会法律意见书.pdf
--------------------------------------------------------------------------------
/Chapter11/juchao/下载/鹏起科技:关于控股子公司成都宝通天宇51%股权质押贷款融资的公告.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter11/juchao/下载/鹏起科技:关于控股子公司成都宝通天宇51%股权质押贷款融资的公告.pdf
--------------------------------------------------------------------------------
/Chapter11/zwquant_pyqt/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/Chapter11/zwquant_pyqt/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Chapter11/zwquant_pyqt/.idea/zquant_she35.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/Chapter11/zwquant_pyqt/__pycache__/MatplotlibWidget.cpython-35.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter11/zwquant_pyqt/__pycache__/MatplotlibWidget.cpython-35.pyc
--------------------------------------------------------------------------------
/Chapter11/zwquant_pyqt/__pycache__/MatplotlibWidget.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter11/zwquant_pyqt/__pycache__/MatplotlibWidget.cpython-36.pyc
--------------------------------------------------------------------------------
/Chapter11/zwquant_pyqt/__pycache__/Ui_my_back_test_show.cpython-35.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter11/zwquant_pyqt/__pycache__/Ui_my_back_test_show.cpython-35.pyc
--------------------------------------------------------------------------------
/Chapter11/zwquant_pyqt/__pycache__/Ui_my_back_test_show.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter11/zwquant_pyqt/__pycache__/Ui_my_back_test_show.cpython-36.pyc
--------------------------------------------------------------------------------
/Chapter11/zwquant_pyqt/__pycache__/my_back_test_show.cpython-35.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter11/zwquant_pyqt/__pycache__/my_back_test_show.cpython-35.pyc
--------------------------------------------------------------------------------
/Chapter11/zwquant_pyqt/__pycache__/zwBacktest.cpython-35.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter11/zwquant_pyqt/__pycache__/zwBacktest.cpython-35.pyc
--------------------------------------------------------------------------------
/Chapter11/zwquant_pyqt/__pycache__/zwQTBox.cpython-35.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter11/zwquant_pyqt/__pycache__/zwQTBox.cpython-35.pyc
--------------------------------------------------------------------------------
/Chapter11/zwquant_pyqt/__pycache__/zwQTDraw.cpython-35.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter11/zwquant_pyqt/__pycache__/zwQTDraw.cpython-35.pyc
--------------------------------------------------------------------------------
/Chapter11/zwquant_pyqt/__pycache__/zwStrategy.cpython-35.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter11/zwquant_pyqt/__pycache__/zwStrategy.cpython-35.pyc
--------------------------------------------------------------------------------
/Chapter11/zwquant_pyqt/__pycache__/zwSys.cpython-35.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter11/zwquant_pyqt/__pycache__/zwSys.cpython-35.pyc
--------------------------------------------------------------------------------
/Chapter11/zwquant_pyqt/__pycache__/zwTools.cpython-35.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter11/zwquant_pyqt/__pycache__/zwTools.cpython-35.pyc
--------------------------------------------------------------------------------
/Chapter11/zwquant_pyqt/__pycache__/zw_talib.cpython-35.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter11/zwquant_pyqt/__pycache__/zw_talib.cpython-35.pyc
--------------------------------------------------------------------------------
/Chapter11/zwquant_pyqt/my_list.pkl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/Chapter11/zwquant_pyqt/my_list.pkl
--------------------------------------------------------------------------------
/Chapter11/zwquant_pyqt/tmp/macd20_xtrdLib.csv:
--------------------------------------------------------------------------------
1 | date,ID,mode,code,dprice,num,kprice,sum,cash
2 | 2015-03-10,macd20_000001,buy,600401,2.89,3114,2.89,8999.460000000001,1000.539999999999
3 | 2015-04-24,macd20_000002,sell,600401,3.78,-3114,3.78,-11770.92,12771.46
4 | 2015-05-18,macd20_000003,buy,600401,4.3,2673,4.3,11493.9,1277.5599999999995
5 | 2015-06-04,macd20_000004,sell,600401,4.66,-2673,4.66,-12456.18,13733.74
6 | 2015-06-10,macd20_000005,buy,600401,5.5,2247,5.5,12358.5,1375.2399999999998
7 | 2015-06-18,macd20_000006,sell,600401,5.12,-2247,5.12,-11504.64,12879.88
8 | 2015-07-23,macd20_000007,buy,600401,3.2,3622,3.2,11590.400000000001,1289.4799999999977
9 | 2015-08-26,macd20_000008,sell,600401,2.56,-3622,2.56,-9272.32,10561.799999999997
10 | 2015-10-13,macd20_000009,buy,600401,2.42,3927,2.42,9503.34,1058.4599999999973
11 | 2015-11-26,macd20_000010,sell,600401,3.05,-3927,3.05,-11977.349999999999,13035.809999999996
12 | 2016-02-16,macd20_000011,buy,600401,2.45,4788,2.45,11730.6,1305.2099999999955
13 | 2016-02-29,macd20_000012,sell,600401,2.16,-4788,2.16,-10342.08,11647.289999999995
14 | 2016-03-11,macd20_000013,buy,600401,2.18,4808,2.18,10481.44,1165.849999999995
15 |
--------------------------------------------------------------------------------
/appendix/i18n01.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | """
4 | 【简介】
5 | 国际化例子
6 |
7 |
8 | """
9 |
10 | import sys
11 | from PyQt5.QtWidgets import QApplication ,QWidget ,QVBoxLayout , QPushButton
12 |
13 | class Winform(QWidget):
14 | def __init__(self,parent=None):
15 | super(Winform,self).__init__(parent)
16 | self.setWindowTitle(self.tr('title'))
17 | self.resize(330, 130)
18 | vlayout = QVBoxLayout()
19 | vlayout.addWidget( QPushButton( self.tr('upload')) )
20 | vlayout.addWidget( QPushButton( self.tr('download')) )
21 | self.setLayout(vlayout)
22 |
23 | if __name__ == "__main__":
24 | app = QApplication(sys.argv)
25 | form = Winform()
26 | form.show()
27 | sys.exit(app.exec_())
28 |
29 |
--------------------------------------------------------------------------------
/appendix/i18n02.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | """
4 | 【简介】
5 | 国际化例子
6 |
7 |
8 | """
9 |
10 | import sys
11 | from PyQt5.QtWidgets import QApplication ,QWidget ,QVBoxLayout , QPushButton
12 | from PyQt5.QtCore import QTranslator
13 |
14 | class Winform(QWidget):
15 | def __init__(self,parent=None):
16 | super(Winform,self).__init__(parent)
17 | self.setWindowTitle(self.tr('title'))
18 | self.resize(330, 130)
19 | vlayout = QVBoxLayout()
20 | vlayout.addWidget( QPushButton( self.tr('upload') ) )
21 | vlayout.addWidget( QPushButton( self.tr('download')) )
22 | self.setLayout(vlayout)
23 |
24 | if __name__ == "__main__":
25 | app = QApplication(sys.argv)
26 | trans = QTranslator()
27 | # 没有后缀.qm
28 | trans.load("zh_CN")
29 | app.installTranslator(trans)
30 | form = Winform()
31 | form.show()
32 | sys.exit(app.exec_())
33 |
34 |
--------------------------------------------------------------------------------
/appendix/qtSample.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | import sys
4 | from PyQt5.QtWidgets import QApplication,QWidget
5 |
6 | app = QApplication( )
7 | w = QWidget()
8 | w.resize(350,300)
9 | w.setWindowTitle('PyQt5 从入门到实战')
10 | w.show()
11 |
12 | sys.exit(app.exec_())
13 |
--------------------------------------------------------------------------------
/appendix/zh_CN.qm:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/appendix/zh_CN.qm
--------------------------------------------------------------------------------
/appendix/zh_CN.ts:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Winform
5 |
6 |
7 | title
8 | 上传
9 |
10 |
11 |
12 | upload
13 | 下载
14 |
15 |
16 |
17 | download
18 | 国际化例子
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/appendix/附录A PyQt 5整体结构.doc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/appendix/附录A PyQt 5整体结构.doc
--------------------------------------------------------------------------------
/appendix/附录B Python开发技巧与实践.doc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/appendix/附录B Python开发技巧与实践.doc
--------------------------------------------------------------------------------
/appendix/附录C Python在线学习资料.doc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/appendix/附录C Python在线学习资料.doc
--------------------------------------------------------------------------------
/tool/PyQt5-api.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/tool/PyQt5-api.zip
--------------------------------------------------------------------------------
/tool/glut64.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/tool/glut64.zip
--------------------------------------------------------------------------------
/tool/sqlite-tools-win32-x86-3140200.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/tool/sqlite-tools-win32-x86-3140200.zip
--------------------------------------------------------------------------------
/《PyQt5快速开发与实战》目录.doc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cxinping/PyQt5/03fe2e3f1a85a254a6cec675ae79234687ea734c/《PyQt5快速开发与实战》目录.doc
--------------------------------------------------------------------------------