【发布时间】:2017-03-11 19:18:27
【问题描述】:
我正在尝试在 pyqtgraph 中不使用 pg.PolyLineROI() 来绘制多边形。我的目标是能够在下面显示的代码中使用大型数据集来代替“数据”。 PolyLineROI() 的问题是我不需要句柄或事件,因此加载大量数据需要很长时间,而且资源浪费在不需要的功能上。
我尝试过使用 QPainter 和 QPen,但我无法获得任何有用的东西,所以我被卡住了。有什么想法吗?
编辑的代码试图合并来自 segFaultCoder 的示例
from PyQt4 import QtCore, QtGui
import pyqtgraph as pg
import sys
class plotwindow(QtGui.QMainWindow):
def setupUi(self, MainWindow):
self.centralwidget = QtGui.QWidget(MainWindow)
MainWindow.resize(1900, 1000)
self.qt = pg.GraphicsView(MainWindow)
self.qt.setGeometry(QtCore.QRect(0,0, 1900, 1000))
self.qt2 = pg.GraphicsLayout()
self.qt.setCentralItem(self.qt2)
self.qt.show()
self.layout = self.qt2.addLayout()
self.qt3 = self.layout.addViewBox()
self.plot()
def plot(self): #This is looped for multiple data sets
data = [[6,6],[6,0],[0,6],[0,0]] #changes based on data import
self.picture = QtGui.QPicture()
p = QtGui.QPainter(self.picture)
p.setPen(pg.mkPen('w'))
self.points = []
for item in data:
point = QtCore.QPoint(item[0], item[1])
self.points.append(point)
p.drawPolygon(*self.points)
p.end()
self.qt3.addItem(p)
def paint(self, p, *args):
p.drawPicture(0, 0, self.picture)
def boundingRect(self):
return QtCore.QRectF(self.picture.boundingRect())
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
MainWindow = QtGui.QMainWindow()
ui = plotwindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
【问题讨论】: