[Interest] QGraphicsView selection not honoring QGraphicsItem::shape?
Patrick Stinson
patrickkidd at gmail.com
Mon Jun 26 04:57:31 CEST 2017
Thanks for the important tips, I wasn’t aware of any of them! I implemented all of them.
Unfortunately it is still selecting based on boundingRect. Any other thoughts?
> On Jun 25, 2017, at 5:00 PM, Christian Gagneraud <chgans at gmail.com> wrote:
>
> On 26 June 2017 at 05:10, Patrick Stinson <patrickkidd at gmail.com <mailto: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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20170625/77427254/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 1403 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20170625/77427254/attachment.bin>
More information about the Interest
mailing list