Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to get accurate screen size of monitor
Forum Updated to NodeBB v4.3 + New Features

How to get accurate screen size of monitor

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 1.7k 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.
  • J Offline
    J Offline
    jimbolaya
    wrote on last edited by
    #1

    I'm currently writing a new QML app that will display the app depending on the size of the monitor of the user. If the user's screen size is < 11 inches (windows tablet), I'd display the app in a maximized window. If it's > 11 inches, I'd display the app 70% of the screen.

    To find out the size of the monitor, I had the following code:

    function shouldDisplayFullScreen() {
     if(((Math.sqrt(Math.pow(Screen.width, 2) + Math.pow(Screen.height, 2))) / Screen.pixelDensity / 25.4) < 11) {
      return true;
     } else {
      return false;
     }
    }
    

    As a test on my 1440p 27" monitor, my console displayed the following:
    Screen width: 2560
    Screen height: 1440
    Screen pixelDensity: 2.8348200660963894
    Screen diagonal size in pixels: 2937.2095601097312

    If I did 2937 / 2.83 / 25.4 (to get the screen size in inches), I get something around 40"

    Is my calculation wrong? Does Screen.pixelDensity really represent x pixels in 1 millimeter? Any simpler way of calculating the user's monitor size?

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      Citing the documentation: "Depending on what information the underlying system provides the value might not be entirely accurate.".

      It's definitely not accurate on Android devices. Perhaps you've just confirmed this to also fail on Windows.

      Any simpler way of calculating the user's monitor size?

      Yes, just use Window.show() and it will automatically call showFullScreen() on mobile devices and showNormal() on desktops.

      Or check out physicalDotsPerInch from QScreen. Warning: it will probably be exactly as inaccurate as Screen in QML.

      (Z(:^

      1 Reply Last reply
      1

      • Login

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