PDA

View Full Version : Independent scaling behavior for QGraphicsItems



avant
30th May 2010, 19:43
I am writing a program to display and export specialized graph data. The graphs are fairly non-standard, so I suspect that Qwt is not an option. As a result, I want to be able to draw these graphs myself.

The problem is that I need to be able to do a selection zoom (QRubberBand) on an area, scaling the graph elements in that area, but leaving the axes exactly where they are and simply redraw the axis labels accordingly. I assume that I cannot use QGraphicsView's scaling, as I don't want scrollbars. So the scene must be redrawn whenever zooming occurs.

What is the best way to ensure that each item will be redrawn according to the new zoom level? Do I group items with the same behavior? Do I write a specialized QGraphicsScene class to handle the scaling of each item?

I can't find any good examples to get started with, so any help would be appreciated.

tbscope
30th May 2010, 20:11
Attached is a picture.

On the left, you select a part of the chart (or graph, in green) with a rubberband (in grey).
The actual size of the canvas that displays your axes (in black) and chart remains the same (see the chart on the right).
What you do is calculate where the rubberband intersects the chart (see orange points on the left and the right) and redraw the chart in the bounding box of the chart canvas (using control points, see orange points) and adjust the scale on the axes (redraw them).

So, you basically provide a chart canvas, consisting of axes and an actual chart (all seperate objects).
The use a rubber band on your canvas. Calculate the intersections with your actual chart. Resize your actual chart within the canvas (as in redraw within the bounding box, don't draw outside of it) and adjust the axes.

Is this clear enough?
There might be other ways too of course.