PDA

View Full Version : Order of elemetns with QGraphicsScene::itemAt



Morea
25th November 2006, 11:31
Hi.
If there are several items at a point, the item that will be returned with the QGraphicsScene::itemAt function will be the one with the highest zValue, right?
But what if there is two QGraphicsItems, call them A and B where A is parent to B and B has lower zValue, which one will be returned?

In this situation I would really like B to be returned, if itemAt does not do this, how do you do it then?

jacek
25th November 2006, 13:28
You could try to use item( const QPointF & ) method to get all items at that position and then something like this:

QGraphicsItem *item = items.first();
foreach( QGraphicsItem *tmpItem, items ) {
if( tmpItem->parentItem() == item ) {
item = tmpItem;
}
}

Bitto
20th December 2006, 21:00
See the docs for QGraphicsItem::zValue(), it's explained in detail there. Children are always on top of parents, and because of this, children are always listed before parents in the itemAt() and items() functions.

http://doc.trolltech.com/4.2/qgraphicsitem.html#setZValue