QSplitter inside a GraphicsLayout

64 views
Skip to first unread message

Stavros Ntaountakis

unread,
Feb 26, 2024, 8:08:19 AMFeb 26
to pyqtgraph
Hello,

I have a GraphicsLayoutWidget which includes many sub layouts (GraphicsLayout).

Each sub-layout contains a LegendItem (left) and a PlotItem (right).

I want to place the equivalent of a QSplitter that adjusts the ratio of the LegendItem relative to the PlotItem inside the sub-layout.

Since I want to keep all the sub-layouts in a GraphicsLayout, using pyqtgraph.LayoutWidget to add a QSplitter with a PlotWidget and a custom LegendWidget is out of the question. 

Using docks is also not something that will work, since I want my plots to share the same scene.

Is there a way to have the equivalent of a QSplitter that can adjust GraphicsWidgets and be placed inside a GraphicsLayout?

A reproducable example as reference:

app = pg.mkQApp()
layout = pg.GraphicsLayoutWidget(show=True)
layout.setMinimumSize(2*650, 300)

plot = pg.PlotItem()
legend = pg.LegendItem()
legend.setParentItem(plot)
plot.legend = legend

plot2 = pg.PlotItem()
legend2 = pg.LegendItem()
legend2.setParentItem(plot2)
plot2.legend = legend2

x = np.linspace(0, 10, 100)
y = np.sin(x)
y2 = np.cos(x)

plot.plot(x, y, name='sinx')
plot2.plot(x, y2, name='cosx')

layout1 = layout.addLayout(row=0, col=0)
layout1.setMinimumSize(650, 300)

layout1.addItem(legend)
layout1.addItem(plot)

layout2 = layout.addLayout(row=0, col=1)
layout2.setMinimumSize(650, 300)

layout2.addItem(legend2)
layout2.addItem(plot2)


if __name__ == "__main__":
    # app.exec()
    pg.exec()

Thank you
Reply all
Reply to author
Forward
0 new messages