PyQtGraph图形布局小部件问题

BMi*_*ell 4 python pyqt pyqtgraph

我正在尝试在 PyQt 应用程序中使用 PyQtGraph 创建绘图布局。

我需要一行有两个图,前两列宽,第二个单列宽。

阅读文档我认为这样的事情会起作用:

# Create the PyQtGraph Plot area
self.view = pg.GraphicsLayoutWidget()
self.w1 = self.view.addPlot(row=1, col=1, colspan=2, title = 'Data1')
self.w2 = self.view.addPlot(row=1, col=3, colspan=1, title = 'Data2')
Run Code Online (Sandbox Code Playgroud)

但在本例中,我得到两个绘图区域,每个区域占窗口宽度的 50%。

我究竟做错了什么?

此致,

tit*_*jan 5

colspan允许您让网格布局中的单元格跨越多个列。我用一种方法合并多个网格单元。在您的示例中,您最终得到一个 1 行 x 3 列的网格。前两列显然各占总宽度的 25%(或者一列为 0%,另一列为 50%),第三列占另外 50%。简而言之:colspan不允许您控制列的宽度。

那么,如何设置列的宽度或其内容呢?令人惊讶的是,很难找到。似乎没有 PyQtGraph 方法可以直接处理这个问题,您必须使用底层 Qt 类。

Apg.GraphicsLayoutWidget将 a 作为其中心项pg.GraphicsLayout。这又具有一个layout包含 Qt 的成员QGraphicsGridLayout。这允许您使用以下方式操纵列宽:setColumnFixedWidthsetColumnMaximimumWidthsetColumnStretchFactor等。您可能需要这样的东西:

self.view = pg.GraphicsLayoutWidget()
self.w1 = self.view.addPlot(row=0, col=0, title = 'Data1')
self.w2 = self.view.addPlot(row=0, col=1, title = 'Data2')

qGraphicsGridLayout = self.view.ci.layout
qGraphicsGridLayout.setColumnStretchFactor(0, 2)
qGraphicsGridLayout.setColumnStretchFactor(1, 1)
Run Code Online (Sandbox Code Playgroud)

查看QGraphicsGridLayout 的文档并进行一些实验。