Qt6 topics merged with General

Android wrong size for QDoubleSpinBox and QPushButton (newbe question)

  • Hi there :)
    Beeing new to Qt Android programming (...not to Qt!) I ran into problems with the size of Spinboxes and Buttons in my multi-plattform app (written in C++ using Qt 5.4 under linux). What looks good as a desktop app fails to show up in reasonable size, when beeing published on my Samsung Galaxy S5mini cell phone and my Samsung Galaxy tablet (both with Android 4.4).
    Both Spinboxes and Buttons show up too small. Besides that, no Buttons are shown in my custom MessageBoxes when running the app on Android.

    My project uses a QMainWindow, provided with layouts.

    I guess I'd have to write some kind of "android scaling startup code" , but I just don't know where to start. Could someone please provide me some help?

    Thanks for any hints!


  • Hey, the best is to set your sizes by knowing the display size.

    I use the following code for all mobile platforms:

    screen = QGuiApplication::screens().first();
    connect(screen, SIGNAL(virtualGeometryChanged(QRect)), this, SLOT(getScreen()));
    void MainWindow::getScreen()
        QRect rec = QApplication::desktop()->screenGeometry();
        screenY = rec.height();
        screenX = rec.width();

    "screen" is a QScreen.

    Once you know the x and y coordinates, you can start setting sizes :) Try and error for good results.

    From my experience, a good size for icons (at least for my apps) is calculated this way:


    For text, the best is to set a font: (20 looks good on 720p and 1080p)

    QFont font = pushButton->font();

    Best regards,

    • Dom

  • Moderators

    @mbergmann-sh Check out this doc.

Log in to reply