PyQtGraph 图形布局小部件问题
PyQtGraph Graphics Layout Widget issue
我正在尝试在 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')
但在这种情况下,我得到两个绘图区域,每个区域占 window 宽度的 50%。
我做错了什么?
此致,
本
colspan
允许您让网格布局中的单元格跨越多个列。我以一种方式合并多个网格单元格。在您的示例中,您最终得到 1 行 3 列的网格。前两列显然各占总宽度的 25%(或一列为 0%,另一列为 50%),第三列占另外 50%。简而言之:colspan
不允许您控制列的宽度。
那么,如何设置列的宽度或它们的内容呢?这出奇地难找。似乎没有直接处理此问题的 PyQtGraph 方法,您必须使用底层 Qt 类.
A pg.GraphicsLayoutWidget
的中心项是 a pg.GraphicsLayout
。这又具有一个包含 Qt QGraphicsGridLayout
的 layout
成员。这允许您通过以下方式操作列宽:setColumnFixedWidth
、setColumnMaximimumWidth
、setColumnStretchFactor
等。您可能需要这样的东西:
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)
看看 the documentation of QGraphicsGridLayout 并进行一些实验。
我正在尝试在 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')
但在这种情况下,我得到两个绘图区域,每个区域占 window 宽度的 50%。
我做错了什么?
此致,
本
colspan
允许您让网格布局中的单元格跨越多个列。我以一种方式合并多个网格单元格。在您的示例中,您最终得到 1 行 3 列的网格。前两列显然各占总宽度的 25%(或一列为 0%,另一列为 50%),第三列占另外 50%。简而言之:colspan
不允许您控制列的宽度。
那么,如何设置列的宽度或它们的内容呢?这出奇地难找。似乎没有直接处理此问题的 PyQtGraph 方法,您必须使用底层 Qt 类.
A pg.GraphicsLayoutWidget
的中心项是 a pg.GraphicsLayout
。这又具有一个包含 Qt QGraphicsGridLayout
的 layout
成员。这允许您通过以下方式操作列宽:setColumnFixedWidth
、setColumnMaximimumWidth
、setColumnStretchFactor
等。您可能需要这样的东西:
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)
看看 the documentation of QGraphicsGridLayout 并进行一些实验。