Important: Please read the Qt Code of Conduct -

Get screen orientation before any form created

  • Hi All

    Is there any way to get current screen orientation before any form or widget created (i.e. in main.cpp after the "QApplication a(argc, argv);" line)? This is required because of the application behaves in a strange manner durring the start-up in this case: if a user clicked application icon in the portrait mode and turned the device into landscape mode, the application will still run in a portrait mode (I mean the widget sizes would be as in the portrait mode but the screen is in landscape mode, and as a result of incorrect application visualization, and this is until next orientation change).

    Thanks ahead

  • Please also note that my application is running in full screen mode (showFullScreen() is called).

  • One idea: you can get the "desktopWidget": for the application and check it's size....

  • You could also check if QOrientationReading is useful, but haven't used it myself

  • Just thinking out loud:

    The orientation sensor will give you the physical orientation of the device. Depending on the device you may want to take other sensors into consideration. For example the auto-rotation on the n900 is disabled when the keyboard is open.

    I can't wait to experiment with it. I have used the dbus signals on the n900 to detect the device changing orientation but this would be The Qt way.

Log in to reply