```python from PyQt5.QtCore import QTimer from PyQt5 import QtCore, QtGui, QtWidgets class myWidgets(QtWidgets.QTableWidget): def __init__(self, paren... ...
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 = "雙擊"