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 603 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.
  • F Offline
    F Offline
    FlacoDanziger
    wrote on 9 May 2016, 12:37 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 9 May 2016, 12:52
    0
    • F FlacoDanziger
      9 May 2016, 12:37

      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 9 May 2016, 12:52 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
      • F Offline
        F Offline
        FlacoDanziger
        wrote on 9 May 2016, 15:44 last edited by
        #3

        @Wieland said:

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

        Thanks this worked

        1 Reply Last reply
        0

        1/3

        9 May 2016, 12:37

        • Login

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