Adjusting for screen orientation with QML Window
-
wrote on 14 Sept 2016, 01:54 last edited by
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?
-
wrote on 14 Sept 2016, 02:20 last edited by
Have you tried Screen.orientation? Note the part about orientationUpdateMask.
-
Have you tried Screen.orientation? Note the part about orientationUpdateMask.
wrote on 14 Sept 2016, 02:33 last edited by@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
-
@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?
-
@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?
wrote on 14 Sept 2016, 05:21 last edited by@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" } }
-
@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.
-
@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" } }
-
wrote on 15 Sept 2016, 01:59 last edited by
Happy to hear it. I'm lacking a device with a rotatable screen at the moment, so that recipe involved a little faith.
1/8