Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Get screen size from QML
Forum Updated to NodeBB v4.3 + New Features

Get screen size from QML

Scheduled Pinned Locked Moved QML and Qt Quick
14 Posts 8 Posters 37.5k Views 1 Watching
  • 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.
  • T Offline
    T Offline
    tomjanssens
    wrote on last edited by
    #1

    Hello,

    how do i set the width / height equal to the screen size in qml?

    Cheers
    Tom

    1 Reply Last reply
    1
    • K Offline
      K Offline
      Kxyu
      wrote on last edited by
      #2

      run qmlviewer in fullscreen mode

      1 Reply Last reply
      0
      • T Offline
        T Offline
        tomjanssens
        wrote on last edited by
        #3

        Hello,

        I am running the QDeclarativeView in Full Screen mode.

        But I am trying to set a child widget relative to the full screen Rectangle:

        Rectangle {

        Myrect1 {
        
        }
        
        Myrect2 {
            x: parent.width / 2
        }
        

        }

        Myrect 2 isn't shown at the right place of the screen.

        Cheers
        Tom

        1 Reply Last reply
        0
        • R Offline
          R Offline
          raghava.chinnappa
          wrote on last edited by
          #4

          Tom,

          to make relative width/height to the parent, you can use the code like this

          @Rectangle{
          // here you need to set the parent width / height properties to use relatively
          width: 500
          height: 500

          Myrect1{ }
          
          Myrect2{
              // set width / height relative to the parent
              width: parent.width
              height: parent.height
          }
          

          }
          @

          1 Reply Last reply
          1
          • T Offline
            T Offline
            tomjanssens
            wrote on last edited by
            #5

            Hello,

            I know I can do that. But I don't want to set a hard coded number because then I am stuck to one screen size. I want to retrieve the screen size of the device and use that. Would this be possible in plain QML, or do I need to do it in C++ and pass the values to QML?

            Cheers
            Tom

            1 Reply Last reply
            0
            • S Offline
              S Offline
              syrianzoro
              wrote on last edited by
              #6

              Yes, you need to pass the values to QML from c++ look the following:

              Obtaining a Desktop Widget

              The QApplication::desktop() function is used to get an instance of QDesktopWidget.

              The widget's screenGeometry() function provides information about the geometry of the available screens with. The number of screens available is returned by screenCount, and the screenCountChanged() signal is emitted when screens are added or removed. The screen number that a particular point or widget is located in is returned by screenNumber().

              Qt is the future

              1 Reply Last reply
              0
              • M Offline
                M Offline
                mbrasser
                wrote on last edited by
                #7

                Hi Tom,

                Have you tried setting the SizeRootObjectToView resize mode on your QDeclarativeView? That should ensure that the root object is the same size as the view. With that in place, the easiest way to center a child in its parent is with anchors:

                @MyRect { anchors.centerIn: parent }@

                you should also be able to center manually with e.g.

                @MyRect { x: parent.width/2 - width/2; ... }@

                Regards,
                Michael

                1 Reply Last reply
                0
                • T Offline
                  T Offline
                  tomjanssens
                  wrote on last edited by
                  #8

                  Hi,

                  The SizeRootObjectToView works perfectly. Just what I needed.

                  Cheers
                  Tom

                  1 Reply Last reply
                  0
                  • K Offline
                    K Offline
                    Kysymys
                    wrote on last edited by
                    #9

                    Is there a pure QML way to achieve this?

                    Okay strike that.
                    -Is there a pure QML way to achieve this?-

                    I found the place where to put the "--fulscreen" parameter in Qt-Creator.

                    \o/ \o/ Kudos ...

                    Paholaisen Kysymys

                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      AlterX
                      wrote on last edited by
                      #10

                      Qt 5.x has QML Screen object you can use within an Item.

                      Qt Ambassador
                      Real-time cooperative teams: http://www.softairrealfight.net
                      Free Real-time network platform sdk: https://github.com/AlterX76/Solomon

                      https://codereview.qt-project.org/...

                      1 Reply Last reply
                      0
                      • clogwogC Offline
                        clogwogC Offline
                        clogwog
                        wrote on last edited by
                        #11

                        [quote author="AlterX" date="1395760356"]Qt 5.x has QML Screen object you can use within an Item.[/quote]

                        thanks !!

                        i just added:

                        @import QtQuick.Window 2.0@

                        then set the width/height like :

                        @ApplicationWindow {
                        id: applicationWindow1

                        width: Screen.width
                        height: Screen.height@
                        

                        and it works

                        1 Reply Last reply
                        1
                        • clogwogC Offline
                          clogwogC Offline
                          clogwog
                          wrote on last edited by
                          #12

                          [quote author="AlterX" date="1395760356"]Qt 5.x has QML Screen object you can use within an Item.[/quote]

                          thanks !!

                          i just added:

                          @import QtQuick.Window 2.0@

                          then set the width/height like :

                          @ApplicationWindow {
                          id: applicationWindow1

                          width: Screen.width
                          height: Screen.height@
                          

                          and it works

                          1 Reply Last reply
                          1
                          • A Offline
                            A Offline
                            AlterX
                            wrote on last edited by
                            #13

                            Good...so tag thread's title with [SOLVED]

                            Qt Ambassador
                            Real-time cooperative teams: http://www.softairrealfight.net
                            Free Real-time network platform sdk: https://github.com/AlterX76/Solomon

                            https://codereview.qt-project.org/...

                            1 Reply Last reply
                            0
                            • A Offline
                              A Offline
                              AlterX
                              wrote on last edited by
                              #14

                              Good...so tag thread's title with [SOLVED]

                              Qt Ambassador
                              Real-time cooperative teams: http://www.softairrealfight.net
                              Free Real-time network platform sdk: https://github.com/AlterX76/Solomon

                              https://codereview.qt-project.org/...

                              1 Reply Last reply
                              0

                              • Login

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