Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. MouseArea.pressed name collision
Forum Updated to NodeBB v4.3 + New Features

MouseArea.pressed name collision

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 2 Posters 780 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    guycook
    wrote on last edited by
    #1

    Hi all,

    I am trying to access the MouseArea.pressed signal as part of a chain of signals but have so far not been able to as there also exists a boolean property on MouseArea with the same name. Here's a minimal test case you can run with qmlscene and observe the console output to see the problem.

    @
    import QtQuick 2.0

    Rectangle {
    id: root
    color: '#CCCCCC'

    width: 250
    height: 150
    
    Rectangle {
        color: 'blue'
        x: 50; y: 50; width: 50; height: 50;
        MouseArea {
            id: bluemouse
            anchors.fill: parent
            onClicked: {
                console.log('click on blue');
                redmouse.doubleClicked(mouse);
            }
            onPressed: {
                console.log('pressed on blue');
            }
        }
    }
    
    Rectangle {
        color: 'red'
        x: 150; y: 50; width: 50; height: 50;
        MouseArea {
            id: redmouse
            anchors.fill: parent
            onClicked: {
                console.log('click on red');
                bluemouse.pressed(mouse);
            }
            onDoubleClicked: {
                console.log('double on red');
            }
        }
    }
    
    Component.onCompleted: {
        redmouse.pressAndHold.connect(redmouse.doubleClicked)
        bluemouse.pressAndHold.connect(bluemouse.pressed) // <- Throws error
        // bluemouse.pressed.connect(bluemouse.doubleClicked) <- Also throws error
    }
    

    }
    @

    Immediately on parsing there is an error in Component.onCompleted stating that bluemouse.pressed isn't a function.
    Then there is also an error when clicking on red where the signal isn't forwarded to the bluemouse.pressed handler, though clicking on the blue will trigger redmouse.doubleClicked as expected.

    Is there any workaround for this, or indeed is it something that should be submitted to the bug tracker?

    Thanks

    1 Reply Last reply
    0
    • T Offline
      T Offline
      Torgeir
      wrote on last edited by
      #2

      A workaround could be to add to the MouseArea another signal with a name that doesn't conflict.

      For ex:
      @
      MouseArea {
      id: bluemouse
      signal mousePressed(MouseEvent mouse)
      onPressed: bluemouse.mousePressed(mouse)
      }
      @

      This way you could connect() to mousePressed and not have the naming conflict.

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved