Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Adjusting for screen orientation with QML Window

Adjusting for screen orientation with QML Window

Scheduled Pinned Locked Moved Solved Mobile and Embedded
iosqml
8 Posts 3 Posters 6.9k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    DRoscoe
    wrote on 14 Sept 2016, 01:54 last edited by
    #1

    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?

    1 Reply Last reply
    0
    • J Offline
      J Offline
      jeremy_k
      wrote on 14 Sept 2016, 02:20 last edited by
      #2

      Have you tried Screen.orientation? Note the part about orientationUpdateMask.

      Asking a question about code? http://eel.is/iso-c++/testcase/

      D 1 Reply Last reply 14 Sept 2016, 02:33
      0
      • J jeremy_k
        14 Sept 2016, 02:20

        Have you tried Screen.orientation? Note the part about orientationUpdateMask.

        D Offline
        D Offline
        DRoscoe
        wrote on 14 Sept 2016, 02:33 last edited by
        #3

        @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

        K 1 Reply Last reply 14 Sept 2016, 04:16
        0
        • D DRoscoe
          14 Sept 2016, 02:33

          @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

          K Offline
          K Offline
          kshegunov
          Moderators
          wrote on 14 Sept 2016, 04:16 last edited by
          #4

          @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?

          Read and abide by the Qt Code of Conduct

          J 1 Reply Last reply 14 Sept 2016, 05:21
          0
          • K kshegunov
            14 Sept 2016, 04:16

            @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?

            J Offline
            J Offline
            jeremy_k
            wrote on 14 Sept 2016, 05:21 last edited by
            #5

            @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" }
            }

            Asking a question about code? http://eel.is/iso-c++/testcase/

            K D 2 Replies Last reply 14 Sept 2016, 08:37
            2
            • J jeremy_k
              14 Sept 2016, 05:21

              @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" }
              }
              K Offline
              K Offline
              kshegunov
              Moderators
              wrote on 14 Sept 2016, 08:37 last edited by
              #6

              @jeremy_k said in Adjusting for screen orientation with QML Window:

              Item anchors aren't available for Window{}.

              Yeah, so I discover.

              Read and abide by the Qt Code of Conduct

              1 Reply Last reply
              0
              • J jeremy_k
                14 Sept 2016, 05:21

                @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" }
                }
                D Offline
                D Offline
                DRoscoe
                wrote on 14 Sept 2016, 14:17 last edited by
                #7

                @jeremy_k That did the trick! Thanks!

                1 Reply Last reply
                0
                • J Offline
                  J Offline
                  jeremy_k
                  wrote on 15 Sept 2016, 01:59 last edited by
                  #8

                  Happy to hear it. I'm lacking a device with a rotatable screen at the moment, so that recipe involved a little faith.

                  Asking a question about code? http://eel.is/iso-c++/testcase/

                  1 Reply Last reply
                  0

                  1/8

                  14 Sept 2016, 01:54

                  • Login

                  • Login or register to search.
                  1 out of 8
                  • First post
                    1/8
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved