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. Knowing if an image is portrait or landscape oriented (QmlImage)
Forum Update on Monday, May 27th 2025

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

Scheduled Pinned Locked Moved Solved QML and Qt Quick
7 Posts 2 Posters 572 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.
  • M Offline
    M Offline
    Moisi
    wrote on last edited by
    #1

    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 ^^

    KroMignonK 1 Reply Last reply
    0
    • M Moisi

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

      KroMignonK Offline
      KroMignonK Offline
      KroMignon
      wrote on last edited by
      #6

      @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
      1
      • M Moisi

        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 ^^

        KroMignonK Offline
        KroMignonK Offline
        KroMignon
        wrote on last edited by KroMignon
        #2

        @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
        2
        • M Offline
          M Offline
          Moisi
          wrote on last edited by
          #3

          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 ?

          KroMignonK 1 Reply Last reply
          0
          • M Moisi

            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 ?

            KroMignonK Offline
            KroMignonK Offline
            KroMignon
            wrote on last edited by
            #4

            @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
            1
            • M Offline
              M Offline
              Moisi
              wrote on last edited by
              #5

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

              KroMignonK 1 Reply Last reply
              0
              • M Moisi

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

                KroMignonK Offline
                KroMignonK Offline
                KroMignon
                wrote on last edited by
                #6

                @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
                1
                • M Offline
                  M Offline
                  Moisi
                  wrote on last edited by
                  #7

                  It's works, thanks a lot =D

                  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