[Qt-interest] QGraphicsScene pos

velociraptor Genjix aphidia at hotmail.com
Tue Oct 26 11:35:39 CEST 2010


Yes, your scene goes from -50,-50 to 50,50.

Image your scene is a 2D world. You can define any rectangle on that world with whatever you want. If I place an object at -10,-20 and another object at 2,80 then my world extends from -10,20 to the bottom corner of the object at 2,80.

Now the view is like the camera onto this world- how it appears if you took a photograph of the world. I might take a photograph of the section from 10,10 to 20,30 and the world would appear zoomed in. But the photograph (view) != world (scene)

________________________________
> Date: Tue, 26 Oct 2010 11:28:20 +0200
> From: pmqt71 at gmail.com
> To: sean.harmer at maps-technology.com
> CC: qt-interest at trolltech.com
> Subject: Re: [Qt-interest] QGraphicsScene pos
>
> Ok, thanks a lot.
>
> I actually was expecting this behaviour without calling any fitInView method.
>
> Just another question:
>
> I have the QRectF -50.0, -50.0, 50.0, 50.0
>
> the width is 50??
>
> qDebug() << "width=" << rect.width(); //returns 50
>
>
>
>
> thanks
> pm
>
>
>
>
>
> 2010/10/26 Sean Harmer
> >
> 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
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
>
> _______________________________________________ Qt-interest mailing
> list Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
 		 	   		  



More information about the Qt-interest-old mailing list