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

QQuickWidget: Mouse double-click problem

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 5.12.2, 5.12.4
    • Quick: Widget
    • None
    • All

    Description

      According to Qt event system, mouse double-clicking turn into the following sequence of events:
      (1)QEvent::MouseButtonPress -> (2)QEvent::MouseButtonRelease -> (3)QEvent::MouseButtonPress -> (4)QEvent::MouseButtonDblClick -> (5)QEvent::MouseButtonRelease (See link title for details).
      For QtWidgets subsystem (3) event generates after (4):

      // QWidget.cpp
      void QWidget::mouseDoubleClickEvent(QMouseEvent *event)
      {
          mousePressEvent(event);
      }
      

      Thus, reimplementation of QQuickwidget::mouseDoubleClickEvent send additional QEvent::MouseButtonPress event to QtQuick subsystem using the above order, BUT flags of this event not marked as Qt::MouseEventCreatedDoubleClick ---> at QtQuick Scene Graph side it is impossible to determine whether the (3) event is related to mouse double-clicking.

      To solve the problem it is necessary to mark event in the following way:

      // Sample widget derived from QQuickWidget
      void QuickWidget::mouseDoubleClickEvent(QMouseEvent *e)
      {
      	QMouseEvent pressEvent(QEvent::MouseButtonPress, e->localPos(), e->localPos(), e->screenPos(),
      						   e->button(), e->buttons(), e->modifiers(), e->source());
      
      	// --->
      	QGuiApplicationPrivate::setMouseEventFlags(&pressEvent, pressEvent.flags() | Qt::MouseEventCreatedDoubleClick); // Bug FIXER!!!
      	// --->
      
      	QGuiApplication::sendEvent(quickWindow(), &pressEvent);
      	e->setAccepted(pressEvent.isAccepted());
      
      	QMouseEvent mappedEvent(e->type(), e->localPos(), e->localPos(), e->screenPos(),
      							e->button(), e->buttons(), e->modifiers(), e->source());
      	QGuiApplication::sendEvent(quickWindow(), &mappedEvent);
      }
      

      Sample is attached in the archive

      Attachments

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

        Activity

          People

            tvete Paul Olav Tvete
            amuralev Artem Muralev
            Votes:
            6 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes