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

QWidget::setFixedSize() causes glitches when moving to another screen with a different DPI

    XMLWordPrintable

Details

    • Bug
    • Resolution: Won't Do
    • Not Evaluated
    • None
    • 5.15.12
    • GUI: High-DPI
    • Windows 10 Pro 22H2, MSVC 2019 x64

    Description

      Code

      // widget.h
      class Widget : public QWidget
      {
          Q_OBJECT
      
      public:
          Widget(QWidget* parent = nullptr) : QWidget(parent) {}
      
      protected:
          void paintEvent(QPaintEvent*)
          {
              QPainter p(this);
              p.drawLine(0, 0, width(), height());
              p.drawLine(0, height(), width(), 0);
          }
      };
      
      // main.cpp
      int main(int argc, char *argv[])
      {
          QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);  // Enabling/disabling this has no effect
          QApplication app(argc, argv);
      
          Widget win;
          win.setMaximumSize(600, 400);
          win.show();
      
          return app.exec();
      }
      

       

      Steps to reproduce

      1. Set up 2 screens, with 125% scaling on the first and 100% on the second.
      2. Build and run the attached project. Launch the application on the 125% screen.
      3. Very gradually, move the window towards the second screen, until just after the window scaling changes
      4. Very gradually, move the window towards the original screen

       

      If the glitch doesn't occur on the first attempt, try a few more times.

       

      Outcome
      During both transitions, glitching occurs.

       

      Scope of bug

      • The issue also occurs if we replace setFixedSize() with setMinimumSize() and setMaximumSize(), giving the same sizes
      • The issue does not occur if we replace setFixedSize() with resize()
      • The issue does not occur in Qt 6

       

      Workaround

      Set a maximum size that is very close to (but not equal to) the minimum size:

      win.setMaximumSize(601, 400);
      win.setMinimumSize(600, 400);
      

      Attachments

        Activity

          People

            vhilshei Volker Hilsheimer
            skoh-qt Sze Howe Koh
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: