Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-136108

EnableHighDpiScaling cause non-smooth window movement across different DPI screens

    XMLWordPrintable

Details

    • Windows
    • Windows

    Description

      QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); 
      QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);    QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);

      I use this code to set auto scaling, but when I use a QLabel and setWordWrap to true, the dialog will have a positon error when moved between screens with diffrent dpi! How to solved this problem?


      // main.cpp
      #include <QApplication>
      #include <QDialog>
      #include <QLabel>
      #include <QVBoxLayout>
      
      int main(int argc, char *argv[])
      {
          QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
          QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
          QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
          QApplication a(argc, argv);
      
          QDialog* dlg = new QDialog();
          dlg->setFixedSize(400, 197);
          QVBoxLayout* mainLayout = new QVBoxLayout(dlg);
      
          QLabel* content = new QLabel(dlg);
          content->setWordWrap(true);
          content->setText("test test test test test test test test test test test test test test test test test test test test");
      
          mainLayout->addWidget(content);
          dlg->show();
      
          return a.exec();
      }
      
      

      This is a example, you can create a Qt project with QtCreator, and replace the main.cpp with this.

       

       

      Attachments

        1. image-2025-04-24-15-29-17-235.png
          image-2025-04-24-15-29-17-235.png
          40 kB
        2. main.cpp
          0.8 kB
        3. Qt6.8.0.mp4
          14.86 MB
        4. video.mp4
          17.70 MB
        5. Video2.mp4
          9.39 MB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            owolff Oliver Wolff
            niewu 杨 冠武
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes