image size, position and aspect ratio



  • Hi!

    I wrote an app using QtWidgets that runs on Android and iPhone.

    In the first window there are 3 images, and I can not, no matter how many ways I tried, to make the images no to loose aspect ratio, as the app runs on a different resolution.

    The images are in QFrame, set using style sheet in the window designer.

    I also searched a lot, and again failed to find a solution.

    Is there a way, in compile time or run time, to do it? I am running out of time, and out of options!

    Thanks!


  • Lifetime Qt Champion

    Hi,

    Why not use QLabel to show these images ?



  • I am trying that right now, and still can't make it...

    The QLabel is inside a QFrame.


  • Lifetime Qt Champion

    Why the label in the Frame ?



  • I use QFrame objects to help me positioning widgets. I do not know if it is the best way to do it, but it is the only way I know, so far.


  • Lifetime Qt Champion

    Why not use layouts ?



  • Thanks for your time

    I tried to use layouts, but the aspect ratio of the image was not preserved. Probably I am misusing it. I solved in the old fashioned way: calculating width, height as position.



  • Bit late... but I feel compelled to point out that QML's Image element's support for aspect ratio scaling (take your pick of Image.PreserveAspectFit or Image.PreserveAspectCrop) combined with the horizontal and vertical alignment control properties, (if you don't just want the default centering) is absolutely brilliant for creating layouts which adapt to different screen ratios while preserving designers' original intentions about what's lined up with what. Don't know if embedding a QQuickView and a little bit of QML was an option for you though.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.