2016-04-27 89 views
1

我正嘗試在PyQt應用程序中使用PyQtGraph創建劇情佈局。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%。

我在做什麼錯?

最好的問候,

回答

2

colspan允許你讓網格佈局跨越多個列的單元格。我合併多個網格單元格的一種方式。在你的例子中,你最終會得到1行3列的網格。前兩列顯然各佔總數的25%(或一個佔0%,另一個佔50%),第三列佔50%。簡而言之:colspan不允許您控制列的寬度。

那麼,如何設置列或其內容的寬度?這令人驚訝地很難找到。似乎沒有直接處理這個問題的PyQtGraph方法,你必須使用底層的Qt類。

A pg.GraphicsLayoutWidget以其中心項目​​爲準。這又有一個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和實驗了一下。

+0

這是完美的工作。謝謝。 – BMichell