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

How to tilt the window by 90 degree?



  • I am creating a QComboBox object in the ui for "Landscape" and "Portrait" mode.How to tilt the ui window?Does Qt support this?


  • Moderators

    Yes Qt will automatically rotate the apps together with the screen. This can be controlled through content orientation and other similar properties.



  • @sierdzio Hi ,Thanks for the reply.Can you send me a code snippet?I did not find any examples for it.


  • Moderators

    You don't need to code anything. Qt will rotate together with your device by default.

    If you want to force rotation, then this may work (untested):

    QWindow window; // your application's window
    window.reportContentOrientationChange(Qt::LandscapeOrientation);
    

    Although quite frankly I suspect this will fail. Most probably some platform-specific calls are necessary here, to force the rotation of the whole screen.



  • @sierdzio what is the header file to be included?


  • Moderators

    @Sriu1
    I'm still not quite clear, on what you want to do.

    • First of, do you do this in QWidgets or in QML?
    • Do you want to detect the current orientation so you can load the different objects?
    • Do you want to force the orientation of your device?
    • Do you simply want to rotate your object around


  • @J.Hilk
    Hi,I am using QWidgets.I want to force the orientation of the application (when I come out of my application I should be in normal mode which is landscape).My screen resolution is 3840x2160.I want to Tilt the application of the qt gui by 90degree so that it can be in portrait mode.So that application works fine on a screen of resolution 2160x3840


  • Moderators

    @Sriu1 said in How to tilt the window by 90 degree?:

    So that application works fine on a screen of resolution 2160x3840

    I'm sorry but that just sounds like you want to resize the app window, not tilt it. Just open your app maximized/ fullscreen and it should work ok.


  • Moderators

    @Sriu1 ok, that makes it a bit clearer,

    two more followup question than,

    • is your app to be supposed to stay in one orientation, or do you want to be able to change that by tilding your phone.
    • do you want something like the youtube up, where when you press full screen the orientation is locked to landscape and outside of that its lockied to portrait ?

    Forcing one orientation throughout the apps lifetime is very easy, making it change due to the gyro of the phone is the default behaviour forcing orientations during specific times of your app is dificult and requieres native code.



  • @J.Hilk Hi,I want it to dynamic.User should be able to switch from portrait to landscape.


  • Moderators

    @Sriu1
    well thats the default behaviour.

    • mkae sure your device can detect orientation changes
    • make sure the orientation is not locked on your device
    • make sure your ui is in a layout, that manages resizing automatically (very important or your ui will stay as it is)

    and just rotate your device around



  • @J.Hilk
    I do not want my complete device(Desktop) to be changed.Only the ui should tilt.I have made sure that all ui objects are in layouts for automatic resizing.Can you send me a code snippet which will only tilt the ui not the complete device?


  • Moderators

    @Sriu1 said in How to tilt the window by 90 degree?:

    @J.Hilk
    I do not want my complete device(Desktop) to be changed.Only the ui should tilt.I have made sure that all ui objects are in layouts for automatic resizing.Can you send me a code snippet which will only tilt the ui not the complete device?

    Well this than has very little to to with the orientation of the device.

    Take a look at the official QWidget-Transformation-Example
    It should give you everything you need to transform your UI the way you want it to.


Log in to reply