[Interest] QGraphicsView selection not honoring QGraphicsItem::shape?
Christian Gagneraud
chgans at gmail.com
Mon Jun 26 02:00:11 CEST 2017
On 26 June 2017 at 05:10, Patrick Stinson <patrickkidd at gmail.com> wrote:
>
> Hi there!
>
> I have a simple QGraphicsItem which draws the left, bottom, and right borders of it’s bounding rect. I am painting the item by creating a QGraphicsPath from top-left => bottom-left => bottom-right =>? top-right.
>
> I have reimplemented shape() to return this path, but the view is still using the item’s bounding rect to select. I have tested this by dragging my selection marquee down through the top border of the item. I tried re-tracing the QPainterPath back to the beginning in case it was automatically closing it from top-right to top-left, but it didn’t help.
>
> Is there something else that needs to happen to get the view to honor shape()?
>
> See code and screenshot below.
>
> Thanks!
> -Patrick
>
> class Marriage(QGraphicsItem, util.Debug):
>
> def __init__(self, a, b):
> super().__init__()
> global last_id
> self.id = last_id = last_id + 1
> self.setFlag(QGraphicsItem.ItemIsSelectable, True)
> self.path = QPainterPath()
> self.pen = util.PEN
> self.people = [a, b]
> self.children = []
> self.hover = False # highlight
> self.update()
>
> def boundingRect(self):
> return self.shape().boundingRect()
>
> def shape(self):
> return self.path
>
>
>
> def update(self, *args):
BTW, update() is not a virtual method, you should instead implement a
custom function, say updateShape() in which you first call
prepareGeometryChange(). No need to call update().
Chris
More information about the Interest
mailing list