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. mapToScene equivalent for a scaled QImage?
Forum Updated to NodeBB v4.3 + New Features

mapToScene equivalent for a scaled QImage?

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 3 Posters 2.1k 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.
  • P Offline
    P Offline
    Pippin
    wrote on last edited by
    #1

    Hello,

    I have a QImage that has a rectangle inside. After scaling it, I would like to know the coordinates of the scaled rectangle in the new, scaled QImage. Is there an easy way to achieve this?

    Thanks a lot.

    raven-worxR 1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      well, how do you
      know the coordinates of the original rectangle ?

      Im not sure i 100% understand. you have an image, where inside
      a rect is DRAWN ?
      then you scale the whole image
      and this drawn rect is also scaled with whole image?
      and then you want to find the corrdinates?
      inside the image?

      1 Reply Last reply
      0
      • P Offline
        P Offline
        Pippin
        wrote on last edited by
        #3

        @mrjj exactly. There's a rectangle at position (x, y), whose size is (w, h) and I would like to know the new position (x', y') as well as its new size (w', h')

        mrjjM 1 Reply Last reply
        0
        • P Pippin

          @mrjj exactly. There's a rectangle at position (x, y), whose size is (w, h) and I would like to know the new position (x', y') as well as its new size (w', h')

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Pippin

          Ok:)
          But do u even have the original coordinates of the rect?
          before scale?

          P 1 Reply Last reply
          0
          • mrjjM mrjj

            @Pippin

            Ok:)
            But do u even have the original coordinates of the rect?
            before scale?

            P Offline
            P Offline
            Pippin
            wrote on last edited by
            #5

            @mrjj Yes. I think I'm going to go with x' = scale_x*x, y' = scale_y*y, w' = scale_x*w and h' = scale_y*h but I'd rather Qt did it for me. This way I'd be sure there's no mistake.

            mrjjM 1 Reply Last reply
            1
            • P Pippin

              @mrjj Yes. I think I'm going to go with x' = scale_x*x, y' = scale_y*y, w' = scale_x*w and h' = scale_y*h but I'd rather Qt did it for me. This way I'd be sure there's no mistake.

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @Pippin
              Well since its drawn inside othe image, not sure about any good Qt way :)

              1 Reply Last reply
              0
              • P Pippin

                Hello,

                I have a QImage that has a rectangle inside. After scaling it, I would like to know the coordinates of the scaled rectangle in the new, scaled QImage. Is there an easy way to achieve this?

                Thanks a lot.

                raven-worxR Offline
                raven-worxR Offline
                raven-worx
                Moderators
                wrote on last edited by raven-worx
                #7

                @Pippin

                QTransform matrix = QTransform().scale(0.5, 0.5);
                QImage scaledImg = img.transformed( matrix, Qt::SmoothTransformation );
                QRect scaledRect = matrix.mapRect( originRect );
                

                (untested)

                --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                If you have a question please use the forum so others can benefit from the solution in the future

                mrjjM 1 Reply Last reply
                2
                • raven-worxR raven-worx

                  @Pippin

                  QTransform matrix = QTransform().scale(0.5, 0.5);
                  QImage scaledImg = img.transformed( matrix, Qt::SmoothTransformation );
                  QRect scaledRect = matrix.mapRect( originRect );
                  

                  (untested)

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @raven-worx
                  oh, i read the question as having a smaller drawn rect inside image. :)

                  1 Reply Last reply
                  0
                  • P Offline
                    P Offline
                    Pippin
                    wrote on last edited by
                    #9

                    Thanks to both of you :-)

                    1 Reply Last reply
                    0

                    • Login

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