View Full Version : how to prevent child QGraphicItem from picking when calling items(path)?

14th March 2013, 23:47
I am implementing picking by calling scene.items(path) where path is a small circle around the pointer. I reimplement shape() to return concentric paths around the true shape, in other words, I am picking only the edge of items.

I have a FramedText class, a QGraphicsItemGroup comprising a rect and text items. I want it to pick by the frame, and not by the text. Is there a way to prevent an item from picking, other than by reimplementing shape() to return a null path?

I have reimplemented shape() for the group to return concentric squarish rings around the edge of the child rect. When the pointer is inside, the group shape() is called, and does not pick, but Qt also calls the child rect shape() , and since I have not reimplemented the rect shape() it does the default, returning the bounding rect, and that does pick. I suppose I just need to reimplement the child rect shape() to return a null path. But is seems ugly to have special classes for non-picking items.

More generally, think of a group as a symbol, in the sense that it comprises many items, but you only want to pick by certain of the items, say the edge of the symbol, or the center of the symbol, or the opaque items of the symbol. Is there a simple way to keep Qt from traversing all the children of a group for the items(path) method?

14th March 2013, 23:50
The simplest solution seems to be to have a list of ignored items and when you traverse the collission list, simply skip items from the ignored list.