1 回答
TA贡献1936条经验 获得超6个赞
所以,我不知道这是否特别聪明,但我想出了一个使用单独的计时器来跟踪clickEvents. 我希望这对有类似问题的人有所帮助。
import sys, pyqtgraph
from PyQt5 import QtGui, QtWidgets, QtCore
class Window(QtWidgets.QDialog):
def __init__(self, parent=None):
QtWidgets.QWidget.__init__(self)
layout = QtGui.QGridLayout(self)
self.view = pyqtgraph.GraphicsLayoutWidget()
self.timer = QtCore.QTimer()
layout.addWidget(self.view,0,0)
self.proxy = pyqtgraph.SignalProxy(self.view.scene().sigMouseMoved, rateLimit=30, slot=self.OnMouseMove)
self.view.scene().sigMouseClicked.connect(self.release)
self.timer.timeout.connect(self.release)
def release(self):
if not self.view.scene().clickEvents:
print("release after drag")
self.timer.stop()
elif not self.timer.isActive():
print("release after click")
def OnMouseMove(self):
if not self.timer.isActive() and self.view.scene().clickEvents:
self.timer.start(10) # After a drag release, this is the "wait" time before self.release is called.
def mouseReleaseEvent(self,ev): # This does only work outside the pyqtgraph widget. It overrides the method in QWidget and not in pyqtgraph.GraphicsScene()
print("released ",ev)
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
form = Window()
form.show()
sys.exit(app.exec_())
添加回答
举报