I am adding items on a QGraphicsScene
. Once added, items may be further processed.
I would like to skip the items completely obscured by other items. It seems that there are several QGraphicsItems
dedicated to this task.
Given two QGraphicsItem
objects, in the shape of a rectangle, identical in size, only differing by color, and each with identical boundingRect()
, each at exactly the same pos()
, but with different zValue()
:
for(int i = 0; i < scene.items().size(); ++i)
{
if(scene.items().at(i)->isObscured())
{
continue;
}
// do work
}
I also tried
if(scene->items().at(i)->isObscured(scene->items().at(i)->boundingRect()))
Neither option skips the item that is not visible.
If I increase slightly the size of the rectangle on top, the isObscured
function works (either version). But with identical shapes, one on top of the other, logically the bottom one would still be obscured...
Would a reasonable fix be to add 1 pixel on each side of the rectangle ? would that not lead to weird situations ?
How can I make items that are covered be skipped ?
This issue is even more complicated if one item is covered by several other items, neither of them fully covering the item.