View Full Version : interactive design

9th September 2016, 13:51
I have a CustomItem that subclasses QGraphicsItem and draw a pie slice with

painter->drawPie(rect, 0, 45 * 16);

Now I want to handle the mouse click event only when the mouse is over the slice, not over the boundingRect.
How can I do it?

9th September 2016, 17:04
Implement the QGraphicsItem::contains() method for your custom item. When you receive a mouse click, check for the point using that method.

You may not have to actually handle the mouse click - if the QGraphicsItem calls the "contains" method internally, then all you may have to do is to implement it correctly.

10th September 2016, 12:03
Thanks d_stranz.
I have found a good solution.
If CustomItem subclasses QGraphicsEllipseItem it works perfectly.

10th September 2016, 19:42
Yes, because your CustomItem class is essentially the same as a QGraphicsEllipseItem that uses a span (i.e. pie slice). Unless your custom class does something special, I don't see any need for it; just use QGraphicsEllipseItem. Notice that QGraphicsEllipseItem reimplements the contains() method...