[Qt-interest] QGraphicsScene pos
Sean Harmer
sean.harmer at maps-technology.com
Tue Oct 26 09:59:17 CEST 2010
Hi,
> myScene->setSceneRect( -50.0, -50.0, 50.0, 50.0 );
> on the following event handler, I want the x and y within the scene rect.
> void MyGraphicsScene::mouseDoubleClickEvent ( QGraphicsSceneMouseEvent *
> mouseEvent)
> {
> QRectF rect = sceneRect(); //this gives -50.0, -50.0, 50.0, 50.0
>
> //but the following returns something out of the sceneRect - e.g. 106,
> -91 double-clicking in the top right corner
>
> QPointF pointScene = mouseEvent->lastScenePos ();
>
> // is it a view related point?
> QPointF point = this->views()[0]->mapToScene(pointScene.toPoint()); //
> but this returns -51, -183
> }
>
> The QGraphicsView is added into a layout and the mainWindow is resizable,
> so the size of the widget is not fixed.
By default the scene is displayed in the view at a scale of 1.0. So if your
view's viewport is larger than 100x100 pixels then it will be displaying
regions outside of your scenerect so the above code and results looks feasible
to me.
If you want your scene to fill your view you will need to call
QGraphicsScene::fitInView() to change the view transformation before you start
double-clicking.
This type of thing is much easier to visualise if you add a small rect at each
corner of your scene rect for example.
HTH,
Sean
>
>
>
> thanks
>
> pm
More information about the Qt-interest-old
mailing list