tags:

views:

42

answers:

1

I'm trying to use a QGraphicsPathItem to represent a polygon with a hole in it (think doughnut). I can get it to draw correctly, and the center is transparent. However, with item selection or movement turned on, I am able to interact with my object when clicking in the hole. I'd rather treat the hole as not part of the polygon.

I've done some testing, and it appears that QPainterPath::contains() will return true when I check a point within the hole. Will I need to subclass QGraphicsPathItem to implement a more specific contains() function, or is there something else I'm missing?

A: 

If you change the filling rule from default value Qt::OddEvenFill to Qt::WindingFill, can you still see the hole? I guess you'll not be able to see the hole. So the hole is actually not a "physical" hole in your path. If you are going to represent a polygon with a hole, you may need to subclass the QGraphicsPathItem, explicitly define outer most path and holes, and maintain the relationship among paths in different role.

Mason Chang