Important: Please read the Qt Code of Conduct -

QT5.15.2 on Android: How to disable Qt::AA_ForceRasterWidgets for child dialogs?

  • I've made an application for Android where I need to set the attribute Qt::AA_ForceRasterWidgets to get the native screen resolution without any scaling. This is working as expected. However. I have a settings dialog created with QTDesigner also. This dialog looks really ugly now because the font is too big and the child's are too small (look at the picture blow). Is there a way to disable the consequences derived from the attribute Qt::AA_ForceRasterWidgets just for such a dialog?


    The code I use:

    int qtmain(int argc, char **argv, TPageManager *pmanager)
        pageManager = pmanager;
    #ifdef Q_OS_ANDROID
        QApplication app(argc, argv);

    And for the dialog:

    void MainWindow::settings()
        TQtSettings *dlg_settings = new TQtSettings(this);
    #ifdef __ANDROID__
        dlg_settings->setAttribute(Qt::WA_NativeWindow);   // <-- Doesn't work!!
        int ret = dlg_settings->exec();
        if (ret && dlg_settings->hasChanged())
        else if (!ret && dlg_settings->hasChanged())
            TConfig cf(TConfig::getConfigPath() + "/" + TConfig::getConfigFileName());

  • I found a solution. The answer is simply to calculate a scale factor and resize everything. The dialog window as well as all elements in this dialog. Here is an example of how to do this:

    void TQtSettings::doResize()
        // The main dialog window
        QSize size = this->size();
        QRect rect = this->geometry();
        size.scale(scale(size.width()), scale(size.height()), Qt::KeepAspectRatio);
        this->move(scale(rect.left()), scale(;
        QWidget *parent = this->parentWidget();
        if (parent)
            rect = parent->geometry();
            this->move( - this->rect().center());
        // labels
        QFont font = ui->label_Channel->font();
        size = ui->label_Channel->size();
        size.scale(scale(size.width()), scale(size.height()), Qt::KeepAspectRatio);
        rect = ui->label_Channel->geometry();
        ui->label_Channel->move(scale(rect.left()), scale(;
    int TQtSettings::scale(int value)
        if (value <= 0 || mScaleFactor == 1.0)
            return value;
        return (int)((double)value * mScaleFactor);

    There may be a more elegant way by iterating through the elements instead of writing spaghetti code. However. The above code just demonstrate how to do it.
    This results in a dialog like this (for the colours blame the poor theme on the VM):
    dialog window