PyQT区分左键双击和左键单击

   日期:2020-05-03     浏览:426    评论:0    
核心提示:from PyQt5.QtCore import QTimer from PyQt5 import QtCore, QtGui, QtWidgets class myWidgets(QtWidgets.QTableWidget): def __init__(self, parent=None): super(myWidgets, self).__init__(parent) self.is
from PyQt5.QtCore import QTimer
from PyQt5 import QtCore, QtGui, QtWidgets

class myWidgets(QtWidgets.QTableWidget):  

    def __init__(self, parent=None):
        super(myWidgets, self).__init__(parent)
        self.isDoubleClick = False
        self.mouse = ""
    def mousePressEvent(self, e): 
        # 左键按下
        if e.buttons() == QtCore.Qt.LeftButton:
            QTimer.singleShot(0, lambda: self.judgeClick(e))
        # 右键按下
        elif e.buttons() == QtCore.Qt.RightButton:
            self.mouse = "右"
        # 中键按下
        elif e.buttons() == QtCore.Qt.MidButton:
            self.mouse = '中'
        # 左右键同时按下
        elif e.buttons() == QtCore.Qt.LeftButton | QtCore.Qt.RightButton:
            self.mouse = '左右'
        # 左中键同时按下
        elif e.buttons() == QtCore.Qt.LeftButton | QtCore.Qt.MidButton:
            self.mouse = '左中'
        # 右中键同时按下
        elif e.buttons() == QtCore.Qt.MidButton | QtCore.Qt.RightButton:
            self.mouse = '右中'
        # 左中右键同时按下
        elif e.buttons() == QtCore.Qt.LeftButton | QtCore.Qt.MidButton | QtCore.Qt.RightButton:
            self.mouse = '左中右'
    def mouseDoubleClickEvent(self,e):
        # 双击
        self.mouse = "双击"
        self.isDoubleClick=True

    def judgeClick(self,e):
        if self.isDoubleClick== False:
           self.mouse="左"
        else:
            self.isDoubleClick=False
            self.mouse = "双击"
 
打赏
 本文转载自:网络 
所有权利归属于原作者,如文章来源标示错误或侵犯了您的权利请联系微信13520258486
更多>最近资讯中心
更多>最新资讯中心
0相关评论

推荐图文
推荐资讯中心
点击排行
最新信息
新手指南
采购商服务
供应商服务
交易安全
关注我们
手机网站:
新浪微博:
微信关注:

13520258486

周一至周五 9:00-18:00
(其他时间联系在线客服)

24小时在线客服