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. How to get screen height and width automatically ?
Forum Updated to NodeBB v4.3 + New Features

How to get screen height and width automatically ?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
5 Posts 3 Posters 7.7k Views 3 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.
  • V Offline
    V Offline
    vishu_fcb
    wrote on last edited by
    #1

    I am using QML to make an UI interface. Is there any possibility to get the screen height and width so that my app is responsive .
    Currently i have hard coded my application for a desired width and height as a result if i am running my app on a different screen size , it is not attaining full screen . I found a class called QDesktopwidget but this only works for Qt with c++ and not using QML
    any suggestions would be appreciated

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mostefa
      wrote on last edited by mostefa
      #2

      HI @vishu_fcb

      You can have full screen Window by using visibilty property,

      http://doc.qt.io/qt-5/qml-qtquick-window-window.html#visibility-prop

      you have to add this line to your qml Window

      visibility: Window.FullScreen
      

      I made a sample for you (tested with qt5.4)

      import QtQuick 2.4
      import QtQuick.Window 2.2
      
      Window {// Here is your window object
          visible: true
          visibility: Window.FullScreen//the line to add to have a full screen window
          Rectangle {
              anchors.fill: parent
              mouseArea.onClicked: {
                  Qt.quit();
              }
      
          }
      }
      

      I hope this can help you !

      V 1 Reply Last reply
      2
      • M mostefa

        HI @vishu_fcb

        You can have full screen Window by using visibilty property,

        http://doc.qt.io/qt-5/qml-qtquick-window-window.html#visibility-prop

        you have to add this line to your qml Window

        visibility: Window.FullScreen
        

        I made a sample for you (tested with qt5.4)

        import QtQuick 2.4
        import QtQuick.Window 2.2
        
        Window {// Here is your window object
            visible: true
            visibility: Window.FullScreen//the line to add to have a full screen window
            Rectangle {
                anchors.fill: parent
                mouseArea.onClicked: {
                    Qt.quit();
                }
        
            }
        }
        

        I hope this can help you !

        V Offline
        V Offline
        vishu_fcb
        wrote on last edited by
        #3

        @mostefa Thanks or your help !! But i fixed the issue
        i used :
        import QtQuick.Window 2.2
        Rectangle {
        width:screen.width
        height:screen.height
        mouseArea{
        .onClicked: {
        Qt.quit();
        }
        }
        }
        It worked

        1 Reply Last reply
        0
        • LorenzL Offline
          LorenzL Offline
          Lorenz
          wrote on last edited by
          #4

          Hi,

          You can find a great article on supporting different screen sizes with Qt here and a simple code example here.

          It will teach you the basics on how to do this with Qt. You can also check out V-Play, which will help you build responsive apps a lot faster, as most of the work is done for you automagically (See image below).

          alt text

          All the best,
          Lorenz

          Developer @ V-Play Engine - http://v-play.net/qt

          V-Play simplifies

          • Game Development with Qt
          • Mobile App Dev with Qt esp. iOS & Android

          What others say
          V-Play scored #1 in Cross-Platform App Development Tools Report - see why: https://goo.gl/rgp3rq

          V 1 Reply Last reply
          0
          • LorenzL Lorenz

            Hi,

            You can find a great article on supporting different screen sizes with Qt here and a simple code example here.

            It will teach you the basics on how to do this with Qt. You can also check out V-Play, which will help you build responsive apps a lot faster, as most of the work is done for you automagically (See image below).

            alt text

            All the best,
            Lorenz

            V Offline
            V Offline
            vishu_fcb
            wrote on last edited by
            #5

            @Lorenz Thanks a lot

            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