Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QTransform no simple call to just set scale?
Qt 6.11 is out! See what's new in the release blog

QTransform no simple call to just set scale?

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 1.2k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • JonBJ Online
    JonBJ Online
    JonB
    wrote on last edited by JonB
    #1

    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())
    graphicsView.setTransform(t2)
    

    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!)

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      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.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      JonBJ 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        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.

        JonBJ Online
        JonBJ Online
        JonB
        wrote on last edited by JonB
        #3

        @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!

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved