ROI does not refresh correctly

62 views
Skip to first unread message

yunsong zhao

unread,
Mar 10, 2020, 3:48:34 PM3/10/20
to pyqtgraph
Hi there, 

I get a problem when using the ROI.
If I set the width of the ROI's pen bigger than 1, it does not refresh correctly when moved, as is shown in the following image .
img.png










To get the image, I modified the image analysis example as follows:

roi = pg.ROI([-8, 14], [6, 5])
roi.addScaleHandle([
0.5, 1], [0.5, 0.5])
roi.addScaleHandle([
0, 0.5], [0.5, 0.5])
roi.setPen("r", width=10) # I added this line
p1.addItem(roi)
roi.setZValue(10

Thanks!

Patrick

unread,
Mar 10, 2020, 10:52:22 PM3/10/20
to pyqtgraph
Hi,

Looks like there is a bug there. The calculated bounding rectangles (used by the GraphicsView system for repaints etc) aren't taking into account the line width.
If you edit the boundingRect method of ROI.py to be:
    def boundingRect(self):
        pw
= 0.5*self.currentPen.width()
       
return QtCore.QRectF(-0.5*pw, -0.5*pw, pw+self.state['size'][0], pw+self.state['size'][1])
then it seems to work. Unfortunately, you'll also need to modify any other ROI subclass (PolyLineROI etc) which override boundingRect() in a similar manner.

Patrick

Kenneth Lyons

unread,
Mar 12, 2020, 11:25:40 PM3/12/20
to pyqtgraph
This indeed looks like a bug. I created an issue for this if anyone wants to keep track of progress on fixing it:

Nathan Jessurun

unread,
Jun 15, 2020, 2:30:49 AM6/15/20
to pyqtgraph
@Patrick beware -- Your solution is great when an ROI updates normally. Keep in mind though that you can drag a rectangle handle "backwards" through the top-left corner of the shape (such that what once was the top-left corner becomes the bottom right), in which case the bounding sizes are negative. When this happens, artifacts remain.
Reply all
Reply to author
Forward
0 new messages