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?
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?
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.
<=== The Great Pumpkin says ===>
Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.
Thanks d_stranz.
I have found a good solution.
If CustomItem subclasses QGraphicsEllipseItem it works perfectly.
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...
<=== The Great Pumpkin says ===>
Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.
Bookmarks