PDA

View Full Version : Find the item under the mouse press



sajis997
17th August 2011, 15:08
Hello forum,


I am over-ridden the mousePressEvent(QGraphicsSceneMouseEvent) of the QGraphicsScene and doing the following to find if there is any item under the mouse press or not:





QGraphicsItem *item = itemAt(event->pos());

if(item)
cout << "Item found under the mouse press " << endl;



When i drag the item into the scene i can see that there is an item, the mousePressEvent() is not detecting it. Is there any basic logic that i am missing ?


Thanks
Sajjad

helloworld
17th August 2011, 15:23
Not sure this is the problem but in case you have subclassed QGraphicsItem, make sure that the boundingRect() of your graphics item is correct.

sajis997
17th August 2011, 15:38
Not sure this is the problem but in case you have subclassed QGraphicsItem, make sure that the boundingRect() of your graphics item is correct.


I think the boundingRect() is fine. I am trying to extend the demo that comes along with the Qt installation - diagramscene.
The examples already over-rides the mousePressEvent() and i have just added the condition as mentioned in the previous post at the end of the function.


Any other hint?



Regards
Sajjad

norobro
17th August 2011, 17:50
Use a qDebug() statement:
qDebug() << event->pos()event->pos() is not what you want. Look in the docs for alternatives.


Any other hint?
On what type of object you are calling itemAt()?

sajis997
18th August 2011, 10:50
Use a qDebug() statement:
qDebug() << event->pos()event->pos() is not what you want. Look in the docs for alternatives.


On what type of object you are calling itemAt()?





DiagramItem *item = qgraphicsitem_cast<DiagramItem*>(itemAt(event->pos()));



And the event type is the QGraphicsSceneMouseEvent .

[/code]

norobro
18th August 2011, 13:24
You are trying to locate an item in a scene so try:
QGraphicsItem *item = itemAt(event->scenePos())