How to use Imageview to display only an image and ROI points

2,307 views
Skip to first unread message

Guillermo Parada

unread,
May 20, 2013, 3:02:28 PM5/20/13
to pyqt...@googlegroups.com
Hi, i'm a new user of pyqtgraph and i'm trying to load an image into a imageview widget and then some ROIs, how can i hide the sidebar and the ROI and norm buttons, there is another widget to load an image and ROI points?
Thanks

Luke Campagnola

unread,
May 20, 2013, 4:33:19 PM5/20/13
to pyqt...@googlegroups.com
On Mon, May 20, 2013 at 3:02 PM, Guillermo Parada <gin...@gmail.com> wrote:
Hi, i'm a new user of pyqtgraph and i'm trying to load an image into a imageview widget and then some ROIs, how can i hide the sidebar and the ROI and norm buttons, there is another widget to load an image and ROI points?
Thanks


If you don't need any of ImageView's features,  you can just put together a ViewBox with an ImageItem inside it. See pyqtgraph/examples/ROIExamples.py -- the top-left panel in this example has an ImageItem and several ROIs inside a ViewBox. Is that what you're looking for?

Luke


Guillermo Parada

unread,
May 20, 2013, 6:01:36 PM5/20/13
to pyqt...@googlegroups.com
Thanks for your quick reply, yes i just found the example, yes is something like that, if can ask you another question, i'm using qt-designer, and in my gui i add the QtgraphicsView widget, how can i make that work with viewbox, because, if i try to add the layout or directly the addviewbox to the widget i receive
error like this : AttributeError: 'GraphicsView' object has no attribute 'addViewBox', how can i set the widget correctly?
Also how can i get the position of a roi point?, using getLocalHandlePositions() i get nothing (using it with imageview)

Thanks.

Luke Campagnola

unread,
May 20, 2013, 6:27:14 PM5/20/13
to pyqt...@googlegroups.com
On Mon, May 20, 2013 at 6:01 PM, Guillermo Parada <gin...@gmail.com> wrote:
Thanks for your quick reply, yes i just found the example, yes is something like that, if can ask you another question, i'm using qt-designer, and in my gui i add the QtgraphicsView widget, how can i make that work with viewbox, because, if i try to add the layout or directly the addviewbox to the widget i receive
error like this : AttributeError: 'GraphicsView' object has no attribute 'addViewBox', how can i set the widget correctly?

addViewBox is a method of GraphicsLayoutWidget, not GraphicsView. 
 
Also how can i get the position of a roi point?, using getLocalHandlePositions() i get nothing (using it with imageview)

getLocalHandlePositions gives you the position of handles relative to the ROI itself, so this is probably not much use to you. You can probably use roi.size() and roi.pos() for rectangular ROIs, or roi.getSceneHandlePositions() for other shapes.


Luke


Guillermo Parada

unread,
May 22, 2013, 5:59:05 AM5/22/13
to pyqt...@googlegroups.com
Thanks for your reply, was really helpful. There is a more complete documentation that the one on the website?

Guillermo Parada

unread,
May 22, 2013, 6:02:27 AM5/22/13
to pyqt...@googlegroups.com
i'm trying to update some label when the ROI change the position, but stateChanged doesn't work, there is another way?

Guillermo Parada

unread,
May 22, 2013, 6:44:19 AM5/22/13
to pyqt...@googlegroups.com

What kinf of data return roi.pos(), how can i separate the X and Y into two variables?.

Luke Campagnola

unread,
May 22, 2013, 7:24:35 AM5/22/13
to pyqt...@googlegroups.com
On Wed, May 22, 2013 at 5:59 AM, Guillermo Parada <gin...@gmail.com> wrote:
Thanks for your reply, was really helpful. There is a more complete documentation that the one on the website?


No. Unfortunately, the documentation still has a few holes in it. For questions about signals and class members that are not documented, often the best place to look is the source code for each class. As always, I am happy to answer questions here and fill in documentation as needed.

Luke


Luke Campagnola

unread,
May 22, 2013, 7:34:46 AM5/22/13
to pyqt...@googlegroups.com
On Wed, May 22, 2013 at 6:44 AM, Guillermo Parada <gin...@gmail.com> wrote:

