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. Mouse event for MouseArea
Forum Updated to NodeBB v4.3 + New Features

Mouse event for MouseArea

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
4 Posts 3 Posters 410 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.
  • R Offline
    R Offline
    RobM
    wrote on last edited by
    #1

    Is there anyway to detect an over all event in a MouseArea? For instance, I have a MouseArea, and I am performing actions at each event such as onClicked or onPressed, but I want to fire a signal if either onPressed or onClicked happens without putting the signal in code on both events, is that possible?

    sierdzioS 1 Reply Last reply
    0
    • R RobM

      Is there anyway to detect an over all event in a MouseArea? For instance, I have a MouseArea, and I am performing actions at each event such as onClicked or onPressed, but I want to fire a signal if either onPressed or onClicked happens without putting the signal in code on both events, is that possible?

      sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      @RobM said in Mouse event for MouseArea:

      Is there anyway to detect an over all event in a MouseArea? For instance, I have a MouseArea, and I am performing actions at each event such as onClicked or onPressed, but I want to fire a signal if either onPressed or onClicked happens without putting the signal in code on both events, is that possible?

      Yes, use a function:

      MouseArea {
        function doSomething() {
          // Something
        }
      
        onClicked: doSomething()
        onPressed: doSomething()
      }
      

      (Z(:^

      1 Reply Last reply
      0
      • R Offline
        R Offline
        RobM
        wrote on last edited by RobM
        #3

        I should have been more specific. Here is what I have:

        signal mouseEvent
        
        MouseArea
        {
          onPressed: do stuff
          onReleased: do stuff
          onClicked: do stuff
          onPressAndHold: do stuff
          onPositionChanged: do stuff
          onWheel: do stuff
        }
        

        so in order to trigger mouseEvent I would have to add it to each event like so:

        signal mouseEvent
        
        MouseArea
        {
          onPressed: mouseEvent()
          onReleased: mouseEvent()
          onClicked: mouseEvent()
          onPressAndHold: mouseEvent()
          onPositionChanged: mouseEvent()
          onWheel: mouseEvent()
        }
        

        but, I was hoping I might be able to avoid that somehow, for instance:

        signal mouseEvent: mouseArea.event //<-- or something like this "event" isn't real... I made it up, but I was hoping for something like that.
        MouseArea
        {
          id: mouseArea
        
          onPressed: do stuff
          onReleased: do stuff
          onClicked: do stuff
          onPressAndHold: do stuff
          onPositionChanged: do stuff
          onWheel: do stuff
        }
        

        but, I can't think of a way. If I could do it this way the I could reduce the calls to mouseEvent to one instead of (in this instance) 6.

        fcarneyF 1 Reply Last reply
        0
        • R RobM

          I should have been more specific. Here is what I have:

          signal mouseEvent
          
          MouseArea
          {
            onPressed: do stuff
            onReleased: do stuff
            onClicked: do stuff
            onPressAndHold: do stuff
            onPositionChanged: do stuff
            onWheel: do stuff
          }
          

          so in order to trigger mouseEvent I would have to add it to each event like so:

          signal mouseEvent
          
          MouseArea
          {
            onPressed: mouseEvent()
            onReleased: mouseEvent()
            onClicked: mouseEvent()
            onPressAndHold: mouseEvent()
            onPositionChanged: mouseEvent()
            onWheel: mouseEvent()
          }
          

          but, I was hoping I might be able to avoid that somehow, for instance:

          signal mouseEvent: mouseArea.event //<-- or something like this "event" isn't real... I made it up, but I was hoping for something like that.
          MouseArea
          {
            id: mouseArea
          
            onPressed: do stuff
            onReleased: do stuff
            onClicked: do stuff
            onPressAndHold: do stuff
            onPositionChanged: do stuff
            onWheel: do stuff
          }
          

          but, I can't think of a way. If I could do it this way the I could reduce the calls to mouseEvent to one instead of (in this instance) 6.

          fcarneyF Offline
          fcarneyF Offline
          fcarney
          wrote on last edited by
          #4

          @RobM
          You could abstract it:
          Put in AllEventMouseArea.qml

          MouseArea {
            property var allfunc
            onPressed: allfunc()
            onReleased: allfunc()
            onClicked: allfunc()
            onPressAndHold: allfunc()
            onPositionChanged: allfunc()
            onWheel: allfunc()
          }
          

          Then in other code:

          AllEventMouseArea {
            func: {
              // do stuff
            }
          }
          

          C++ is a perfectly valid school of magic.

          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