赞
踩
1、继承 QWidget
2、事件捕获
- from PyQt5.QtCore import Qt
- from PyQt5.QtWidgets import QWidget
-
- from py_ui.demo import Ui_demo
-
-
- class handler_demo(QWidget, Ui_demo):
- def __init__(self):
- super().__init__()
- self.setupUi(self)
-
- def mousePressEvent(self, e):
- if e.button() == Qt.RightButton:
- self.input1.setText("RightButton press")
- elif e.button() == Qt.LeftButton:
- self.input1.setText("LeftButton press")
- elif e.button() == Qt.BackButton:
- self.input1.setText("BackButton press")
- elif e.button() == Qt.ForwardButton:
- self.input1.setText("ForwardButton press")
- elif e.button() == Qt.MiddleButton:
- self.input1.setText("MiddleButton press")
- elif e.button() == Qt.MidButton:
- self.input1.setText("MidButton press")
-
- def mouseReleaseEvent(self, e):
- if e.button() == Qt.RightButton:
- self.input2.setText("RightButton release")
- elif e.button() == Qt.LeftButton:
- self.input2.setText("LeftButton release")
- elif e.button() == Qt.BackButton:
- self.input2.setText("BackButton release")
- elif e.button() == Qt.ForwardButton:
- self.input2.setText("ForwardButton release")
- elif e.button() == Qt.MiddleButton:
- self.input2.setText("MiddleButton release")
- elif e.button() == Qt.MidButton:
- self.input2.setText("MidButton release")
-
- return
-
- def mouseDoubleClickEvent(self, e):
- if e.button() == Qt.RightButton:
- self.input3.setText("RightButton double")
- elif e.button() == Qt.LeftButton:
- self.input3.setText("LeftButton double")
- elif e.button() == Qt.BackButton:
- self.input3.setText("BackButton double")
- elif e.button() == Qt.ForwardButton:
- self.input3.setText("ForwardButton double")
- elif e.button() == Qt.MiddleButton:
- self.input3.setText("MiddleButton double")
- elif e.button() == Qt.MidButton:
- self.input3.setText("MidButton double")
-
- return
-
- def mouseMoveEvent(self, e):
- if e.button() == Qt.RightButton:
- self.input4.setText("RightButton move")
- elif e.button() == Qt.LeftButton:
- self.input4.setText("LeftButton move")
- elif e.button() == Qt.BackButton:
- self.input4.setText("BackButton move")
- elif e.button() == Qt.ForwardButton:
- self.input4.setText("ForwardButton move")
- elif e.button() == Qt.MiddleButton:
- self.input4.setText("MiddleButton move")
- elif e.button() == Qt.MidButton:
- self.input4.setText("MidButton move")
-
- return
-
- def mouseGrabber(self):
- return
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。