When you know how to do it then you may do it wrong.
When you don't know how to do it then it is not that you may do it wrong but you may not do it right.
Thank you very much, you opened my eyes. Now I realise, that I have focused too much on solving it from the other side, I was looking for a way to get the item boundingbox center coordinates to translate to global coordinates(btw how would I do that?, I didn't find a matching map to global function). But of course, for my needs there is no difference if global or scene corrdinates, they just have to match! Thank you!
QGraphcisScene coordinates connot be directly mapped to screen coordinates, as the on screen position of QGraphicsScene is taken care by QGraphicsView. So to get the screen coridinates of a point you have convert the point to QGraphicsSecen coordinates and then to screen codinates using the QGraphicsView which is displaying the QGraphicsScene.
Qt Code:
view->setScene(scene); scene->addItem(item); QPointF point; point = item->boundingRect().center(); point = item->mapToScene(point); point = view->mapFromScene(point);To copy to clipboard, switch view to plain text mode
Note that without having a view there is no sense for screen/viewport/global coordinates.
Last edited by Santosh Reddy; 8th November 2012 at 07:48.
When you know how to do it then you may do it wrong.
When you don't know how to do it then it is not that you may do it wrong but you may not do it right.
AndyQT (8th November 2012)
Thank you very much for the detailed explanation. It seems so logical when you see it.
And of course, in my case I should also stick to the scene coordinates, so I don't need to care about the window position. In fact, all my problem started by choosing the wrong source for cursor position - QCursor:os() instead of the cursor scenePos supplied by the mouse event. I simply took what google gave me first :-(.
Now everything is OK!
Bookmarks