2019-05-21 17:54:22 +08:00
|
|
|
|
#!/usr/bin/env python
|
|
|
|
|
# encoding: utf-8
|
2021-07-13 14:52:26 +08:00
|
|
|
|
"""
|
2019-05-21 17:54:22 +08:00
|
|
|
|
Created on 2019年5月21日
|
|
|
|
|
@author: weike32
|
2021-07-13 14:52:26 +08:00
|
|
|
|
@site: https://pyqt.site ,https://github.com/weike32
|
2019-05-21 17:54:22 +08:00
|
|
|
|
@email: 394967319@qq.com
|
|
|
|
|
@file: CopyContent
|
|
|
|
|
@description: 禁止右键,添加滑动窗口,点击按钮生成图片,自定义Y轴坐标,背景颜色调整
|
2021-07-13 14:52:26 +08:00
|
|
|
|
"""
|
2019-05-21 17:54:22 +08:00
|
|
|
|
import sys
|
2021-07-13 14:52:26 +08:00
|
|
|
|
|
2019-05-21 17:54:22 +08:00
|
|
|
|
import pyqtgraph as pg
|
2021-07-13 14:52:26 +08:00
|
|
|
|
from PyQt5.QtGui import QSpacerItem, QSizePolicy
|
|
|
|
|
from PyQt5.QtWidgets import QDialog, QApplication, QWidget, QScrollArea, QVBoxLayout
|
|
|
|
|
|
2019-05-21 18:13:13 +08:00
|
|
|
|
from PyQtGraph.Data.graphTest import graph_Form
|
2019-05-21 17:54:22 +08:00
|
|
|
|
|
2021-07-13 14:52:26 +08:00
|
|
|
|
|
2019-05-21 17:54:22 +08:00
|
|
|
|
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)
|
|
|
|
|
|
2021-07-13 14:52:26 +08:00
|
|
|
|
def wheelEvent(self, ev, axis=None):
|
2019-05-21 17:54:22 +08:00
|
|
|
|
# pg.ViewBox.wheelEvent(self, ev, axis)
|
|
|
|
|
ev.ignore()
|
|
|
|
|
|
2021-07-13 14:52:26 +08:00
|
|
|
|
|
|
|
|
|
class graphAnalysis(QDialog, graph_Form):
|
2019-05-21 17:54:22 +08:00
|
|
|
|
def __init__(self):
|
|
|
|
|
super(graphAnalysis, self).__init__()
|
|
|
|
|
self.setupUi(self)
|
|
|
|
|
self.pushButton_7.clicked.connect(self.test)
|
|
|
|
|
self.tabWidget.clear()
|
|
|
|
|
|
|
|
|
|
def test(self):
|
2021-07-13 14:52:26 +08:00
|
|
|
|
tab1 = QWidget()
|
|
|
|
|
scrollArea = QScrollArea(tab1)
|
|
|
|
|
scrollArea.setMinimumSize(984, 550)
|
2019-05-21 17:54:22 +08:00
|
|
|
|
scrollArea.setWidgetResizable(True)
|
|
|
|
|
labelsContainer = QWidget()
|
2021-07-13 14:52:26 +08:00
|
|
|
|
labelsContainer.setMinimumSize(0, 1500)
|
2019-05-21 17:54:22 +08:00
|
|
|
|
scrollArea.setWidget(labelsContainer)
|
2021-07-13 14:52:26 +08:00
|
|
|
|
layout = QVBoxLayout(labelsContainer)
|
2019-05-21 17:54:22 +08:00
|
|
|
|
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)))]
|
|
|
|
|
vb = CustomViewBox()
|
2021-07-13 14:52:26 +08:00
|
|
|
|
plt = pg.PlotWidget(title="标题这里填写", viewBox=vb)
|
2019-05-21 17:54:22 +08:00
|
|
|
|
plt.setBackground(background=None)
|
|
|
|
|
plt.plot(list(xdict.keys()), value)
|
|
|
|
|
plt.getPlotItem().getAxis("bottom").setTicks(ticks)
|
2021-07-13 14:52:26 +08:00
|
|
|
|
temp = QWidget()
|
|
|
|
|
temp.setMinimumSize(900, 300)
|
|
|
|
|
temp.setMaximumSize(900, 300)
|
|
|
|
|
layout1 = QVBoxLayout(temp)
|
2019-05-21 17:54:22 +08:00
|
|
|
|
layout1.addWidget(plt)
|
|
|
|
|
layout.addWidget(temp)
|
2021-07-13 14:52:26 +08:00
|
|
|
|
spacerItem = QSpacerItem(20, 40, QSizePolicy.Minimum,
|
|
|
|
|
QSizePolicy.Expanding)
|
2019-05-21 17:54:22 +08:00
|
|
|
|
layout.addItem(spacerItem)
|
|
|
|
|
self.tabWidget.addTab(tab1, '这里tabWidget修改标签')
|
|
|
|
|
|
2021-07-13 14:52:26 +08:00
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2019-05-21 17:54:22 +08:00
|
|
|
|
app = QApplication(sys.argv)
|
|
|
|
|
w = graphAnalysis()
|
|
|
|
|
w.show()
|
2021-07-13 14:52:26 +08:00
|
|
|
|
sys.exit(app.exec_())
|