Skip to content

Commit c28e04d

Browse files
committed
updata pyqtgraph 滚动区实例 和更新README文件
1 parent d2cb0f4 commit c28e04d

File tree

6 files changed

+234
-2
lines changed

6 files changed

+234
-2
lines changed

PyQtGraph/Data/graphAnalysis.py

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# -*- coding: utf-8 -*-
2+
3+
# Form implementation generated from reading ui file 'graphAnalysis.ui'
4+
#
5+
# Created by: PyQt5 UI code generator 5.11.3
6+
#
7+
# WARNING! All changes made in this file will be lost!
8+
9+
from PyQt5 import QtCore, QtGui, QtWidgets
10+
11+
class graph_Form(object):
12+
def setupUi(self, Form):
13+
Form.setObjectName("Form")
14+
Form.resize(1024, 768)
15+
self.gridLayout_3 = QtWidgets.QGridLayout(Form)
16+
self.gridLayout_3.setContentsMargins(20, 20, 20, 20)
17+
self.gridLayout_3.setSpacing(20)
18+
self.gridLayout_3.setObjectName("gridLayout_3")
19+
self.pushButton_7 = QtWidgets.QPushButton(Form)
20+
self.pushButton_7.setMinimumSize(QtCore.QSize(0, 80))
21+
font = QtGui.QFont()
22+
font.setPointSize(15)
23+
self.pushButton_7.setFont(font)
24+
self.pushButton_7.setObjectName("pushButton_7")
25+
self.gridLayout_3.addWidget(self.pushButton_7, 2, 2, 1, 2)
26+
self.label = QtWidgets.QLabel(Form)
27+
font = QtGui.QFont()
28+
font.setPointSize(15)
29+
self.label.setFont(font)
30+
self.label.setAlignment(QtCore.Qt.AlignCenter)
31+
self.label.setObjectName("label")
32+
self.gridLayout_3.addWidget(self.label, 0, 0, 1, 4)
33+
self.tabWidget = QtWidgets.QTabWidget(Form)
34+
self.tabWidget.setObjectName("tabWidget")
35+
self.tab = QtWidgets.QWidget()
36+
self.tab.setObjectName("tab")
37+
self.tabWidget.addTab(self.tab, "")
38+
self.tab_2 = QtWidgets.QWidget()
39+
self.tab_2.setObjectName("tab_2")
40+
self.tabWidget.addTab(self.tab_2, "")
41+
self.gridLayout_3.addWidget(self.tabWidget, 1, 1, 1, 4)
42+
43+
self.retranslateUi(Form)
44+
QtCore.QMetaObject.connectSlotsByName(Form)
45+
46+
def retranslateUi(self, Form):
47+
_translate = QtCore.QCoreApplication.translate
48+
Form.setWindowTitle(_translate("Form", "Form"))
49+
self.pushButton_7.setText(_translate("Form", "分析"))
50+
self.label.setText(_translate("Form", "图形分析"))
51+
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab), _translate("Form", "折线图"))
52+
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_2), _translate("Form", "Tab 2"))
53+

PyQtGraph/Data/graphAnalysis.ui

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ui version="4.0">
3+
<class>Form</class>
4+
<widget class="QWidget" name="Form">
5+
<property name="geometry">
6+
<rect>
7+
<x>0</x>
8+
<y>0</y>
9+
<width>1024</width>
10+
<height>768</height>
11+
</rect>
12+
</property>
13+
<property name="windowTitle">
14+
<string>Form</string>
15+
</property>
16+
<layout class="QGridLayout" name="gridLayout_3">
17+
<property name="leftMargin">
18+
<number>20</number>
19+
</property>
20+
<property name="topMargin">
21+
<number>20</number>
22+
</property>
23+
<property name="rightMargin">
24+
<number>20</number>
25+
</property>
26+
<property name="bottomMargin">
27+
<number>20</number>
28+
</property>
29+
<property name="spacing">
30+
<number>20</number>
31+
</property>
32+
<item row="2" column="2" colspan="2">
33+
<widget class="QPushButton" name="pushButton_7">
34+
<property name="minimumSize">
35+
<size>
36+
<width>0</width>
37+
<height>80</height>
38+
</size>
39+
</property>
40+
<property name="font">
41+
<font>
42+
<pointsize>15</pointsize>
43+
</font>
44+
</property>
45+
<property name="text">
46+
<string>分析</string>
47+
</property>
48+
</widget>
49+
</item>
50+
<item row="0" column="0" colspan="4">
51+
<widget class="QLabel" name="label">
52+
<property name="font">
53+
<font>
54+
<pointsize>15</pointsize>
55+
</font>
56+
</property>
57+
<property name="text">
58+
<string>图形分析</string>
59+
</property>
60+
<property name="alignment">
61+
<set>Qt::AlignCenter</set>
62+
</property>
63+
</widget>
64+
</item>
65+
<item row="1" column="1" colspan="4">
66+
<widget class="QTabWidget" name="tabWidget">
67+
<widget class="QWidget" name="tab">
68+
<attribute name="title">
69+
<string>折线图</string>
70+
</attribute>
71+
</widget>
72+
<widget class="QWidget" name="tab_2">
73+
<attribute name="title">
74+
<string>Tab 2</string>
75+
</attribute>
76+
</widget>
77+
</widget>
78+
</item>
79+
</layout>
80+
</widget>
81+
<resources/>
82+
<connections/>
83+
</ui>

