Handling and ignoring events



  • 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


  • Moderators

    Hi,

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



  • 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 :(


  • Moderators

    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")
    }
    

    }
    @



  • 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... :((


  • Moderators

    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.



  • 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 :)


  • Moderators

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



  • 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?


  • Moderators

    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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.