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

Widget takes a long time until it starts to receive mouse events in full screen mode on macOS

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 5.15.6, 6.4.0
    • QPA
    • None
    • macOS

    Description

      In normal screen mode, Qt widgets receive mouse events immediately after creation. In full-screen mode on macOS, however, it takes a while until the widget starts receiving those events. From my tests, it takes ~700ms on average until a widget receives its first mouse event versus ~30ms in normal screen mode. See my test in the GIF animation below.

      I don't see any reason why events couldn't stream in earlier when opening a widget into full-screen mode, as there is no zoom-to-full-screen animation like when you maximize an existing window into full-screen. Therefore, I would expect the full-screen window to receive mouse events immediately after rendering, just like if you had opened it in normal-screen mode. The code for my test follows below, which I ran with Qt 5.15.6 and 6.4.0.

      /**
       * main.cpp
       */
      
      #include <QApplication>
      #include "mainwindow.h"
      
      int main(int argc, char *argv[]) {
          QApplication a(argc, argv);
          MainWindow mainWindow;
          mainWindow.show();
          return QApplication::exec();
      }
      
      
      /**
       * mainwindow.h
       */
      
      #pragma once
      
      #include "popupwindow.h"
      #include <QWidget>
      #include <QPushButton>
      
      class MainWindow : public QWidget
      {
          Q_OBJECT
      
      public:
          MainWindow(QWidget *parent = nullptr);
      
      private slots:
          void handleFullScreenButton();
          void handleNormalScreenButton();
      
      private:
          PopupWindow* m_fullScreenWindow;
          QPushButton* m_fullScreenButton;
          QPushButton* m_normalScreenButton;
          PopupWindow* m_normalScreenWindow;
      };
      
      
      /**
       * popupwindow.h
       */
      
      #pragma once
      
      #include <QWidget>
      #include <QLabel>
      
      class PopupWindow : public QWidget
      {
          Q_OBJECT
      
      public:
          explicit PopupWindow(QWidget* parent = nullptr);
      
      protected:
          void mouseMoveEvent(QMouseEvent *event) override;
          void mousePressEvent(QMouseEvent *event) override;
      
      private:
          void showText(const QString &text);
          QLabel* m_text;
          qint64 m_creationTimestamp;
          bool m_eventReceived;
      };
      
      
      /**
       * mainwindow.cpp
       */
      
      #include "mainwindow.h"
      #include <QDebug>
      #include <QVBoxLayout>
      
      MainWindow::MainWindow(QWidget *parent)
          : m_normalScreenWindow(nullptr)
          , m_fullScreenWindow(nullptr)
      {
          auto *layout = new QVBoxLayout(this);
          m_normalScreenButton = new QPushButton("Popup screen");
          m_fullScreenButton = new QPushButton("Popup full screen");
          connect(m_normalScreenButton, &QPushButton::released, this, &MainWindow::handleNormalScreenButton);
          connect(m_fullScreenButton, &QPushButton::released, this, &MainWindow::handleFullScreenButton);
          layout->addWidget(m_normalScreenButton);
          layout->addWidget(m_fullScreenButton);
      }
      
      void MainWindow::handleNormalScreenButton() {
          m_normalScreenWindow = new PopupWindow(this);
          m_normalScreenWindow->show();
          m_normalScreenWindow->activateWindow();
          m_normalScreenWindow->raise();
      }
      
      void MainWindow::handleFullScreenButton() {
          m_fullScreenWindow = new PopupWindow(this);
          m_fullScreenWindow->showFullScreen();
          m_fullScreenWindow->activateWindow();
          m_fullScreenWindow->raise();
      }
      
      
      /**
       * popupwindow.cpp
       */
      
      #include "popupwindow.h"
      #include <QDateTime>
      #include <QDebug>
      #include <QHBoxLayout>
      
      PopupWindow::PopupWindow(QWidget *parent)
          : m_creationTimestamp(QDateTime::currentMSecsSinceEpoch())
          , m_eventReceived(false)
          , m_text(nullptr)
      {
          setAttribute(Qt::WA_DeleteOnClose);
          setMouseTracking(true);
      }
      
      void PopupWindow::mouseMoveEvent(QMouseEvent *event) {
          if (m_eventReceived) {
              return;
          }
          auto deltaTimeMs = QDateTime::currentMSecsSinceEpoch() - m_creationTimestamp;
          showText(QString("First mouse event received after %1 ms.").arg(deltaTimeMs));
          m_eventReceived = true;
      }
      
      void PopupWindow::mousePressEvent(QMouseEvent *event) {
          showNormal();
          close();
      }
      
      void PopupWindow::showText(const QString &text) {
          m_text = new QLabel(text);
          m_text->setStyleSheet("font: 26pt;");
          auto *layout = new QVBoxLayout(this);
          layout->addWidget(m_text, Qt::AlignCenter);
      }

       

       

      Attachments

        Activity

          People

            vestbo Tor Arne Vestbø
            tomasito665 Jordi Ortolá Ankum
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: