Display portrait qml application in landscape
Article Metadata
Quite often an application is designed and build in a portrait mode and while the device used for testing it might be N900, the result is not what expected. The application is visible only half of the screen and literally in portrait.
To accommodate this, you can consider using the following snippet as a wrapper for the application and in this way still keep building it as portrait, but to be able to test it for example in N900.
QML
/**
* QML Application sizing and rotation as per N900
*/
import QtQuick 1.0 // Qt 4.7.1 and up, N900 with qt quick compatibility package
import Qt 4.7 // Qt 4.7.0
Rectangle {
id: runner
width: 800
height: 480
// Container element for rotating
Item {
height: 800
width: 480
transformOrigin: Item.TopLeft
y: width
rotation: -90
// Add the main QML element here...
MyApp {
}
}
}
QML with Qt
QmlApplicationViewer viewer;
// force lock for portrait mode
viewer.setOrientation(QmlApplicationViewer::ScreenOrientationLockPortrait);


Woudn't it be better to rotate the view if the device detects that the screen dimensions have changed (ie a transition on x>y changing)? Can you explain a bit more how this works. I think you're fixing to portrait, so not clear to me why you need the inner element
hamishwillee 04:43, 8 March 2011 (UTC)