QML Window gets resized on Android - How to deal with this?



  • Dear QT Headz,

    I have a small QML App which I deploy to android.

    There is an image that i would like to show in the original resolution independently from the devices screen resolution.
    The app performs "perfect" on the Desktop (Window Resolution set to 720*1280 - portrait) but if i deploy it to the android phone,
    I can read from the debug that the window width is set to 411 in portrait and to 617 in landscape mode.

    (onWidthChanged): qml: width changed 617
    (onWidthChanged): qml: width changed 411
    

    This is a very minimum code to show my confusion:

    import QtQuick 2.10
    import QtQuick.Window 2.7
    
    Window {
        id: window
        visible: true
        width: 720
        height: 1280
        title: qsTr("Hello World")
        minimumWidth: 720
        minimumHeight: 1280
        onWidthChanged: {
            print ("width changed: " + width)
        }
    
        Rectangle {
            id: recti
            width: 0.75 * window.width
            height: 0.02 * width
            radius: height * 0.5
            anchors.top: parent.top
            anchors.topMargin: 10
            anchors.horizontalCenter: parent.horizontalCenter
            color: "green"
        }
    
        Image {
            id: image
            width: sourceSize.width
            height: sourceSize.height
            anchors.top: recti.bottom
            anchors.topMargin: 10
            anchors.horizontalCenter: parent.horizontalCenter
            source: "bear.png"
        }
    }
    

    The problem is, that the a part of the picture gets cut off in portrait mode. Is there an option to optimize the size of it for portrait and not for landscape mode?
    In the real project I have a Pathview Type on a picture positioned on a given position (provided in pixels..), that is why i tried to avoid using relative size like width: parent.width * 0.75

    I also receive some Warnings from the Linker when I upload the app to the phone.

    W linker  : /data/data/org.qtproject.example.windowResize/qt-reserved-files/qml/QtQuick.2/libqtquick2plugin.so: unsupported flags DT_FLAGS_1=0x81
    W linker  : /data/data/org.qtproject.example.windowResize/qt-reserved-files/qml/QtQuick/Window.2/libwindowplugin.so: unsupported flags DT_FLAGS_1=0x81
    W linker  : /data/data/org.qtproject.example.windowResize/qt-reserved-files/qml/QtQuick/Controls.2/libqtquickcontrols2plugin.so: unsupported flags DT_FLAGS_1=0x81
    W linker  : /data/data/org.qtproject.example.windowResize/qt-reserved-files/plugins/imageformats/libqgif.so: unsupported flags DT_FLAGS_1=0x81
    W linker  : /data/data/org.qtproject.example.windowResize/qt-reserved-files/plugins/imageformats/libqicns.so: unsupported flags DT_FLAGS_1=0x81
    W linker  : /data/data/org.qtproject.example.windowResize/qt-reserved-files/plugins/imageformats/libqico.so: unsupported flags DT_FLAGS_1=0x81
    W linker  : /data/data/org.qtproject.example.windowResize/qt-reserved-files/plugins/imageformats/libqjpeg.so: unsupported flags DT_FLAGS_1=0x81
    W linker  : /data/data/org.qtproject.example.windowResize/qt-reserved-files/plugins/imageformats/libqtga.so: unsupported flags DT_FLAGS_1=0x81
    W linker  : /data/data/org.qtproject.example.windowResize/qt-reserved-files/plugins/imageformats/libqtiff.so: unsupported flags DT_FLAGS_1=0x81
    W linker  : /data/data/org.qtproject.example.windowResize/qt-reserved-files/plugins/imageformats/libqwbmp.so: unsupported flags DT_FLAGS_1=0x81
    W linker  : /data/data/org.qtproject.example.windowResize/qt-reserved-files/plugins/imageformats/libqwebp.so: unsupported flags DT_FLAGS_1=0x81
    

    The resolution of the phone is: 1620 x 1080
    Portrait: (Cut off sides)
    0_1522410532822_Screenshot_20180330-134443.png

    Landscape:
    0_1522410504877_Screenshot_20180330-134718.png

    Maybe using a GridLayout with a preferred height / width could help?
    I am happy about any advice.

    Thank you for bearing with me :)



  • I solved it for now by using a size relative to its parent and calculating a scale from it. Also applying the same scale to the position of the Pathview gives a usable solution, but it requires a few additional calculations.
    I see how the (617 * 411) resolution occurs.
    So the Windows width: and height: properties are not sizes in pixels..

    Desktop - 1920*1200 or 2560x1440
    density 4.2969047380546925
    pixelRatio 1

    Mobile
    density 6.5092731829573935 - 1620 x 1080
    pixelRatio 2.626672502927989

    1620/2.6266... gives 617
    1080/2.6266... gives 411


Log in to reply
 

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