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. [SOLVED] QGraphicsView and scale
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] QGraphicsView and scale

Scheduled Pinned Locked Moved General and Desktop
7 Posts 4 Posters 11.8k Views 1 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.
  • A Offline
    A Offline
    Anticross
    wrote on last edited by
    #1

    Graphics view has function scale(qreal,qreal) which scales objects inside it. How to get scale factor of my view ? I found that I cam get transformation matrix using transformation() function, but how can I get factor value using this or maybe other ideas ?

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dakron
      wrote on last edited by
      #2

      QTransform is returned by the QGraphicsView::transform(). Please take a look at QTransform class information, you can find there the description of basic matrix operations and this is what you are looking for.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        Anticross
        wrote on last edited by
        #3

        I mean can I get scaleFactor from this transformation matrix and if yes - how ? I don't need to do any transform operations on this step, I just need to get current scale factor.

        1 Reply Last reply
        0
        • D Offline
          D Offline
          dakron
          wrote on last edited by
          #4

          Yes, you can. The elements m11 and m22 in the matrix operations.

          1 Reply Last reply
          0
          • A Offline
            A Offline
            Anticross
            wrote on last edited by
            #5

            Sorry I found that it's m11 and m22. Thanks,dakron.

            1 Reply Last reply
            0
            • R Offline
              R Offline
              rokemoon
              wrote on last edited by
              #6

              Please mark post as [SOLVED]

              1 Reply Last reply
              0
              • S Offline
                S Offline
                Secundo
                wrote on last edited by
                #7

                I know this topic is quite old, but I want to update the solution. I used the solution from dakron but got weird behavior sometimes.
                m11 for x and m22 for y works only if the view has no rotation applied. If the view is rotated the returned values will be wrong.
                You can calculate the x scale with 'sqrt(trf.m11() * trf.m11() + trf.m12() * trf.m12())' (pythagoras, where trf is the QTransform) and y with 'sqrt(trf.m21() * trf.m21() + trf.m22() * trf.m22())'.

                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