Hi all,

For some reason, I need to propagate "Pressed event" to lower MouseArea. In the meanwhile, I still want to handle "Clicked event" after handling "Pressed event".
It turns out that I cannot achieve both criteria together.

If I set mouse.accepted = false during handling redBlock's onPressed() as example code below, I can successfully propagate "Pressed event" to blueBlock. However, this will disable the handling of "Clicked event" in redBlock which I don't think it makes any sense.

From QT document,
pressed(MouseEvent mouse):
When handling this signal, use the accepted property of the mouse parameter to control whether this MouseArea handles the press and all future mouse events until release.The default is to accept the event and not allow other MouseAreas beneath this one to handle the event. If accepted is set to false, no further events will be sent to this MouseArea until the button is next pressed.

I don't understand why they design like this. "If accepted is set to false, no further events will be sent to this MouseArea until the button is next pressed." doesn't make any sense to me. When you set mouse.accepted = false, you expect that the other mouse handler can take over this mouse event. Does anyone know why they design such weird mechanism for onPressed?

Qt Code:
  1. import QtQuick 2.4
  2. import QtQuick.Controls 1.3
  3. import QtQuick.Window 2.2
  4.  
  5. ApplicationWindow {
  6. title: qsTr("Hello World")
  7. width: 1280
  8. height: 720
  9. visible: true
  10.  
  11. Rectangle{
  12. id: blueBlock
  13. width: parent.width ; height: parent.height;
  14. color: "blue"
  15. MouseArea{
  16. anchors.fill: parent
  17. onPressed:{
  18. console.log("Blue block is pressed")
  19. }
  20. onClicked: {
  21. console.log("Blue block is clicked")
  22. }
  23. }
  24. }
  25. Rectangle{
  26. id: redBlock
  27. width: parent.width/2; height: parent.height/2
  28. anchors.centerIn: parent
  29. color: "red"
  30. MouseArea{
  31. anchors.fill: parent
  32. onPressed:{
  33. console.log("Red block is pressed")
  34. mouse.accepted = false
  35. }
  36. onClicked: {
  37. console.log("Red block is clicked")
  38. }
  39.  
  40. }
  41. }
  42. }
To copy to clipboard, switch view to plain text mode