Define our own mouse clicked handler
parent
a55d72f8d6
commit
d492f5c35a
|
@ -288,6 +288,7 @@ class ChartView(ViewBox):
|
||||||
) -> None:
|
) -> None:
|
||||||
# if axis is specified, event will only affect that axis.
|
# if axis is specified, event will only affect that axis.
|
||||||
ev.accept() # we accept all buttons
|
ev.accept() # we accept all buttons
|
||||||
|
button = ev.button()
|
||||||
|
|
||||||
pos = ev.pos()
|
pos = ev.pos()
|
||||||
lastPos = ev.lastPos()
|
lastPos = ev.lastPos()
|
||||||
|
@ -301,7 +302,9 @@ class ChartView(ViewBox):
|
||||||
mask[1-axis] = 0.0
|
mask[1-axis] = 0.0
|
||||||
|
|
||||||
# Scale or translate based on mouse button
|
# Scale or translate based on mouse button
|
||||||
if ev.button() & (QtCore.Qt.LeftButton | QtCore.Qt.MidButton):
|
if button & (QtCore.Qt.LeftButton | QtCore.Qt.MidButton):
|
||||||
|
|
||||||
|
# print(f'left click drag pos {pos}')
|
||||||
|
|
||||||
# zoom only y-axis when click-n-drag on it
|
# zoom only y-axis when click-n-drag on it
|
||||||
if axis == 1:
|
if axis == 1:
|
||||||
|
@ -340,6 +343,8 @@ class ChartView(ViewBox):
|
||||||
# update shape of scale box
|
# update shape of scale box
|
||||||
# self.updateScaleBox(ev.buttonDownPos(), ev.pos())
|
# self.updateScaleBox(ev.buttonDownPos(), ev.pos())
|
||||||
else:
|
else:
|
||||||
|
# default bevavior: click to pan view
|
||||||
|
|
||||||
tr = self.childGroup.transform()
|
tr = self.childGroup.transform()
|
||||||
tr = fn.invertQTransform(tr)
|
tr = fn.invertQTransform(tr)
|
||||||
tr = tr.map(dif*mask) - tr.map(Point(0, 0))
|
tr = tr.map(dif*mask) - tr.map(Point(0, 0))
|
||||||
|
@ -348,13 +353,16 @@ class ChartView(ViewBox):
|
||||||
y = tr.y() if mask[1] == 1 else None
|
y = tr.y() if mask[1] == 1 else None
|
||||||
|
|
||||||
self._resetTarget()
|
self._resetTarget()
|
||||||
|
|
||||||
if x is not None or y is not None:
|
if x is not None or y is not None:
|
||||||
self.translateBy(x=x, y=y)
|
self.translateBy(x=x, y=y)
|
||||||
|
|
||||||
self.sigRangeChangedManually.emit(self.state['mouseEnabled'])
|
self.sigRangeChangedManually.emit(self.state['mouseEnabled'])
|
||||||
|
|
||||||
elif ev.button() & QtCore.Qt.RightButton:
|
elif button & QtCore.Qt.RightButton:
|
||||||
|
|
||||||
|
# right click zoom to center behaviour
|
||||||
|
|
||||||
# print "vb.rightDrag"
|
|
||||||
if self.state['aspectLocked'] is not False:
|
if self.state['aspectLocked'] is not False:
|
||||||
mask[0] = 0
|
mask[0] = 0
|
||||||
|
|
||||||
|
@ -374,6 +382,20 @@ class ChartView(ViewBox):
|
||||||
self.scaleBy(x=x, y=y, center=center)
|
self.scaleBy(x=x, y=y, center=center)
|
||||||
self.sigRangeChangedManually.emit(self.state['mouseEnabled'])
|
self.sigRangeChangedManually.emit(self.state['mouseEnabled'])
|
||||||
|
|
||||||
|
def mouseClickEvent(self, ev):
|
||||||
|
"""Full-click callback.
|
||||||
|
|
||||||
|
"""
|
||||||
|
button = ev.button()
|
||||||
|
pos = ev.pos()
|
||||||
|
|
||||||
|
if button == QtCore.Qt.RightButton and self.menuEnabled():
|
||||||
|
ev.accept()
|
||||||
|
self.raiseContextMenu(ev)
|
||||||
|
|
||||||
|
elif button == QtCore.Qt.LeftButton:
|
||||||
|
print(f'clicked {pos}')
|
||||||
|
|
||||||
def keyReleaseEvent(self, ev):
|
def keyReleaseEvent(self, ev):
|
||||||
# print(f'release: {ev.text().encode()}')
|
# print(f'release: {ev.text().encode()}')
|
||||||
if ev.isAutoRepeat():
|
if ev.isAutoRepeat():
|
||||||
|
|
Loading…
Reference in New Issue