Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. QT5.15.2 on Android: How to disable Qt::AA_ForceRasterWidgets for child dialogs?
QtWS25 Last Chance

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

Scheduled Pinned Locked Moved Solved Mobile and Embedded
aaforcerasterwandroid 10
2 Posts 1 Posters 392 Views
  • 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.
  • T Offline
    T Offline
    TheoSys
    wrote on last edited by TheoSys
    #1

    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?

    Screenshot

    The code I use:

    int qtmain(int argc, char **argv, TPageManager *pmanager)
    {
        pageManager = pmanager;
    
    #ifdef Q_OS_ANDROID
        QApplication::setAttribute(Qt::AA_ForceRasterWidgets);
    #endif
    
        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!!
    #endif
        int ret = dlg_settings->exec();
    
        if (ret && dlg_settings->hasChanged())
            writeSettings();
        else if (!ret && dlg_settings->hasChanged())
        {
            TConfig cf(TConfig::getConfigPath() + "/" + TConfig::getConfigFileName());
        }
    }
    
    1 Reply Last reply
    0
    • T Offline
      T Offline
      TheoSys
      wrote on last edited by
      #2

      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->resize(size);
          this->move(scale(rect.left()), scale(rect.top()));
          QWidget *parent = this->parentWidget();
      
          if (parent)
          {
              rect = parent->geometry();
              this->move(rect.center() - this->rect().center());
          }
      
          // labels
          QFont font = ui->label_Channel->font();
          font.setPointSizeF(12.0);
          size = ui->label_Channel->size();
          size.scale(scale(size.width()), scale(size.height()), Qt::KeepAspectRatio);
          ui->label_Channel->resize(size);
          rect = ui->label_Channel->geometry();
          ui->label_Channel->move(scale(rect.left()), scale(rect.top()));
          ui->label_Channel->setFont(font);
      [...]
      }
      
      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

      1 Reply Last reply
      0

      • Login

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