What kinf of data return roi.pos(), how can i separate the X and Y into two variables?.

This method returns a Point instance, which is a subclass of QPoint: 

Luke Campagnola

unread,
May 22, 2013, 7:36:39 AM5/22/13
to pyqt...@googlegroups.com
On Wed, May 22, 2013 at 6:02 AM, Guillermo Parada <gin...@gmail.com> wrote:
i'm trying to update some label when the ROI change the position, but stateChanged doesn't work, there is another way?

Here is the documentation I am adding about ROI signals:

    Signals
    ----------------------- ----------------------------------------------------
    sigRegionChangeFinished Emitted when the user stops dragging the ROI (or
                            one of its handles) or if the ROI is changed
                            programatically.
    sigRegionChangeStarted  Emitted when the user starts dragging the ROI (or
                            one of its handles).
    sigRegionChanged        Emitted any time the position of the ROI changes,
                            including while it is being dragged by the user.
    sigHoverEvent           Emitted when the mouse hovers over the ROI.
    sigClicked              Emitted when the user clicks on the ROI
    sigRemoveRequested      Emitted when the user selects 'remove' from the 
                            ROI's context menu (if available).
    ----------------------- ----------------------------------------------------

Guillermo Parada

unread,
May 22, 2013, 4:42:43 PM5/22/13
to pyqt...@googlegroups.com

Thanks, is this the right way to capture the signal?
        QtCore.QObject.connect([myroi], QtCore.SIGNAL("sigRegionChangeFinished()"), [my_function])

Luke Campagnola

unread,
May 22, 2013, 6:06:16 PM5/22/13
to pyqt...@googlegroups.com
On Wed, May 22, 2013 at 4:42 PM, Guillermo Parada <gin...@gmail.com> wrote:

Thanks, is this the right way to capture the signal?
        QtCore.QObject.connect([myroi], QtCore.SIGNAL("sigRegionChangeFinished()"), [my_function])



So the correct code looks like this:

    myroi.sigRegionChangeFinished.connect(my_function)

Guillermo Parada

unread,
May 23, 2013, 11:54:46 AM5/23/13
to pyqt...@googlegroups.com
Works perfectly!! Thanks
There is any ROI related feature to add a visible label to a ROI?
How can i set the movable property to False after i created the ROI?

Luke Campagnola

unread,
May 23, 2013, 5:06:45 PM5/23/13
to pyqt...@googlegroups.com
On Thu, May 23, 2013 at 11:54 AM, Guillermo Parada <gin...@gmail.com> wrote:
There is any ROI related feature to add a visible label to a ROI?

There is not, but you can always make a TextItem as a child of the ROI to achieve this effect.
 
How can i set the movable property to False after i created the ROI?

You can set this:
    roi.translatable = False
But note that this only affects dragging the ROI itself; handles will be unaffected.


Luke

bruno.ba...@gmail.com

unread,
Nov 14, 2018, 7:23:41 AM11/14/18
to pyqtgraph

class LabelledROI(ROI):
    """
    Normal ROI with a label attached.
    
    
    ============== =============================================================
    **Arguments**
    label          String for the label 
    \**args        All extra keyword arguments are passed to ROI()
    ============== =============================================================
    
    """
    def __init__(self, *args, label=None, **kwargs):
        ROI.__init__(self, *args, **kwargs)
        if label is not None:
            self.label = QtGui.QGraphicsTextItem(label, self)         
            self.label.setPos(QtCore.QPointF( self.boundingRect().center().x() - (self.label.boundingRect().width()/2),  self.state['size'][1] ))   
        else:
            self.label = None
        
            
    def paint(self, p, opt, widget):
        """ p es un objeto QPainter """
        super().paint(p, opt, widget)
        if self.label is not None:
            self.label.setPos(QtCore.QPointF( self.boundingRect().center().x() - (self.label.boundingRect().width()/2),  self.state['size'][1] ))           

Tim Williams

unread,
Jun 7, 2019, 7:13:09 PM6/7/19
to pyqtgraph
Thanks so much for  posting this! I was just wondering today about how to do this.
Reply all
Reply to author
Forward
0 new messages