Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. [Solved] preserve original aspect ratio on Image

[Solved] preserve original aspect ratio on Image

Scheduled Pinned Locked Moved QML and Qt Quick
10 Posts 2 Posters 7.7k Views
  • 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.
  • 2 Offline
    2 Offline
    2beers
    wrote on last edited by
    #1

    Hi everyone. I have an Image element and I want to change the with of the image and the height to be scaled automatically to preserve original aspect ratio. Can I do this without created a special function?

    Thanks

    1 Reply Last reply
    0
    • T Offline
      T Offline
      tony
      wrote on last edited by
      #2

      Hi,

      you can scale a QPixmap or a QImage using the "scaled" method and Qt::KeepAspectRatio option.

      Tony.

      1 Reply Last reply
      0
      • T Offline
        T Offline
        tony
        wrote on last edited by
        #3

        Oops, this is Qt Quick section ... well, I don't know :)

        1 Reply Last reply
        0
        • ? This user is from outside of this forum
          ? This user is from outside of this forum
          Guest
          wrote on last edited by
          #4

          Have you seen the imageelements declarative example that ships with Qt ? Is that what you are looking for ?

          1 Reply Last reply
          0
          • 2 Offline
            2 Offline
            2beers
            wrote on last edited by
            #5

            you mean : "Image element":http://doc.qt.nokia.com/4.7/qml-image.html ?

            Yes I was looking at that, and I'm interested in the fillMode property however:
            "Set this property to define what happens when the image set for the item is smaller than the size of the item."

            And I'm interested in the situation when the picture is larger than the size of item

            1 Reply Last reply
            0
            • ? This user is from outside of this forum
              ? This user is from outside of this forum
              Guest
              wrote on last edited by
              #6

              [quote author="2beers" date="1289119699"]And I'm interested in the situation when the picture is larger than the size of item[/quote]

              I just tried setting a larger image (640x340) in a 200x200 image element and the PreserveAspectFit worked just fine.

              1 Reply Last reply
              0
              • 2 Offline
                2 Offline
                2beers
                wrote on last edited by
                #7

                [quote author="chetankjain" date="1289192635"]

                I just tried setting a larger image (640x340) in a 200x200 image element and the PreserveAspectFit worked just fine.
                [/quote]

                can you post your example please, in mine it doesn't. I'm using qt 4.7.0 . Are you using a different version?

                1 Reply Last reply
                0
                • ? This user is from outside of this forum
                  ? This user is from outside of this forum
                  Guest
                  wrote on last edited by
                  #8

                  yup I'm on 4.7.0. In the same Image Element example, you can try to replace the small smiley they are using with a much larger image... that test case would do ? (see ImageCell.qml)

                  then you can resize the window and chk how the various image modes work.

                  1 Reply Last reply
                  0
                  • 2 Offline
                    2 Offline
                    2beers
                    wrote on last edited by
                    #9

                    Thanks. now it seems that is working. I don't know what I did that it didn't work the first time :))

                    1 Reply Last reply
                    0
                    • ? This user is from outside of this forum
                      ? This user is from outside of this forum
                      Guest
                      wrote on last edited by
                      #10

                      2 beers and cheers to u 2beers :p
                      glad it worked :)

                      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