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. Handling and ignoring events
Forum Updated to NodeBB v4.3 + New Features

Handling and ignoring events

Scheduled Pinned Locked Moved QML and Qt Quick
10 Posts 2 Posters 3.5k 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
    maxim.prishchepa
    wrote on last edited by
    #1

    Hello,
    I have such code:

    @StackView {
    z: -1
    id: contentView
    anchors.fill: parent
    initialItem: "my.qml"
    }

    MouseArea {
        id: slideDetector
        signal slided(int direction) // -1 left; 1 - right
        z: 100
        anchors.fill: parent 
        property int xCord : 0
        property int slideSize: parent.width / 5
        onPressed: {
            xCord = mouse.x
            console.log("onPressed: x: ", xCord)
    

    // mouse.accepted = false
    }
    onReleased: {
    var result = mouse.x - xCord
    console.log("onReleased: x: ", mouse.x)
    Math.abs(result)
    if (result >= slideSize) {
    slideDetector.slided(Math.sign(result))
    }
    mouse.accepted = false
    }

        onSlided: {
            console.log("======= Detect sliding: ", direction)
        }
    }@
    

    currently, this code can detect slideing, but elements at the StackView isn't active.
    but if i uncomment "mouse.accepted = false" signal reseased not emmite, but elements in StackView - is active.

    so, how can i mix this variant for expected results: StackView elements is active and sliding can be detected?

    tnx a lot 4 answers

    Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz).

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      Hi,

      May be "propagateComposedEvents":http://doc.qt.io/qt-5/qml-qtquick-mousearea.html#propagateComposedEvents-prop would work here.

      157

      1 Reply Last reply
      0
      • M Offline
        M Offline
        maxim.prishchepa
        wrote on last edited by
        #3

        tnx p3c0,
        unfortunately this is not help :(
        @StackView {
        id: contentView
        anchors.fill: parent
        initialItem: "my.qml"

             MouseArea {
                 propagateComposedEvents: true
                 id: slideDetector
                 signal slided(int direction) // -1 left; 1 - right
                 anchors.fill: parent
                 property int xCord : 0
                 property int slideSize: parent.width / 5
                 onPressed: {
                     xCord = mouse.x
                     console.log("onPressed: x: ", xCord)
                     controlPanel.Mous
                     mouse.accepted = true
                 }
                 onReleased: {
                     var result = mouse.x - xCord
                     console.log("onReleased: x: ", mouse.x)
        
                     if (Math.abs(result) >= slideSize) {
                         var resultValue = -1
                         if (result > 0) {
                             resultValue = 1
                         }
                         slideDetector.slided(resultValue)
                     }
                     mouse.accepted = false
                 }
        
                 onSlided: {
                     console.log("======= Detect sliding: ", direction)
                 }
             }
         }@
        

        When i put MouseArea inside StackView, onPressed isn't invoke :(

        Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz).

        1 Reply Last reply
        0
        • p3c0P Offline
          p3c0P Offline
          p3c0
          Moderators
          wrote on last edited by
          #4

          No. Keep it outside. Try following:
          @
          Rectangle {
          width: 200
          height: 400

          StackView {
              id: stack
              initialItem: view
          
              Component {
                  id: view
          
                  MouseArea {
                      Text {
                          text: stack.depth
                          anchors.centerIn: parent
                      }
                      onClicked: stack.push(view)
                  }
              }
          }
          
          MouseArea {
              anchors.fill: parent
              propagateComposedEvents: true
              onPressed: console.log("press")
              onReleased: console.log("rel")
          }
          

          }
          @

          157

          1 Reply Last reply
          0
          • M Offline
            M Offline
            maxim.prishchepa
            wrote on last edited by
            #5

            wow, almost work correct :)
            currently pressing is detected correct. but...
            at the view i have some elements like ListView, InputField etc.
            the items which contains MouseArea (i manual descrybe it at the my qml file) - pressing work correct, but standard elements isn't works. I saw them, but when i press to this element's they aren't activate... :((

            Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz).

            1 Reply Last reply
            0
            • p3c0P Offline
              p3c0P Offline
              p3c0
              Moderators
              wrote on last edited by
              #6

              Ok. Which standard elements don't work ? An example would be helpful. You can modify the example that I posted since its a minimal one.

              157

              1 Reply Last reply
              0
              • M Offline
                M Offline
                maxim.prishchepa
                wrote on last edited by
                #7

                for example scrolling at the ListView....
                how i understand from documentation, if use propagateComposedEvents then to the child mouceArea will be send only "clicked, doubleClicked and pressAndHold". How i understand scrolling will be work, if will be work event handlers on pressed and released... IMO this is not exactly what i need. BTW, currently i saw unexpected (for me perssonlay) behavior: when i press mouse at some plase in MouseArea, and then change cursore possition to some child element (for example to some ListView element, which contains other MouseArea) and then release mouse button, behavior will be same as i click to the child element. Don't know, this is bug or feature, but IMO this is little bit unexpacted :)

                Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz).

                1 Reply Last reply
                0
                • p3c0P Offline
                  p3c0P Offline
                  p3c0
                  Moderators
                  wrote on last edited by
                  #8

                  Sorry to say but I didn't quite understand what you want to say in the above post.

                  157

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    maxim.prishchepa
                    wrote on last edited by
                    #9

                    ok, try to rephrase...

                    Currently i have a StackView, which contains some element, for example ListView, this ListView contains other element let it name: "ListViewElements". At the ListViewElements i have an other MouseArea, let it name: "ListViewElementMouseArea".

                    Currently, i do like you say in http://qt-project.org/forums/viewthread/52932/#219702

                    Sliding detection - work correct.

                    But scrolling at the ListView stop to work.

                    And one more, when i press Mouse btn at the some StackView area, then hover cursor to the some ListViewElement and after that release mouse btn. i handle click() signal at the ListViewElementMouseArea.

                    that's all...

                    how i understand from the link: http://doc.qt.io/qt-5/qml-qtquick-mousearea.html#propagateComposedEvents-prop

                    if propagateComposedEvents == true then child MouseArea will be receive only click(), doubleClick and pressAndHold signals/events. i think this is a reason, why scrolling isn't work.

                    Maybe have some variants how to allow receive press and relase signals in child MouseAreas?

                    Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz).

                    1 Reply Last reply
                    0
                    • p3c0P Offline
                      p3c0P Offline
                      p3c0
                      Moderators
                      wrote on last edited by
                      #10

                      It propagates the wheel too. Modified the above example
                      @
                      import QtQuick 2.4
                      import QtQuick.Controls 1.3

                      Rectangle {
                      width: 200
                      height: 400

                      StackView {
                          id: stack
                          initialItem: view
                      
                          Component {
                              id: view
                              MouseArea {
                                  ListModel {
                                      id: model
                                  }
                                  ListView {
                                      anchors.fill: parent
                                      model: model
                                      delegate: Text {
                                          text: name
                                      }
                                  }
                                  Component.onCompleted: {
                                      for(var a=0;a<50;a++) {
                                          model.append( { "name":a } )
                                      }
                                  }
                                  onClicked: console.log("inner clicked")
                              }
                          }
                      }
                      
                      MouseArea {
                          anchors.fill: parent
                          propagateComposedEvents: true
                          onPressed: { console.log("outer press") }
                          onReleased: { console.log("outer released") }
                      }
                      

                      }
                      @

                      It detects press,release and also the ListView scrolls.

                      157

                      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