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

[Reg 5.11 -> 5.12] Incorrect handling of active window in response to a double click in a view

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P1: Critical
    • 5.12.1
    • 5.12.0
    • Widgets: Itemviews
    • None
    • Windows
    • df27484fc0349bb060e023ac2dce246c1176d838

    Description

      The code at the bottom of this bug report is a functioning example to illustrate the bug.

      Double clicking on an item in the view opens a popup as desired, but the main window immediately goes active again. The output of the program around this time is:

      ...
      QEvent::HoverMove
      QEvent::HoverMove
      QEvent::UpdateRequest
      popup opened!
      QEvent::WindowDeactivate
      QEvent::ActivationChange
      QEvent::WindowActivate
      QEvent::ActivationChange
      QEvent::UpdateRequest
      QEvent::Paint
      QEvent::Paint
      QEvent::HoverMove
      QEvent::HoverMove
      ...
      

      The program outputs QEvent::WindowActivate without delay after WindowDeactivate.

      Very interestingly, it does not happen if I use QAbstractItemView::clicked instead of doubleClicked. My testing tells me this is a regression from 5.11.3. It also does not occur with 5.12 on linux. In both those cases the output above is similar, except there is no WindowActivate and second ActivationChange.

      The backtrace when a breakpoint hits the flag = false; line:

      1   MainWindow::event                                      main.cpp    21 0x7ff618e962cb 
      2   QScrollBar::wheelEvent                                 Qt5Widgetsd    0x7fffd667bf3e 
      3   QScrollBar::wheelEvent                                 Qt5Widgetsd    0x7fffd6679694 
      4   QFutureInterfaceBase::waitForFinished                  Qt5Cored       0x7fffd2dbcc56 
      5   QFutureInterfaceBase::waitForFinished                  Qt5Cored       0x7fffd2dbcafb 
      6   QScrollBar::wheelEvent                                 Qt5Widgetsd    0x7fffd667597a 
      7   QScrollBar::wheelEvent                                 Qt5Widgetsd    0x7fffd667a767 
      8   QOpenGLFunctions_3_3_Compatibility::glMultiTexCoord1dv Qt5Guid        0x7fffd9203662 
      9   QOpenGLFunctions_3_3_Compatibility::glMultiTexCoord1dv Qt5Guid        0x7fffd9203a41 
      10  QOpenGLFunctions_3_3_Compatibility::glMultiTexCoord1dv Qt5Guid        0x7fffd91d1e95 
      11  QOpenGLFunctions_3_3_Compatibility::glMultiTexCoord1dv Qt5Guid        0x7fffd91d20c2 
      12  qt_plugin_query_metadata                               qwindowsd      0x7fffd24fb8ac 
      13  qt_plugin_query_metadata                               qwindowsd      0x7fffd251fbdd 
      14  qt_plugin_query_metadata                               qwindowsd      0x7fffd2516455 
      15  UserCallWinProcCheckWow                                USER32         0x7ff84c6a6d41 
      16  DispatchClientMessage                                  USER32         0x7ff84c6a6a1c 
      17  _fnDWORD                                               USER32         0x7ff84c6b04d3 
      18  KiUserCallbackDispatcherContinue                       ntdll          0x7ff84cd3e6b4 
      19  NtUserDispatchMessage                                  win32u         0x7ff849da1744 
      20  DispatchMessageWorker                                  USER32         0x7ff84c6a6780 
      ... <More>
      

      I am fairly confident I am not scrolling the wheel when I double click Also, there is no output from the main window's wheelEvent(), nor any QEvent::wheel lines printed from event().

      Finally, the code I used for testing:

      #include <QApplication>
      #include <QDebug>
      #include <QLabel>
      #include <QListView>
      #include <QListWidget>
      #include <QMainWindow>
      #include <QStandardItem>
      #include <QStandardItemModel>
      #include <QVBoxLayout>
      
      bool flag = false;
      
      class MainWindow : public QMainWindow
      {
      protected:
          bool event(QEvent* e) override
          {
              qDebug() << e->type();
              if (flag && e->type() == QEvent::WindowActivate)
              {
                  flag = false;
              }
      
              return QMainWindow::event(e);
          }
      
          void wheelEvent(QWheelEvent* e) override
          {
              qDebug() << "wheel!";
              QMainWindow::wheelEvent(e);
          }
      };
      
      void openPopup()
      {
          auto w = new QWidget(nullptr);
          w->setFixedSize(200, 100);
          w->setLayout(new QVBoxLayout);
          w->layout()->addWidget(new QLabel("Hello"));
          w->setAttribute(Qt::WA_DeleteOnClose);
          w->show();
          flag = true;
          qDebug() << "popup opened!";
      }
      
      int main(int argc, char* argv[])
      {
          QApplication a(argc, argv);
      
          QStandardItemModel model(20, 1);
          for (int i = 0; i < model.rowCount(); ++i)
              model.setItem(i, 0, new QStandardItem("hello"));
      
          auto lv = new QListView;
          lv->setEditTriggers(QAbstractItemView::NoEditTriggers);
          lv->setModel(&model);
          QObject::connect(lv, &QAbstractItemView::doubleClicked, lv, openPopup);
      
          MainWindow d;
          d.setCentralWidget(lv);
          d.show();
      
          return a.exec();
      }
      

      Attachments

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

        Activity

          People

            anrocha André De La Rocha (Inactive)
            ow Øystein Walle
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes