【问题标题】:PyQtGraph Graphics Layout Widget issuePyQtGraph 图形布局小部件问题
【发布时间】:2016-08-21 17:05:19
【问题描述】:

我正在尝试在 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')

但在这种情况下,我得到两个绘图区域,每个区域占据窗口宽度的 50%。

我做错了什么?

最好的问候,

【问题讨论】:

    标签: python pyqt pyqtgraph


    【解决方案1】:

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

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

    pg.GraphicsLayoutWidget 的中心项是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)
    

    查看the documentation of QGraphicsGridLayout 并进行一些实验。

    【讨论】:

      猜你喜欢
      • 2016-09-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-09
      • 1970-01-01
      • 2019-02-21
      相关资源
      最近更新 更多