Getting screen size of Android virtual device

  • All,

    'am running the following code snippet in Qt to get the screen size of my android virtual device.

    QApplication app(argc, argv);
     QDesktopWidget *mydesk = app.desktop();
        // redundant but using both showFullScreen and showMaximized...
        // ...just to play it safe
      QScreen *screen = app.primaryScreen();
        int width = screen->size().width();
        int height = screen->size().height();

    I created a Nexus 5 Android Virtual Device with resolution 1080x1920 to test my code and my width and height values are 1080x1776 instead of the expected 1080x1920. What 'am I doing wrong here? Can someone please help me?


  • Lifetime Qt Champion


    Just a wild guess, but isn't that the size without the top bar ?

  • Thanks @SGaist. My guess was the same but I do not know how to prove it. Any thoughts?

  • Lifetime Qt Champion

    Does your application cover the status bar ?

  • Qt Champions 2017

    You dont really have to prove it.
    Many other have wondered.

    1080x1776 too much a magic number to be a coincidence ( IMHO)

    I wonder when you create a Nexus 5 Android Virtual Device, it must know from some where
    the size of the bar.

    But if app covers bar ( as @SGaist asks) then it might be bug in the virtual device as as far as i know
    (some) info apps will report full size if app is fullscreen.

  • Thanks @SGaist and @mrjj . My app does not cover the status bar. It is just a test app/Hello World type app that displays the resolution on the screen (so not much to the code than what i posted here). I will try creating an app that covers the status bar and see how that behaves.

    Thanks again

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.