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

[Windows] QWidget::showMaximized() does not follow SPI_SETWORKAREA correctly when Qt::FramelessWindowHint is set

    XMLWordPrintable

Details

    • Windows
    • 90be6609b (dev), 2c1a23f3c (6.8), f7da1103e (tqtc/lts-6.5)

    Description

      Frameless QWidgets have this issue; frameless non-Qt windows do not.

       

      Code

      #include <QtWidgets>
      #include <windows.h>
      
      static QLabel *label = nullptr;
      static void adjustWorkArea(int height_delta)
      {
          RECT rect;
          SystemParametersInfo(SPI_GETWORKAREA, 0, &rect, 0);
          rect.top += height_delta;
          SystemParametersInfo(SPI_SETWORKAREA, 0, &rect, SPIF_UPDATEINIFILE);
      
          label->setText(
              QStringLiteral(
                  "Offset: %1\n\n"
                  "Remember to restore the offset to 0!"
              )
              .arg(rect.top)
          );
      }
      
      int main(int argc, char *argv[])
      {
          QApplication app(argc, argv);
      
          auto btn_increaseOffset = new QPushButton("Increase work area offset");
          auto btn_decreaseOffset = new QPushButton("Decrease work area offset");
          label = new QLabel;
          auto checkbox_frameless = new QCheckBox("Frameless?");
          auto btn_maximize = new QPushButton("Maximize");
          auto btn_restore = new QPushButton("Restore");
      
          QWidget win;
          auto layout = new QVBoxLayout(&win);
          layout->addWidget(btn_increaseOffset);
          layout->addWidget(btn_decreaseOffset);
          layout->addWidget(label);
          layout->addWidget(checkbox_frameless);
          layout->addWidget(btn_maximize);
          layout->addWidget(btn_restore);
          win.resize(400, 300);
          win.show();
      
          adjustWorkArea(0);
      
          QObject::connect(btn_increaseOffset, &QPushButton::clicked, qApp, [] {
              adjustWorkArea(50);
          });
          QObject::connect(btn_decreaseOffset, &QPushButton::clicked, qApp, [] {
              adjustWorkArea(-50);
          });
          QObject::connect(checkbox_frameless, &QCheckBox::stateChanged, qApp, [&] {
              win.setWindowFlag(Qt::FramelessWindowHint, (checkbox_frameless->checkState() == Qt::Checked));
              win.show();
          });
          QObject::connect(btn_maximize, &QPushButton::clicked, qApp, [&] {
              win.showMaximized();
          });
          QObject::connect(btn_restore, &QPushButton::clicked, qApp, [&] {
              win.showNormal();
          });
      
          return app.exec();
      }
      

       

      Steps to reproduce

      1. Build and run the attached code
      2. Click "Increase work area offset" to get a non-zero offset
      3. Maximize the widget (click the "Maximize" button, or use the [Win]+[↑] keyboard shortcut)
      4. Restore the widget
      5. Check the "Frameless?" checkbox
      6. Maximize the widget
      7. Build and run the code at https://github.com/melak47/BorderlessWindow
      8. Maximize that non-Qt borderless window (use the [Win]+[↑] keyboard shortcut)
      9. Click "Decrease work area offset" to get a zero offset before quitting

       

      Outcomes

      • Step #3: The framed QWidget is maximized with an offset at the top of the screen (Expected)
      • Step #6: The frameless QWidget is maximized with an offset at the bottom of the screen (Not Expected)
      • Step #8: The frameless non-Qt window is maximized with an offset at the top of the screen (Expected)

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              wladimir.leuschner Wladimir Leuschner
              skoh-qt Sze Howe Koh
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes