我想同时使用这两个事件:mouseDoubleClick
和mouseReleaseEvent
。但是有一个问题:即使双击鼠标也会触发后一事件。
答案 0 :(得分:0)
答案如下。请发布建议以帮助我改进此代码。
from PySide2.QtCore import qApp, QTimer
from PySide2.QtWidgets import QApplication, QWidget
class Widget(QWidget):
def __init__(self):
super().__init__()
self.timer = QTimer(self)
self.timer.setSingleShot(True)
self.timer.timeout.connect(self.single_click)
self.double_click_interval = qApp.doubleClickInterval()
def mouseReleaseEvent(self, e):
if not self.timer.isActive():
self.timer.start(self.double_click_interval)
else:
self.timer.stop()
self.double_click()
super().mouseReleaseEvent(e)
def single_click(self):
print("single")
def double_click(self):
print("double")
if __name__ == '__main__':
import sys
app = QApplication(sys.argv)
w = Widget()
w.show()
w.raise_()
sys.exit(app.exec_())