PyQtGraph/README.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,10 @@
2727

2828
![mouseFlow](ScreenShot/function.gif)
2929

30-
## 2、不用修改源码,重加载,解决右键保存图片异常;解决自定义坐标轴密集显示;禁止鼠标事件;
31-
[加载 tools.py](tools.py)
30+
## 3、不用修改源码,重加载,解决右键保存图片异常;解决自定义坐标轴密集显示;禁止鼠标事件;
31+
[加载 tools.py](tools.py)
32+
33+
## 4、QScrollArea添加和修改大小例子;
34+
[运行 testGraphAnalysis.py](testGraphAnalysis.py)
35+
36+
![testGraphAnalysis](ScreenShot/GraphAnalysis.gif)
422 KB
Loading

PyQtGraph/testGraphAnalysis.py

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#!/usr/bin/env python
2+
# encoding: utf-8
3+
'''
4+
Created on 2019年8月17日
5+
@author: weike32
6+
@site: https://pyqt5.com ,https://github.com/weike32
7+
8+
@file: CopyContent
9+
@description:
10+
'''
11+
import sys
12+
from PyQt5.QtCore import Qt
13+
from PyQt5.QtWidgets import QDialog, QApplication, QWidget
14+
from qtpy import QtWidgets
15+
import pyqtgraph as pg
16+
17+
from PyQtGraph.Data.graphAnalysis import graph_Form
18+
19+
20+
class CustomViewBox(pg.ViewBox):
21+
def __init__(self, *args, **kwds):
22+
pg.ViewBox.__init__(self, *args, **kwds)
23+
self.RectMode = 3
24+
self.setMouseMode(self.RectMode)
25+
26+
def mouseClickEvent(self, ev):
27+
if ev.button() == pg.QtCore.Qt.RightButton:
28+
self.autoRange()
29+
def mouseDragEvent(self, ev):
30+
pg.ViewBox.mouseDragEvent(self, ev)
31+
def wheelEvent(self,ev,axis=None):
32+
ev.ignore()
33+
34+
class graphAnalysis(QDialog,graph_Form):
35+
def __init__(self):
36+
super(graphAnalysis, self).__init__()
37+
self.setupUi(self)
38+
self.pushButton_7.clicked.connect(self.test)
39+
self.tabWidget.clear()
40+
41+
def handleChanged(self,item,column):
42+
count = item.childCount()
43+
if item.checkState(column) == Qt.Checked:
44+
for index in range(count):
45+
item.child(index).setCheckState(0,Qt.Checked)
46+
if item.checkState(column) == Qt.Unchecked:
47+
for index in range(count):
48+
item.child(index).setCheckState(0,Qt.Unchecked)
49+
50+
def test(self):
51+
52+
tab1 = QtWidgets.QWidget()
53+
scrollArea = QtWidgets.QScrollArea(tab1)
54+
scrollArea.setMinimumSize(650,550)
55+
scrollArea.setWidgetResizable(True)
56+
57+
labelsContainer = QWidget()
58+
labelsContainer.setMinimumSize(0,3000+200)
59+
scrollArea.setWidget(labelsContainer)
60+
layout = QtWidgets.QVBoxLayout(labelsContainer)
61+
62+
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']
63+
value = [1.2, 2, 1, 4]
64+
xdict = dict(enumerate(time))
65+
ticks = [list(zip(range(4), tuple(time)))]
66+
for i in range(11):
67+
vb1 = CustomViewBox()
68+
plt1 = pg.PlotWidget(title="Basic array plotting%s"%i, viewBox=vb1)
69+
plt1.resize(500, 500)
70+
plt1.setBackground(background=None)
71+
plt1.plot(list(xdict.keys()), value)
72+
plt1.getPlotItem().getAxis("bottom").setTicks(ticks)
73+
temp1 = QtWidgets.QWidget()
74+
temp1.setMinimumSize(600, 300)
75+
temp1.setMaximumSize(600, 300)
76+
layout2 = QtWidgets.QVBoxLayout(temp1)
77+
layout2.addWidget(plt1)
78+
layout.addWidget(temp1)
79+
spacerItem = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
80+
layout.addItem(spacerItem)
81+
# print(layout.count())
82+
self.tabWidget.addTab(tab1, '12')
83+
for i in range(self.tabWidget.count()):
84+
self.tabWidget.widget(i)
85+
86+
if __name__ =="__main__":
87+
app = QApplication(sys.argv)
88+
w = graphAnalysis()
89+
w.show()
90+
sys.exit(app.exec_())

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ https://pyqt5.com 社区是专门针对PyQt5学习和提升开设的博客网站
158158
- [鼠标获取X轴坐标](PyQtGraph/mouseFlow.py)
159159
- [禁止右键点击功能、鼠标滚轮,添加滚动条等功能](PyQtGraph/graph1.py)
160160
- [工具类](PyQtGraph/tools.py)
161+
- [滚动区相关](PyQtGraph/testGraphAnalysis.py)
161162

162163
- [Animation](QPropertyAnimation)
163164
- [窗口淡入淡出](QPropertyAnimation/FadeInOut.py)

0 commit comments

Comments
 (0)