PDA

View Full Version : Where to apply transform? iterm or QPainter?



lni
29th January 2009, 02:48
Hi,

I need to plot a curve within a rectangle, the min/max of curve data will be mapped to the edge of the rectangle. In doing so, I create a QTransform, which is

QTransform xf;
xf.scale( rect_width / ( curveMax - curveMin ), 1 ); // assuming no scaling in Y
xf.translate( -curveMax, 0 ); // assuming no translation in Y, but really, should I scale first, or translate first?

After creating the transform, where do I need to set it to? The QPainter inside paint() method or the GraphicsCurveItem itself?

I first set it to QPainter, and then change to set it to GraphicsCurveItem. In theory, they should not be any difference as the curve has no children. However, one of them caused GraphicsCurveItem's parent's sibling to be drawn in a wrong place (it appears to draw the scene more than once too), but if I resize the view, it redraws the things in the right place...

Any idea? Thanks

wysota
29th January 2009, 08:40
The item should always draw itself the same way regardless of what the actual output will look like, so based on that it's safe to assume you should apply the transformation on the item. Scale the item so that it fits the rectangle you want and then move it into position.