问题1:python安装pyqt5-tools时找不到designer.exe
下图第2步找不到designer.exe
原因:design 需要单独安装。 直接用pip3 install PyQt5-tools会找不到安装文件。
解决方法:
1.手动到下面的地址下载whl。
https://github.com/altendky/pyqt5-tools/releases/tag/v5.7.dev1
2.手动安装。
pip3 install PyQt5_Tools-5.7.dev1-py3-none-any.whl
二、pyqt5中将一个view类中鼠标点击信号的结果传递到类外,供其他类使用
参考博客:pyqt5-多线程QThread类 - 天子骄龙 - 博客园
import sys
from PyQt5.QtCore import Qt, QThread,pyqtSignal
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QLabel, QVBoxLayout,QHBoxLayout
# 主类
class Demo(QWidget):
def __init__(self):
super(Demo, self).__init__()
self.button = QPushButton('开始', self)
self.button.clicked.connect(self.count_func)
self.button_2 = QPushButton('停止', self)
self.button_2.clicked.connect(self.stop_count_func)
self.label = QLabel('0', self)
self.label.setAlignment(Qt.AlignCenter)
self.my_thread = MyThread() #实例化副类对象
self.my_thread.my_signal.connect(self.set_label_func)
#线程自定义信号连接的槽函数
self.h_layout = QHBoxLayout()
self.v_layout = QVBoxLayout()
self.h_layout.addWidget(self.button)
self.h_layout.addWidget(self.button_2)
self.v_layout.addWidget(self.label)
self.v_layout.addLayout(self.h_layout)
self.setLayout(self.v_layout)
def stop_count_func(self):
self.my_thread.is_on = False
self.my_thread.count = 0
def count_func(self):
self.my_thread.is_on = True
self.my_thread.start()#启动线程
def set_label_func(self, num):
self.label.setText(num)
#由于自定义信号时自动传递一个字符串参数,所以在这个槽函数中要接受一个参数
class MyThread(QThread):# 副类
my_signal = pyqtSignal(str) #自定义信号对象。参数str就代表这个信号可以传一个字符串
def __init__(self):
super(MyThread, self).__init__()
self.count = 0
self.is_on = True
def run(self): #线程执行函数
while self.is_on :
print(self.count)
self.count += 1
self.my_signal.emit(str(self.count)) # 将这个信号结果以str形式传递出去传给槽函数
self.sleep(1)
if __name__ == '__main__':
app = QApplication(sys.argv)
demo = Demo()
demo.show()
sys.exit(app.exec_())