赞
踩
- class QmyChartView(QChartView):
- mouseMove=pyqtSignal(QPoint)##鼠标移动
-
- def __init__(self, parent=None):
- super().__init__(parent)
- self.setDragMode(QGraphicsView.DragMode.RubberBandDrag)
-
- self.__beginPoint=QPoint()
- self.__endPoint=QPoint()
(一) 鼠标的事件函数:
- def mousePressEvent(self, event):##鼠标单击
- if event.button()==Qt.MouseButton.LeftButton:
- self.__beginPoint=event.pos()
- super().mousePressEvent(event)
-
- def mouseMoveEvent(self, event):##鼠标移动
- point=event.pos()
- self.mouseMove.emit(point)
- super().mouseMoveEvent(event)
-
- def mouseReleaseEvent(self, event):##鼠标框选放大,右键恢复
- if event.button()==Qt.MouseButton.LeftButton:
- self.__endPoint=event.pos()
- rectF=QRectF()
- rectF.setTopLeft(self.__beginPoint.toPointF())
- rectF.setBottomRight(self.__endPoint.toPointF())
- self.chart().zoomIn(rectF)
- elif event.button()==Qt.MouseButton.RightButton:
- self.chart().zoomReset()#鼠标右键释放,resetZoon

- def keyPressEvent(self, event):
- key=event.key()
- if key ==Qt.Key.Key_Plus:# +
- self.chart().zoom(1.2)
- elif key ==Qt.Key.Key_Minus:# -
- self.chart().zoom(0.8)
- elif key==Qt.Key.Key_Left: #向左
- self.chart().scroll(10, 0)
- elif key ==Qt.Key.Key_Right:#向右
- self.chart().scroll(-10, 0)
- elif key==Qt.Key.Key_Up:#向上
- self.chart().scroll(0, -10)
- elif key==Qt.Key.Key_Down:#向下
- self.chart(0, 10)
- elif key==Qt.Key.Key_PageUp:#pageup
- self.chart().scroll(0, -50)
- elif key==Qt.Key.Key_PageDown:#pagedown
- self.chart().scroll(0, 50)
- elif key ==Qt.Key.Key_Home:#home
- self.chart().zoomReset()

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。