QMatrix vs QTransform
-
Hello,
Currently I'm porting and cleaning old code from my application.
As QMatrix is already deprecated, I want to replace it using the
QTransform class.This is a little example about what I'm planning:
@
// Old code
QMatrix m;
m.translate(point.x(), point.y());
m.scale(-1.0, 1.0);
m.translate(-point.x(), -point.y());
item->setMatrix(m, true);
@@
// New code
QTransform transform;
transform.translate(point.x(), point.y());
transform.scale(-1.0, 1.0);
transform.translate(-point.x(), -point.y());
item->setTransform(transform);
@I would like to read about previous experiences doing this
kind of operations. Suggestions? recommendations?Thanks!
-
In the end both are matrices.
-
Well, I started to replace the code and in some points the "usual" behavior is not the same. I guess I will have to spend some time dealing with this.
Theoretically both are matrices... but in practice and after my first try I'm not so sure at all :P
-
And where is the different behavior?
I am looking at the documentation and I can see only one difference betweet this two.
QMatrix has m11, m12, 0, m21, m22, 0, dx, dy, 1.
QTransform is m11, m12, m13, m21, m22, m23, m31, m32, m33.Notice the difference, in the QMatrix m13 and m23 are always 0. These members are used when doing projection.
So, final, with QMatrix you can't define projection transformation.
-
As feature of my app, I wrote a plugin to allow scaling for QGraphicsItems using mouse events. With QMatrix the transformation looks smooth. When I tried to use QTransform (as in my first post), the effect was ugly (slow, discontinuous). I guess I'm missing something.
In case you want to see something, here is the code (working with QMatrix for now):
http://gitorious.org/tupi/tupi/trees/master/src/plugins/tools/selecttoolGoing to the point (line 177):
http://gitorious.org/tupi/tupi/blobs/master/src/plugins/tools/selecttool/nodemanager.cppAny advice is very welcome.
-
I think it's time for bug report. I don't see why there is performance problems with scaling.