diff --git a/Qpyqtgraph/README.md b/Qpyqtgraph/README.md index ab34e3d..53ef9f6 100644 --- a/Qpyqtgraph/README.md +++ b/Qpyqtgraph/README.md @@ -7,5 +7,14 @@ - 3、pyqtgraph如何禁止左键,右键,滑轮事件功能 - 4、使用QScrollArea后添加pg.PlotWidget()不能选择图片尺寸问题。 - 5、多图共享轴(Difficult) +- 6、pg.PlotWidget()鼠标获取X轴坐标 -- 目录 \ No newline at end of file +- 目录 + - [pg.PlotWidget()鼠标获取X轴坐标](#1、pg.PlotWidget()鼠标获取X轴坐标) + + ## 1、Sqlalchemy动态拼接字段查询显示表格 +[运行 mouseFlow.py](mouseFlow.py) + +移动鼠标获取X轴坐标 + +![mouseFlow](ScreenShot/mouseFlow.gif) \ No newline at end of file diff --git a/Qpyqtgraph/ScreenShot/mouseFlow.gif b/Qpyqtgraph/ScreenShot/mouseFlow.gif new file mode 100644 index 0000000..646ab99 Binary files /dev/null and b/Qpyqtgraph/ScreenShot/mouseFlow.gif differ diff --git a/Qpyqtgraph/mouseFlow.py b/Qpyqtgraph/mouseFlow.py new file mode 100644 index 0000000..9efe804 --- /dev/null +++ b/Qpyqtgraph/mouseFlow.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python +# encoding: utf-8 +''' +Created on 2017年5月2日 +@author: weike32 +@site: https://pyqt5.com ,https://github.com/weike32 +@email: 394967319@qq.com +@file: CopyContent +@description: 查阅了很多博客,如果有异,可以联系作者邮箱。本Demo仅作学习参考用,保有后续相关权益。 +''' +import sys +from PyQt5.QtWidgets import QApplication, QMainWindow +from PyQt5 import QtCore +import numpy as np +import pyqtgraph as pg + +class Ui_Form(object): + def setupUi(self, Form): + Form.setObjectName("Form") + Form.resize(726, 595) + self.graphicsView = pg.PlotWidget(Form) + self.graphicsView.setGeometry(QtCore.QRect(75, 131, 621, 441)) + self.graphicsView.setObjectName("graphicsView") + +class MyWindow(QMainWindow, Ui_Form): + def __init__(self, parent=None): + super(MyWindow, self).__init__(parent) + self.setupUi(self) + x = np.linspace(-100, 100, 1000) + data = np.sin(x) / x + self.graphicsView.plot(data, pen=(255, 255, 255, 200)) + self.label = pg.TextItem(text="横坐标:{}".format(0)) + self.graphicsView.addItem(self.label) + self.setMouseTracking(True) + self.graphicsView.scene().sigMouseMoved.connect(self.onMouseMoved) + def onMouseMoved(self, evt): + if self.graphicsView.plotItem.vb.mapSceneToView(evt): + point =self.graphicsView.plotItem.vb.mapSceneToView(evt) + self.label.setHtml("

横坐标:{0}

".format(point.x())) +if __name__ == '__main__': + app = QApplication(sys.argv) + myWin = MyWindow() + myWin.show() + sys.exit(app.exec_()) \ No newline at end of file