PyQT区分左键双击和左键单击(pyqt实现按钮重复点击)

网友投稿 811 2022-09-20

PyQT区分左键双击和左键单击(pyqt实现按钮重复点击)

PyQT区分左键双击和左键单击(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 = "双击"

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

         http://cnblogs.com/surpassme/

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:AIX中的网络类命令
下一篇:lamp源码编译安装脚本+源码包
相关文章

 发表评论

暂时没有评论,来抢沙发吧~