Problem with pressed/released event when touch an Item of Flickable!



  • Hi all,

    I'm using Qt 5.9.2, 32bit, with VS2017 on Win7, iiyama prolite 22" touch monitor.

    I have a problem with touch events when using Flickable.
    The Flickable contains a dragable Rectangle which has a MouseArea to get pressed/released/clicked events.

    When I click the Rectangle with the mouse everything works fine - pressed, released, clicked is called.

    But when I touch fast the Rectangle then only pressed is called but NO released, clicked.

    Whereas touch and hold a while the Rectangle then pressed, released, clicked is called as I expect (think this is Flickable.pressDelay property)

    This problem occures since I have changed from Qt 5.4.1 to 5.9.2!
    With Qt 5.4.1 everything works, pressed, released, clicked is always called when touch the Rectangle.

    Here the simple code:

    Rectangle {
        width: 420
        height: 380
        color: "lightgray"
    
        Flickable {
            id: flick
            clip: true
            width: 320; height: 280
            contentWidth: image.width; contentHeight: image.height
            pressDelay: 100
            anchors.centerIn: parent
    
            // handle events when touch/click flickable
            MouseArea {
                anchors.fill: parent
                onClicked: console.log("flick clicked")
                onPressed: console.log("flick pressed")
                onReleased: console.log("flick released")
            }
    
            // simple background image
            Image { id: image; source: "babes.jpg" }
    
            // dragable rectangle
            Rectangle {
                width: 70; height: 70
                color: "red"
    
                // handle events when touch/click dragable item
                MouseArea {
                    drag.target: parent
                    anchors.fill: parent
    
                    onClicked: {
                        console.log("rect clicked")
                    }
    
                    onPressed: {
                        console.log("rect pressed")
                    }
    
                    onReleased: {
                        console.log("rect released")
                    }
                }
            }
        }
    }
    

    I know, Qt has reworked touch/mouse event handling (synthesized events...), MultiTouchPointArea, ....

    But this seems like a bug! Has anybody an idea how I can fix that?

    thx



  • It might be related to this bug: https://bugreports.qt.io/browse/QTBUG-62424?
    I am facing similar problem but only with Qt 5.10 (5.9 seems to work fine).



  • Maybe you can file a bug report so that the problem gets addressed?



  • Solved!

    Re-designed my code. Seems the Qt 5.4.1 had a bug for mouse/touch event handling of items inside Flickable. Therefore were a lot of workarounds implemented.

    Now I set the Flickable.pressDelay to 0, means Flickable is stealing events when detect a flick/pinch gesture. At this time underlaying MouseArea's are informed with MouseArea.pressed/cancelled. According docs this is a good time to "reset" some custom logic.

    Example:
    Flickable contains some dragable items. Flickable's content is scaled/zoomed an can be flicked. When press/hold a dragable item the item should be dragged and not the flickable should flick.

    For this issue I set the items by default to NOT dragable. When an item is pressed I will start an "pressed timer". If we flick it item's MouseArea.cancelled() is called and I check the timer is elapsed. If running I say "goodby, its a flick gesture". If elapsed I set the Flickable.interactive = false and enable item dragging. Then I can drag the item free and Flickable does nothing. Also items released/clicked is called.


Log in to reply
 

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