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. Qml set action dynamically
Qt 6.11 is out! See what's new in the release blog

Qml set action dynamically

Scheduled Pinned Locked Moved Solved QML and Qt Quick
2 Posts 2 Posters 422 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.
  • M Offline
    M Offline
    MartinD
    wrote on last edited by
    #1

    Hi,
    I have a mouseArea:

    MouseArea {
       id: myMouseArea
    }
    

    How I can set onClicked action for myMouseArea outside this element? I want to set onClicked action dynamically for myMouseArea e.g. in Component.onCompleted section of my qml file.

    1 Reply Last reply
    0
    • ODБOïO Offline
      ODБOïO Offline
      ODБOï
      wrote on last edited by
      #2

      hi @MartinD ,

      You can use connect() fucntion

        function fnc(){
              console.log("click")
          }
      
          Component.onCompleted:{
              ms.clicked.connect(fnc)
          }
      
      
          Rectangle{
              height: 90
              width: 90
              color: "grey"
              anchors.centerIn: parent
              MouseArea{
                  id:ms
                  anchors.fill: parent
              }
          }
      
      1 Reply Last reply
      1

      • Login

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