PyQt/PyQtGraph/graph1.py

75 lines
2.5 KiB
Python
Raw Normal View History

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