Apologies, the minimum working example had a mistake in it. Here is the 
corrected code:
from <filename> import EllipseItem
pw = pg.PlotWidget()
item = EllipseItem([0,1],[1,0.5])
pw.addItem(item)
item.setRadius([0.5,1])



On Wednesday, 5 August 2020 23:54:29 UTC+2, Magne Lauritzen wrote:
>
> Good day.
>
> I am attempting to rapidly animate an ellipse in the form of a 
> GraphicsObject in a PlotWidget. When the parameters of the ellipse changes, 
> I call the requisite :
>             self.update()
>             self.informViewBoundsChanged()
> However, this appears to only schedule an update of the scene for later. 
> This is not sufficient for me, as I will be rapidly updating the parameters 
> of the GraphicsObject and require update speeds on the same order as 
> PlotDataItem, i.e. near-instantaneous.
>
> Could this perhaps be solved by subclassing an implementation of Viewbox 
> that catches an emitted signal from the GraphicsObject and forces an 
> update? I believe this is how instantaneous updates of PlotDataItem is 
> achieved, through the sigPlotChanged signal.
>
> Anyways, the following is the class definition for the custom ellipse 
> GraphicsObject. 
> class EllipseItem(pg.GraphicsObject):
>     def __init__(self, center:Union[float,List[float]], 
> radius:Union[float,List[float]]):
>         pg.GraphicsObject.__init__(self)
>         self.center = None
>         self.radius = None
>         self.setCenter(center)
>         self.setRadius(radius)
>     
>     def setCenter(self,center:Union[float,List[float]]):
>         self.center = center
>         self.generatePicture()
>         
>     def setRadius(self,radius:Union[float,List[float]]):
>         self.radius = radius
>         self.generatePicture()
>         
>     def generatePicture(self):
>         if self.center is not None and self.radius is not None:
>             self.picture = QtGui.QPicture()
>             p = QtGui.QPainter(self.picture)
>             p.setPen(pg.mkPen('w'))
>             try:
>                 r1 = self.radius[0]
>                 r2 = self.radius[1]
>             except (TypeError, IndexError):
>                 r1 = r2 = self.radius
>             try:
>                 c1 = self.center[0] - r1
>                 c2 = self.center[1] - r2
>             except (TypeError, IndexError):
>                 c1 = self.center - r1
>                 c2 = self.center - r2            
>             p.drawEllipse(QtCore.QRectF(c1,c2,r1*2,r2*2))
>             p.end()
>             self.update()
>             self.informViewBoundsChanged()
>       
>     def paint(self, p, *args):
>         p.drawPicture(0, 0, self.picture)
>
>     def boundingRect(self):
>         return QtCore.QRectF(self.picture.boundingRect())
>
> The following is a minimal working example showing that update is not 
> immediate. Note the delay between updating the radius of the Ellipse and 
> the change becoming apparent in the PlotWindow.
>
> from <filename> import EllipseItem
> pw = pg.PlotWidget()
> item = EllipseItem([0,1],[1,0.5])
> plotui.addItem(item)
> item.setRadius([0.5,1])
>
>
> Regards,
> Magne Lauritzen
>
>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/pyqtgraph/42dce521-8c1a-4de3-9c25-8c466128817bo%40googlegroups.com.

Reply via email to