Setting size proportion between items in a GraphicsLayout

1,912 views
Skip to first unread message

Julio Trevisan

unread,
Mar 18, 2013, 1:16:06 PM3/18/13
to pyqt...@googlegroups.com
Hi

I have a layout with three rows and 1 column. I would like to set the height of the first row as fixed (title label), and the proportions between the second and third rows as something like 13:8. Please see the code below. I am trying to set the layoutRowStretch property with no effect (the 2nd and 3rd rows do differ in height, but I have no idea how this is determined, since I tried different values with no change in this automatic proportion).

# PlotStack descends from pyqtgraph.GraphicsLayout
class PriceVolumeStack(PlotStack):
    def __init__(self, *args, **kwargs):
        PlotStack.__init__(self, *args, **kwargs)
        p = PricePlot()
        p.hideAxis("bottom")
        self.addItem(p)
        self.nextRow()
        self.addItem(VolumePlot())
        self.layoutRowStretch = [0, 13, 8]

Luke Campagnola

unread,
Mar 18, 2013, 1:31:49 PM3/18/13
to pyqt...@googlegroups.com
Hello,  'layoutRowStretch' is not a name that is used by GraphicsLayout. It does have a 'layout' attribute, which is a QGraphicsGridLayout (http://qt-project.org/doc/qt-4.8/qgraphicsgridlayout.html). So you could probably call self.layout.setRowStretchFactor(...) to achieve the effect you're after.

Luke

Julio Trevisan

unread,
Mar 18, 2013, 1:34:09 PM3/18/13
to pyqt...@googlegroups.com
Thanks a lot. I added the following lines to make this work:

        self.layout.setRowStretchFactor(0, 0)
        self.layout.setRowStretchFactor(1, 13)
        self.layout.setRowStretchFactor(2, 8)



--
-- [ You are subscribed to pyqt...@googlegroups.com. To unsubscribe, send email to pyqtgraph+...@googlegroups.com ]
---
You received this message because you are subscribed to the Google Groups "pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyqtgraph+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Julio Trevisan

unread,
Jul 2, 2014, 9:23:08 PM7/2/14
to pyqt...@googlegroups.com
Hello Luke

Still on this old thread. I recently decided to fine-tune the ratio between the heights of two plots that I have stacked using QGraphicsGridLayout::setRowStretchFactor(). 

Although changing the proportion (first plot factor)/(second plot factor) produces a visual change, the proportion is not respected exactly. I find dealing with Qt layouts confusing, likely I am missing something here. Could you please help me to sort this out? Attached are two screenshots. I attempted the proportions 9/9 and 9/11. In the 9/9 case, I expected both plots to have the same height, but they don't (they nearly do in the 9/11 case, when the second one should be higher). Does it have something to do with the fact that I hid the x-axis in the first plot?




On Monday, 18 March 2013 14:34:09 UTC-3, Julio Trevisan wrote:
Thanks a lot. I added the following lines to make this work:

        self.layout.setRowStretchFactor(0, 0)
        self.layout.setRowStretchFactor(1, 13)
        self.layout.setRowStretchFactor(2, 8)
On Mon, Mar 18, 2013 at 2:31 PM, Luke Campagnola <luke.ca...@gmail.com> wrote:

On Mon, Mar 18, 2013 at 1:16 PM, Julio Trevisan <juliot...@gmail.com> wrote:
Hi

I have a layout with three rows and 1 column. I would like to set the height of the first row as fixed (title label), and the proportions between the second and third rows as something like 13:8. Please see the code below. I am trying to set the layoutRowStretch property with no effect (the 2nd and 3rd rows do differ in height, but I have no idea how this is determined, since I tried different values with no change in this automatic proportion).

# PlotStack descends from pyqtgraph.GraphicsLayout
class PriceVolumeStack(PlotStack):
    def __init__(self, *args, **kwargs):
        PlotStack.__init__(self, *args, **kwargs)
        p = PricePlot()
        p.hideAxis("bottom")
        self.addItem(p)
        self.nextRow()
        self.addItem(VolumePlot())
        self.layoutRowStretch = [0, 13, 8]

Hello,  'layoutRowStretch' is not a name that is used by GraphicsLayout. It does have a 'layout' attribute, which is a QGraphicsGridLayout (http://qt-project.org/doc/qt-4.8/qgraphicsgridlayout.html). So you could probably call self.layout.setRowStretchFactor(...) to achieve the effect you're after.

Luke

--
-- [ You are subscribed to pyqt...@googlegroups.com. To unsubscribe, send email to pyqtgraph+unsubscribe@googlegroups.com ]

---
You received this message because you are subscribed to the Google Groups "pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyqtgraph+unsubscribe@googlegroups.com.
q-9-9.png
q-9-11.png

Luke Campagnola

unread,
Jul 6, 2014, 11:34:43 AM7/6/14
to pyqt...@googlegroups.com
On Wed, Jul 2, 2014 at 9:23 PM, Julio Trevisan <juliot...@gmail.com> wrote:
Still on this old thread. I recently decided to fine-tune the ratio between the heights of two plots that I have stacked using QGraphicsGridLayout::setRowStretchFactor(). 

Although changing the proportion (first plot factor)/(second plot factor) produces a visual change, the proportion is not respected exactly. I find dealing with Qt layouts confusing, likely I am missing something here.

You are not missing anything; Qt layouts are confusing.
 
Could you please help me to sort this out? Attached are two screenshots. I attempted the proportions 9/9 and 9/11. In the 9/9 case, I expected both plots to have the same height, but they don't (they nearly do in the 9/11 case, when the second one should be higher). Does it have something to do with the fact that I hid the x-axis in the first plot?

It is indeed because the axis is hidden that the plot sizes become different. I don't have a good explanation for this..
To be honest, I have had so much trouble with Qt layouts that I am considering writing my own layout class (but this would be a lot of work).

 

Julio Trevisan

unread,
Jul 7, 2014, 8:10:31 AM7/7/14
to pyqt...@googlegroups.com
On Sun, Jul 6, 2014 at 12:34 PM, Luke Campagnola <luke.ca...@gmail.com> wrote:
On Wed, Jul 2, 2014 at 9:23 PM, Julio Trevisan <juliot...@gmail.com> wrote:
Still on this old thread. I recently decided to fine-tune the ratio between the heights of two plots that I have stacked using QGraphicsGridLayout::setRowStretchFactor(). 

Although changing the proportion (first plot factor)/(second plot factor) produces a visual change, the proportion is not respected exactly. I find dealing with Qt layouts confusing, likely I am missing something here.

You are not missing anything; Qt layouts are confusing.

At least I am not alone in this.
 
Could you please help me to sort this out? Attached are two screenshots. I attempted the proportions 9/9 and 9/11. In the 9/9 case, I expected both plots to have the same height, but they don't (they nearly do in the 9/11 case, when the second one should be higher). Does it have something to do with the fact that I hid the x-axis in the first plot?

It is indeed because the axis is hidden that the plot sizes become different. I don't have a good explanation for this..
To be honest, I have had so much trouble with Qt layouts that I am considering writing my own layout class (but this would be a lot of work).
 There is a good chance that I would become an adept of your layout class.

Thanks 
 

 

--
You received this message because you are subscribed to the Google Groups "pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyqtgraph+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyqtgraph/CACZXET_dHVTpu1C6RmbfuUNnGDfd%3D9XDXAYCyzAfSt4Z2vu0eQ%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages