PDA

View Full Version : qgraphicsview and coordinates



mcarter
7th September 2013, 02:37
I am trying to use a qgraphicsview as part of a plotting app. There are two graphs, one above the other that are aligned with the x-axis extents. I have axes around a center widget, in the lower instance it uses a simple qwidget and in upper, it uses a qgraphicsview.

My problem comes in lining up the axes extents to the extents inside of the qgraphicsview. For example, my X-axis runs from 2000000 to 30000000 and my Y-axis from 3600 to 90000. I call setSceneRect with these values and then call a modified fitInView (modified to remove the hard-coded margin of 2 adjustment). The sceneRect shows the proper (2000000,3600 28000000x86400). However, if I try to do mapToScene( QPoint(0,0) ), I do not get (2000000,3600) that I expect but values slightly off (1971830.985915, 3578.698225), so qgraphicsview does not quite line up with values of the axes. If I put a qgraphicslineitem vertically at 20000000, it does not draw in the proper location wrt x-axis. I know this seems negligible but with a crosshair cursor that displays the x,y values with the cursor position based on the axis, it just looks wrong. And it does not line up with a similar vertical line and similar crosshair cursor in the qwidget that uses transform routines based on the axes.

Is there a way to tweak the matrix/transform so the qgraphicsview coordinates match closer to my axis scaling?

amleto
7th September 2013, 02:42
why are you making your own plotting app? there is already qwt.

btw, it will be your maths/mapping that is making something not quite match. Trying to fudge it with a Qt transform will just move the error somewhere else.

mcarter
8th September 2013, 17:09
why are you making your own plotting app? there is already qwt.
It is an app at work that is unique to the data set.


btw, it will be your maths/mapping that is making something not quite match. Trying to fudge it with a Qt transform will just move the error somewhere else.
The qwidget plotting canvas is controlled by the x/y axes . . . simple math to get the mapping. I assumed setting the same x/y ratios in the qgraphicsview would use the same scaling. I guess the fit in view is not producing the affect I expect. The initial setting seems to set the view outside my initial screenRect. How do I set the qgraphicsview to a specific X,Y WxH? Specific meaning that the viewport (0,0) = X,Y and viewport (xmax,ymax) = X+W,Y+H

I know that pixel on the screen can take on a number of values depending on the resolution of the widget. I just want to be able to specific what those "real" values are for the left,right and top,bottom edges of the qgraphicsview like I do with the qwidget.