controlling the size of a PlotItem and Gradient widget as a function of another PlotItem?

958 views
Skip to first unread message

Vincent Le Saux

unread,
Jul 3, 2014, 5:44:34 PM7/3/14
to pyqt...@googlegroups.com
Dear all,

I'm currently implementing an ImageWidget on PyQtGraph, very similar to the ImageView widget, but with some layout modifications and the addition of a dedicated axisitem to the gradient (screenshot provided in attachement : file named ImageWidget.png). This widget is composed of 3 widgets connected together:
   - a PlotWidget displaying an image (widget 1)
   - a GradientWidget composed of a colorbar and an axis indicating the values related to the colobar (widget 2)
   - a PlotWidget displaying the histogram of the image and a LinearRegionItem connected to the colorbar and its axis (widget 3)

Everything is fully functionnal, but there remains two problems:
 1. I want the size of the colorbar (and its axis) to be exactly the same as the widget 1 PlotItem (and in the prolongation) as illustrated by the red element in the fileImageWidget_wanted.png. I would like to It is possible to do that in PyQtGraph?
 2. I would like to adapt the size of the PlotItem axis of widget 3 so that its width is exactly the same as the widget 1 PlotItem axis (in the prolongation in fact) as illustrated by the blue lines in the file ImageWidget_wanted.png. Is it possible with PyQtGraph?

Any help will be grealty appreciated. When these problems are solved, I will of course provide the source code!

Regards,

vls 

ImageWidget.png
ImageWidget_wanted.png

Luke Campagnola

unread,
Jul 6, 2014, 7:19:30 AM7/6/14
to pyqt...@googlegroups.com
Looks really good!

On Thu, Jul 3, 2014 at 5:44 PM, Vincent Le Saux <vincent...@gmail.com> wrote:
Everything is fully functionnal, but there remains two problems:
 1. I want the size of the colorbar (and its axis) to be exactly the same as the widget 1 PlotItem (and in the prolongation) as illustrated by the red element in the fileImageWidget_wanted.png. I would like to It is possible to do that in PyQtGraph?

Perhaps use QGraphicsWidget.setMaximumHeight() and setMinimumHeight() to enforce the size, or add a spacer of fixed size to the layout. Either way, you'll need to have some code that reacts when the widget is resized.
 
 2. I would like to adapt the size of the PlotItem axis of widget 3 so that its width is exactly the same as the widget 1 PlotItem axis (in the prolongation in fact) as illustrated by the blue lines in the file ImageWidget_wanted.png. Is it possible with PyQtGraph?

Same solution as above. You might also find that it is easier to do without the layout entirely and manually set the position / size of each widget whenever the top level widget is resized.

Luke Campagnola

unread,
Jul 6, 2014, 12:15:58 PM7/6/14
to pyqt...@googlegroups.com
On Thu, Jul 3, 2014 at 5:44 PM, Vincent Le Saux <vincent...@gmail.com> wrote:
Everything is fully functionnal, but there remains two problems:
 1. I want the size of the colorbar (and its axis) to be exactly the same as the widget 1 PlotItem (and in the prolongation) as illustrated by the red element in the fileImageWidget_wanted.png. I would like to It is possible to do that in PyQtGraph?
 2. I would like to adapt the size of the PlotItem axis of widget 3 so that its width is exactly the same as the widget 1 PlotItem axis (in the prolongation in fact) as illustrated by the blue lines in the file ImageWidget_wanted.png. Is it possible with PyQtGraph?

There's another solution here that might make more sense: Try adding all of the sub-components of each plot to a single grid. This would ensure that the boundaries all line up automatically. You could, for example, take the AxisItems, ViewBox, and LabelItems from widget 3 and add them into the layout used by widget 1.


Vincent Le Saux

unread,
Jul 6, 2014, 2:51:28 PM7/6/14
to pyqt...@googlegroups.com
This is exactly what I did (using a QGridLayout). However, I had to add a "blank" label over the left axis to make sure the plotItem size of the two widgets are exactly the same. 

I'll test your solution regarding the colorbar size. 

I should be able to provide the source code this week (if someone is interested in of course).

Thanks for your time!

Regards, 

Vincent

Nicholas Tan Jerome

unread,
Oct 17, 2014, 10:15:10 AM10/17/14
to pyqt...@googlegroups.com
I am interested :)

mgele...@gmail.com

unread,
Aug 2, 2016, 10:39:06 AM8/2/16
to pyqtgraph
Hi Vincent,

I'd be really interested to see your code for this if you've still got it!

Cheers,
Michael
Reply all
Reply to author
Forward
0 new messages