Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Rotate coordinates of display?



  • I have an app I would like to test in full screen with a resolution of 1920x1080. I would also like to test the orientation of the display as if the display is 1080x1920. I tried using the Page component to rotate (rotation: -90), but it does not swap the underlying coordinates of the Components inside of it. It just rotates all the components, but the top level component inside the Page still sees the area as 1920x1080. Is there a way to rotate the entire app such that the width and height get swapped as well?



  • I tried virtualizing the width and height and it sorta works:

    property int r_width: pagerot.rotation == 0 ? width : height
    property int r_height: pagerot.rotation == 0 ? height : width
    

    But the origin of where it starts drawing does not seem to be the corner where I would expect it to be. It would also cause the mouse to be wrong when testing. I am just going to rely on the operating system to rotate my screen for testing. This trying to trick qml to do it is folly.



  • Hi @fcarney , just to add, i guess the simplest way you can do is to deploy a simple android app, with auto-rotate enabled on your phone. So when you rotate your phone the height and width get swapped.

    I just tried a sample app with 2 Rectangles inside a ColumnLayout and Rectangles consisting of a text which prints the Screen.height and Screen.width

    ColumnLayout {
        anchors.fill: parent
    
        Rectangle {
            Layout.fillHeight: true
            Layout.fillWidth: true
            color: "red"
    
            Text {
                text: Screen.height
                anchors.centerIn: parent
            }
        }
    
        Rectangle {
            Layout.fillHeight: true
            Layout.fillWidth: true
            color: "green"
    
            Text {
                text: Screen.width
                anchors.centerIn: parent
            }
        }
    }
    

    Portrait Mode:-
    0_1559197044024_ab817d6a-452d-4861-b1de-926b6193c362-image.png

    Landscape Mode:-
    0_1559197075947_9c5f9336-a4cf-4b28-ba7b-07b70c233691-image.png

    Here the red rectangle prints the height and green rectangle prints the width, so you can see from the above images when rotate your phone the height and the width get swapped.


Log in to reply