Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved Knowing if an image is portrait or landscape oriented (QmlImage)

    QML and Qt Quick
    2
    7
    171
    Loading More Posts
    • 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.
    • M
      Moisi last edited by

      Hi, ^^

      Is there a way to know if an image is portrait or landscape ?

      Something like:

      Image {
          source: "some/path/myImage.svg"
          property bool isPortrait: implicitHeight > implicitWidth // Cause a binding loop, so it's not a solution
          sourceSize.width: isPortrait ? 0 : 150 // The reason why I want to know the myImage orientation
          sourceSize.height: isPortrait ? 150 : 0 // The reason why I want to know the myImage orientation
      }
      

      Thanks a lot ^^

      KroMignon 1 Reply Last reply Reply Quote 0
      • KroMignon
        KroMignon @Moisi last edited by

        @Moisi said in Knowing if an image is portrait or landscape oriented (QmlImage):

        There is something I do not understand. Setting the width/height properties makes my images pixellated...

        Okay, perhaps like this, it is better:

        Image {
            source: "some/path/myImage.svg"
            readonly property bool isPortrait: height > width
            fillMode: Image.PreserveAspectFit
            sourceSize: Qt.size(150, 150)
        }
        

        It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

        1 Reply Last reply Reply Quote 1
        • KroMignon
          KroMignon @Moisi last edited by KroMignon

          @Moisi You have to use sourceSize for this:

          Image {
              source: "some/path/myImage.svg"
              readonly property bool isPortrait: sourceSize.height > sourceSize.width
          }
          

          It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

          1 Reply Last reply Reply Quote 2
          • M
            Moisi last edited by

            Thank you for the answer.

            Unfortunately I can't use it for my case because I want to use the orientation to set the sourceSize dimention. So if I do:

            Image {
                source: "some/path/myImage.svg"
                property bool isPortrait: sourceSize.height> sourceSize.width
                sourceSize.width: isPortrait ? 0 : 150 // This line is not working
                sourceSize.height: isPortrait ? 150 : 0 // This line is not working
            }
            

            My two last lines are not working :/

            But maybe it's not the correct way to resize a svg file ?

            KroMignon 1 Reply Last reply Reply Quote 0
            • KroMignon
              KroMignon @Moisi last edited by

              @Moisi said in Knowing if an image is portrait or landscape oriented (QmlImage):

              But maybe it's not the correct way to resize a svg file ?

              Yes maybe ;)

              Image {
                  source: "some/path/myImage.svg"
                  readonly property bool isPortrait: sourceSize.height > sourceSize.width
                  fillMode: Image.PreserveAspectFit
                  width: 150
                  height: 150
              }
              

              It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

              1 Reply Last reply Reply Quote 1
              • M
                Moisi last edited by

                There is something I do not understand. Setting the width/height properties makes my images pixellated...

                KroMignon 1 Reply Last reply Reply Quote 0
                • KroMignon
                  KroMignon @Moisi last edited by

                  @Moisi said in Knowing if an image is portrait or landscape oriented (QmlImage):

                  There is something I do not understand. Setting the width/height properties makes my images pixellated...

                  Okay, perhaps like this, it is better:

                  Image {
                      source: "some/path/myImage.svg"
                      readonly property bool isPortrait: height > width
                      fillMode: Image.PreserveAspectFit
                      sourceSize: Qt.size(150, 150)
                  }
                  

                  It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                  1 Reply Last reply Reply Quote 1
                  • M
                    Moisi last edited by

                    It's works, thanks a lot =D

                    1 Reply Last reply Reply Quote 0
                    • First post
                      Last post