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. Invoke onPressed from another function within a qml
Forum Updated to NodeBB v4.3 + New Features

Invoke onPressed from another function within a qml

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
3 Posts 2 Posters 619 Views 2 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.
  • FlacoDanzigerF Offline
    FlacoDanzigerF Offline
    FlacoDanziger
    wrote on last edited by
    #1

    I am writing a program using qml. and I need to invoke the mouseArea onPressed fucintion within my function in QML. does anyone know how to do it?
    My second question is how to change the mouse position (x,y) from within qml?

    Thanks

    ? 1 Reply Last reply
    0
    • FlacoDanzigerF FlacoDanziger

      I am writing a program using qml. and I need to invoke the mouseArea onPressed fucintion within my function in QML. does anyone know how to do it?
      My second question is how to change the mouse position (x,y) from within qml?

      Thanks

      ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      Hi! @FlacoDanziger said:

      I need to invoke the mouseArea onPressed fucintion within my function in QML

      import QtQuick 2.6
      import QtQuick.Controls 1.5
      
      ApplicationWindow {
          visible: true
          width: 640
          height: 480
          title: qsTr("Hello World")
      
          Rectangle {
              id: myRectangle
              width: 300
              height: 300
              anchors.centerIn: contentItem
              color: "black"
              MouseArea {
                  id: myMouseArea
                  anchors.fill: parent
                  onPressed: myRectangle.color = "orange"
              }
          }
      
          Button {
              anchors.bottom: contentItem.bottom
              text: "Press"
              onClicked: {
                  var ma = Qt.MouseEvent
                  myMouseArea.onPressed(ma)
              }
          }
      }
      
      1 Reply Last reply
      0
      • FlacoDanzigerF Offline
        FlacoDanzigerF Offline
        FlacoDanziger
        wrote on last edited by
        #3

        @Wieland said:

        var ma = Qt.MouseEvent
        myMouseArea.onPressed(ma)

        Thanks this worked

        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