Phantom double clicks from MouseArea on Android

641 views Asked by At

While testing out an application on Android I noticed something funky going on. A double click event handler has been triggering without any double clicks occurring on that particular item.

Trying to isolate the issue I discovered that pretty much every chain of clicks rapid as a double click on regardless what two objects would cause the second click on the second object to register as a double click, when in fact it is just a single click.

Below is an example consisting of a row of 3 randomly colored rectangles, each one with a mouse area inside of it. The double click of each mouse area is rigged to set the parent rectangle's color to a different random color. Clicking rapidly two different rectangles under android triggers a double click and a color change for the second. This does not happen on Windows or Ubuntu Linux.

Window {
  id: main
  visible: true
  width: 400
  height: 400
  title: qsTr("Hello World")

  Row {
    Rectangle {
      width: main.width * .33
      height: main.height
      color: Qt.rgba(Math.random(), Math.random(), Math.random(), 1)
      border.color: "black"
      border.width: 2
      MouseArea {
        anchors.fill: parent
        onDoubleClicked: parent.color = Qt.rgba(Math.random(), Math.random(), Math.random(), 1)
      }
    }
    Rectangle {
      width: main.width * .33
      height: main.height
      color: Qt.rgba(Math.random(), Math.random(), Math.random(), 1)
      border.color: "black"
      border.width: 2
      MouseArea {
        anchors.fill: parent
        onDoubleClicked: parent.color = Qt.rgba(Math.random(), Math.random(), Math.random(), 1)
      }
    }
    Rectangle {
      width: main.width * .33
      height: main.height
      color: Qt.rgba(Math.random(), Math.random(), Math.random(), 1)
      border.color: "black"
      border.width: 2
      MouseArea {
        anchors.fill: parent
        onDoubleClicked: parent.color = Qt.rgba(Math.random(), Math.random(), Math.random(), 1)
      }
    }
  }
}

It looks as if the "previous click" or whatever property that's supposed to be used to detect double clicks is shared between different mouse areas instead of being per mouse area. The issue manifests in both Qt 5.7 and 5.7.1.

It definitely looks like my 10th discovered Qt bug this year, but I still feel like asking on the odd chance someone knows what's going on and how to fix it, because I need this fixed, and the Qt bugreport process is not speedy. So any ideas are more than welcome.

1

There are 1 answers

0
dtech On

Until there is a better answer with an actual solution, it may be useful to know that it is possible to somewhat mitigate the devastating effect this issue has on user experience by reducing the global interval for double click detection.

By default it is the rather lethargic 500 msec. I found out that by reducing it to 250 msec helps to avoid over 90% of the incorrect double clicks:

QGuiApplication app(argc, argv);
app.styleHints()->setMouseDoubleClickInterval(250);

Additionally, there is a quick and hacky qml-only way to create a "fixed" copy of MouseArea:

// MArea.qml
Item {
  id: main
  property alias mouseX : ma.mouseX
  property alias mouseY : ma.mouseY
  property alias acceptedButtons: ma.acceptedButtons
  // etc aliases
  signal clicked(var mouse)
  signal doubleClicked(var mouse)
  // etc signals, function accessors
  MouseArea {
    id: ma
    property real lClick : 0
    anchors.fill: parent
    onClicked: {
      var nc = Date.now()
      if ((nc - lClick) < 500) main.doubleClicked(mouse)
      else main.clicked(mouse)
      lClick = nc
    }
  }
}

This one actually works as intended and can be made almost entirely "plug and play" compatible with the original one.