PDA

View Full Version : QGraphicsView::itemAt() always returns zero



tuli
25th September 2013, 18:13
So i created a few MyItem instances and addItem()ed then to my custom QGraphicsView. This works perfectly, and the widgets show up just fine.
However, the scene()->itemAt(...) functions returns always zero, when given the coordinates obtained from a QMouseEvent.



class MyItem: public QGraphicsProxyWidget
{
MyItem() {
setWidget(new SomeWidget());
}
//...
};


void MyQGraphicsView::mousePressEvent( QMouseEvent *event )
{
QGraphicsItem* itm = scene()->itemAt(event->pos()); //nope
itm = scene()->itemAt(event->pos(), transform()); //nope
}




Now, i am still struggling with understanding all the transformation stuff :/, but to my understanding, nothing of that sort should be necessary here? Unfortunately, this seems to be a rarely used function, and i cant seem to find any proper examples.


Do i have to apply some magic to the coordinates before passing them to the function? What else could be wrong?

wysota
25th September 2013, 18:26
The coordinates are in viewport's coordinate space. You need to map that to the scene first.

tuli
25th September 2013, 19:36
i really need to do more reading on all this. thanks.