QTransform no simple call to just set scale?

  • I am using a graphics view, and simply want to set the scale (only that, everything else untouched) to some absolute number, not a relative delta from where it is now.

    QTransform::scale(qreal sx, qreal sy) scales from where the current transform is presently, e.g. each time you pass in 2.0 it doubles in size (1.0 -> 2.0 -> 4.0 -> 8.0 ...). I call that a "delta" scaling, it is a relative change in scale. So that will not work to set the scale to an absolute number like, say, 2.0.

    I can read the current absolute scale from m11() & m22(), but there is no setm11/setm22(). So the only way I can see is:

    t = graphicsView.transform()
    t2 = QTransform(2.0, t.m12(), t.m13(), t.m21(), 2.0, t.m23(), t.m31(), t.m32(), t.m33())

    That seems like a lot of typing in the long line (I allowed variable to be named t in the example, it will be longer than that!) to just set two of the values! Am I missing something neater? (I am totally new to graphics/scaling/transforms, so don't expect any knowledge from me!)

  • Lifetime Qt Champion


    Likely not ideal but based on the basic matrix operation, it looks like you should keep one transformation per type and then calculate the final one.

  • @SGaist
    Thank you for replying. Sometimes your answers are cryptic to me :) I have read that doc section, and still don't know what you mean.

    My goal is to reset the zoom level, in a standalone function which knows nothing else about the state the current graphics transform might or might not be in. I have a feeling you are implying I am responsible for tracking other, non-zoom-scale settings separately in code, which is not my responsibility, but I'm not sure if that's what you have in mind? :)

    Anyway, if the answer does indeed seem to be "yes, there is no simple call to set just m11/m22 absolutely, you might as well do it with all the parameters to QTransform() as you showed", which is where I am at the moment, that's fine, at least I know!

  • Lifetime Qt Champion

    The example shows three QTransform objects, one per transformation type, that are combined before being applied.

    What I was suggesting would be to keep this idea of one QTransform per modification type and combine them when needed so you can more freely modify their parameters.

Log in to reply