updata pyqtgraph 滚动区实例 和更新README文件
This commit is contained in:
parent
d2cb0f4cad
commit
c28e04de25
6 changed files with 234 additions and 2 deletions
53
PyQtGraph/Data/graphAnalysis.py
Normal file
53
PyQtGraph/Data/graphAnalysis.py
Normal file
|
@ -0,0 +1,53 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Form implementation generated from reading ui file 'graphAnalysis.ui'
|
||||
#
|
||||
# Created by: PyQt5 UI code generator 5.11.3
|
||||
#
|
||||
# WARNING! All changes made in this file will be lost!
|
||||
|
||||
from PyQt5 import QtCore, QtGui, QtWidgets
|
||||
|
||||
class graph_Form(object):
|
||||
def setupUi(self, Form):
|
||||
Form.setObjectName("Form")
|
||||
Form.resize(1024, 768)
|
||||
self.gridLayout_3 = QtWidgets.QGridLayout(Form)
|
||||
self.gridLayout_3.setContentsMargins(20, 20, 20, 20)
|
||||
self.gridLayout_3.setSpacing(20)
|
||||
self.gridLayout_3.setObjectName("gridLayout_3")
|
||||
self.pushButton_7 = QtWidgets.QPushButton(Form)
|
||||
self.pushButton_7.setMinimumSize(QtCore.QSize(0, 80))
|
||||
font = QtGui.QFont()
|
||||
font.setPointSize(15)
|
||||
self.pushButton_7.setFont(font)
|
||||
self.pushButton_7.setObjectName("pushButton_7")
|
||||
self.gridLayout_3.addWidget(self.pushButton_7, 2, 2, 1, 2)
|
||||
self.label = QtWidgets.QLabel(Form)
|
||||
font = QtGui.QFont()
|
||||
font.setPointSize(15)
|
||||
self.label.setFont(font)
|
||||
self.label.setAlignment(QtCore.Qt.AlignCenter)
|
||||
self.label.setObjectName("label")
|
||||
self.gridLayout_3.addWidget(self.label, 0, 0, 1, 4)
|
||||
self.tabWidget = QtWidgets.QTabWidget(Form)
|
||||
self.tabWidget.setObjectName("tabWidget")
|
||||
self.tab = QtWidgets.QWidget()
|
||||
self.tab.setObjectName("tab")
|
||||
self.tabWidget.addTab(self.tab, "")
|
||||
self.tab_2 = QtWidgets.QWidget()
|
||||
self.tab_2.setObjectName("tab_2")
|
||||
self.tabWidget.addTab(self.tab_2, "")
|
||||
self.gridLayout_3.addWidget(self.tabWidget, 1, 1, 1, 4)
|
||||
|
||||
self.retranslateUi(Form)
|
||||
QtCore.QMetaObject.connectSlotsByName(Form)
|
||||
|
||||
def retranslateUi(self, Form):
|
||||
_translate = QtCore.QCoreApplication.translate
|
||||
Form.setWindowTitle(_translate("Form", "Form"))
|
||||
self.pushButton_7.setText(_translate("Form", "分析"))
|
||||
self.label.setText(_translate("Form", "图形分析"))
|
||||
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab), _translate("Form", "折线图"))
|
||||
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_2), _translate("Form", "Tab 2"))
|
||||
|
83
PyQtGraph/Data/graphAnalysis.ui
Normal file
83
PyQtGraph/Data/graphAnalysis.ui
Normal file
|
@ -0,0 +1,83 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>Form</class>
|
||||
<widget class="QWidget" name="Form">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>1024</width>
|
||||
<height>768</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_3">
|
||||
<property name="leftMargin">
|
||||
<number>20</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>20</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>20</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>20</number>
|
||||
</property>
|
||||
<property name="spacing">
|
||||
<number>20</number>
|
||||
</property>
|
||||
<item row="2" column="2" colspan="2">
|
||||
<widget class="QPushButton" name="pushButton_7">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>80</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>15</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>分析</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0" colspan="4">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>15</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>图形分析</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1" colspan="4">
|
||||
<widget class="QTabWidget" name="tabWidget">
|
||||
<widget class="QWidget" name="tab">
|
||||
<attribute name="title">
|
||||
<string>折线图</string>
|
||||
</attribute>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tab_2">
|
||||
<attribute name="title">
|
||||
<string>Tab 2</string>
|
||||
</attribute>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
|
@ -27,5 +27,10 @@
|
|||
|
||||
![mouseFlow](ScreenShot/function.gif)
|
||||
|
||||
## 2、不用修改源码,重加载,解决右键保存图片异常;解决自定义坐标轴密集显示;禁止鼠标事件;
|
||||
## 3、不用修改源码,重加载,解决右键保存图片异常;解决自定义坐标轴密集显示;禁止鼠标事件;
|
||||
[加载 tools.py](tools.py)
|
||||
|
||||
## 4、QScrollArea添加和修改大小例子;
|
||||
[运行 testGraphAnalysis.py](testGraphAnalysis.py)
|
||||
|
||||
![testGraphAnalysis](ScreenShot/GraphAnalysis.gif)
|
||||
|
|
BIN
PyQtGraph/ScreenShot/GraphAnalysis.gif
Normal file
BIN
PyQtGraph/ScreenShot/GraphAnalysis.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 422 KiB |
90
PyQtGraph/testGraphAnalysis.py
Normal file
90
PyQtGraph/testGraphAnalysis.py
Normal file
|
@ -0,0 +1,90 @@
|
|||
#!/usr/bin/env python
|
||||
# encoding: utf-8
|
||||
'''
|
||||
Created on 2019年8月17日
|
||||
@author: weike32
|
||||
@site: https://pyqt5.com ,https://github.com/weike32
|
||||
@email: 394967319@qq.com
|
||||
@file: CopyContent
|
||||
@description:
|
||||
'''
|
||||
import sys
|
||||
from PyQt5.QtCore import Qt
|
||||
from PyQt5.QtWidgets import QDialog, QApplication, QWidget
|
||||
from qtpy import QtWidgets
|
||||
import pyqtgraph as pg
|
||||
|
||||
from PyQtGraph.Data.graphAnalysis import graph_Form
|
||||
|
||||
|
||||
class CustomViewBox(pg.ViewBox):
|
||||
def __init__(self, *args, **kwds):
|
||||
pg.ViewBox.__init__(self, *args, **kwds)
|
||||
self.RectMode = 3
|
||||
self.setMouseMode(self.RectMode)
|
||||
|
||||
def mouseClickEvent(self, ev):
|
||||
if ev.button() == pg.QtCore.Qt.RightButton:
|
||||
self.autoRange()
|
||||
def mouseDragEvent(self, ev):
|
||||
pg.ViewBox.mouseDragEvent(self, ev)
|
||||
def wheelEvent(self,ev,axis=None):
|
||||
ev.ignore()
|
||||
|
||||
class graphAnalysis(QDialog,graph_Form):
|
||||
def __init__(self):
|
||||
super(graphAnalysis, self).__init__()
|
||||
self.setupUi(self)
|
||||
self.pushButton_7.clicked.connect(self.test)
|
||||
self.tabWidget.clear()
|
||||
|
||||
def handleChanged(self,item,column):
|
||||
count = item.childCount()
|
||||
if item.checkState(column) == Qt.Checked:
|
||||
for index in range(count):
|
||||
item.child(index).setCheckState(0,Qt.Checked)
|
||||
if item.checkState(column) == Qt.Unchecked:
|
||||
for index in range(count):
|
||||
item.child(index).setCheckState(0,Qt.Unchecked)
|
||||
|
||||
def test(self):
|
||||
|
||||
tab1 = QtWidgets.QWidget()
|
||||
scrollArea = QtWidgets.QScrollArea(tab1)
|
||||
scrollArea.setMinimumSize(650,550)
|
||||
scrollArea.setWidgetResizable(True)
|
||||
|
||||
labelsContainer = QWidget()
|
||||
labelsContainer.setMinimumSize(0,3000+200)
|
||||
scrollArea.setWidget(labelsContainer)
|
||||
layout = QtWidgets.QVBoxLayout(labelsContainer)
|
||||
|
||||
time = ['2019-04-20 08:09:00', '2019-04-20 08:09:00', '2019-04-20 08:09:00', '2019-04-20 08:09:00']
|
||||
value = [1.2, 2, 1, 4]
|
||||
xdict = dict(enumerate(time))
|
||||
ticks = [list(zip(range(4), tuple(time)))]
|
||||
for i in range(11):
|
||||
vb1 = CustomViewBox()
|
||||
plt1 = pg.PlotWidget(title="Basic array plotting%s"%i, viewBox=vb1)
|
||||
plt1.resize(500, 500)
|
||||
plt1.setBackground(background=None)
|
||||
plt1.plot(list(xdict.keys()), value)
|
||||
plt1.getPlotItem().getAxis("bottom").setTicks(ticks)
|
||||
temp1 = QtWidgets.QWidget()
|
||||
temp1.setMinimumSize(600, 300)
|
||||
temp1.setMaximumSize(600, 300)
|
||||
layout2 = QtWidgets.QVBoxLayout(temp1)
|
||||
layout2.addWidget(plt1)
|
||||
layout.addWidget(temp1)
|
||||
spacerItem = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
|
||||
layout.addItem(spacerItem)
|
||||
# print(layout.count())
|
||||
self.tabWidget.addTab(tab1, '12')
|
||||
for i in range(self.tabWidget.count()):
|
||||
self.tabWidget.widget(i)
|
||||
|
||||
if __name__ =="__main__":
|
||||
app = QApplication(sys.argv)
|
||||
w = graphAnalysis()
|
||||
w.show()
|
||||
sys.exit(app.exec_())
|
|
@ -158,6 +158,7 @@ https://pyqt5.com 社区是专门针对PyQt5学习和提升开设的博客网站
|
|||
- [鼠标获取X轴坐标](PyQtGraph/mouseFlow.py)
|
||||
- [禁止右键点击功能、鼠标滚轮,添加滚动条等功能](PyQtGraph/graph1.py)
|
||||
- [工具类](PyQtGraph/tools.py)
|
||||
- [滚动区相关](PyQtGraph/testGraphAnalysis.py)
|
||||
|
||||
- [Animation](QPropertyAnimation)
|
||||
- [窗口淡入淡出](QPropertyAnimation/FadeInOut.py)
|
||||
|
|
Loading…
Reference in a new issue