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

Ungrab does not work for Input Handlers

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 5.13.1
    • None
    • Dell XPS 15 9560, Windows 10
    • Windows

    Description

      I created a small example to show the problem:

      #include "UiHelper.h"
      
      #include <QCoreApplication>
      #include <QDebug>
      
      UiHelper::UiHelper(QObject* parent)
          : QObject(parent) {}
      
      void UiHelper::ungrabMouseAndTouchPoints(QQuickItem* item, bool recursive) const {
          if (item != nullptr) {
              qDebug() << "Ungrab:" << item << item->objectName();
              item->ungrabMouse();
              item->ungrabTouchPoints();
              if (recursive) {
                  for (auto* child : item->childItems()) {
                      this->ungrabMouseAndTouchPoints(child, recursive);
                  }
              }
          }
      }
      
      import QtQuick 2.12
      import QtQuick.Controls 2.5
      import QtQuick.Layouts 1.3
      
      import Ui 1.0
      
      ApplicationWindow {
          visible: true
          width: 640
          height: 480
      
          ColumnLayout {
              anchors.centerIn: parent
      
              Button {
                  id: button
      
                  text: "Button"
                  background: Rectangle {
                      color: button.pressed ? "orange" : "lightGrey"
                  }
              }
              MouseArea {
                  id: mouseArea
      
                  implicitWidth: 200
                  implicitHeight: 100
      
                  Rectangle {
                      anchors.fill: parent
                      color: mouseArea.pressed ? "orange" : "lightGrey"
      
                      Label {
                          anchors.centerIn: parent
                          text: "MouseArea"
                      }
                  }
              }
              Item {
                  id: tapHandlerContainer
      
                  implicitWidth: 200
                  implicitHeight: 100
      
                  Rectangle {
                      anchors.fill: parent
                      color: tapHandler.pressed ? "orange" : "lightGrey"
      
                      Label {
                          anchors.centerIn: parent
                          text: "TapHandler"
                      }
                  }
                  TapHandler {
                      id: tapHandler
      
                      gesturePolicy: TapHandler.ReleaseWithinBounds
                  }
              }
          }
      
          Timer {
              running: true
              interval: 4000
              repeat: true
              onTriggered: {
                  UiHelper.ungrabMouseAndTouchPoints(button, false);
                  UiHelper.ungrabMouseAndTouchPoints(mouseArea, false);
                  UiHelper.ungrabMouseAndTouchPoints(tapHandlerContainer, false);
                  console.debug("----");
              }
          }
      }
      

       

      To reproduce the problem press and hold Button or MouseArea or TapHandler. 

      At a constant interval, the timer tries to take the grab from these items. 

      This, however, does not work for parent of TapHandler.

      In my opinion, it makes sense for all Input Handlers to stop grabbing if these methods were called on their parent Item.

      Otherwise, it is for example  not possible to cancel a gesture. (see https://bugreports.qt.io/browse/QTBUG-78248)

      Attachments

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

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            permotion88 Karol Polak
            Votes:
            2 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes