Important: Please read the Qt Code of Conduct -

Running Qt app on phone vs desktop

  • How can I easily detect that I'm running on a smaller screen e.g. 5 to 7 inches, and therefore use the full screen area,
    versus running on a desktop where the display may be huge and the app window smaller? For instance, if I try to infer it by looking at the resolution e.g. 1920x1080, that could apply to both a desktop and to a phone. Even if I get qApp->desktop()->logicalDpiX(); to get the screen dimensions, or I use getenv("QT_SCALE_FACTOR") to try to guess the rough screen size, some desktops have smaller screens e.g. the Raspberry pi 7 inch display.

  • You can use QSysInfo

  • QRect rect = QGuiApplication::screens().at( 0 )->geometry();
    resize your app to the size of rect for full screen or compare the size to check if it is in the full screen mode

  • @mchinand I'm not sure that will work with the PinePhone which runs various Linuxes.

    Perhaps if the screen diagonal is less than 6.8 inches I could call it a phone.
    However I'm finding that when I use QGuiApplication::screens().at(0)->geometry(), combined with dpiX and dpiY,
    the diagonal screen measurement is not accurate, because the DPI values are obtained from the OS, not from the monitor.

  • 6.8 inches means physical size, right? So I think you shouldn't use any logicalDpi*() methods for that.
    Maybe try QScreen::physicalSize(), that should give you the physical screen size in millimeters.
    Or you can search for other physicalDotsPerInch*() / physicalDpi*() methods if you want DPI infomations.

  • @Bonnie The real problem here is that a screen of any size can be used like a desktop, or a phone screen.
    For instance the Raspberry Pi 7" is always used like a desktop UI.
    Thus it is a question of "user interface idiom" i.e. how the screen is meant to be used.

Log in to reply