VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > temp > 简明python教程 >
  • PyQT区分左键双击和左键单击

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 = "双击"

作者: Surpassme

来源: http://www.jianshu.com/u/28161b7c9995/

         http://www.cnblogs.com/surpassme/



相关教程