Adjusting for screen orientation with QML Window
-
I have a custom QML Window that sets its initial height and width based on the screen orientation when the window is created:
property bool is_landscape: mainWindow.width > mainWindow.height width: is_landscape ? mainWindow.width/3 : mainWindow.width/2 height: mainWindow.height/4
This works fine. The problem comes when the screen orientation is changed after the window is displayed. With a QML Rectangle object, I can use states to capture when the orientation changes:
states: [ State { name: "Landscape" when: splash_screen.width > splash_screen.height PropertyChanges { target: splash_screen image_file: "./SplashScreen-landscape.png" } }, State { name: "Portrait" when: splash_screen.height > splash_screen.width PropertyChanges { target: splash_screen image_file: "./SplashScreen-portrait.png" } } ]
However, I cannot use states with a QML Window object, and the window position and dimensions become messed up when the screen orientation changes.
How can I resize my window when screen orientation changes?
-
Have you tried Screen.orientation? Note the part about orientationUpdateMask.
-
@jeremy_k I've come across it, but I am not clear how to use it. The documentation is less than clear. What I want is to re-center my dialog window based on the screen orientation when it changes, and to optionally change height and width properties of the window
-
@DRoscoe said in Adjusting for screen orientation with QML Window:
What I want is to re-center my dialog window based on the screen orientation when it changes
Why don't you just anchor the dialog to the center point, or am I missing something here?
-
@kshegunov said in Adjusting for screen orientation with QML Window:
@DRoscoe said in Adjusting for screen orientation with QML Window:
What I want is to re-center my dialog window based on the screen orientation when it changes
Why don't you just anchor the dialog to the center point, or am I missing something here?
Item anchors aren't available for Window{}.
I wonder if this will work:
Window { id: window visible: true Screen.orientationUpdateMask: Qt.LandscapeOrientation | Qt.PortraitOrientation x: (Screen.width - window.width) / 2 y: (Screen.height - window.height) / 2 Text { anchors.centerIn: parent; text: "X" } }
-
@jeremy_k said in Adjusting for screen orientation with QML Window:
Item anchors aren't available for Window{}.
Yeah, so I discover.