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?
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?