onWheel not working in Flickable



  • Hello i am trying to implement mouse wheel scrolling over Flickable area. Rectangle which is inside Flickable is kind a menu content container. And it holds menu items which number is changing. So i used Flickable to get that container scrolling but it works when you press a mouse and drag but scroll wheel is not working. I tried to put Item element outside flickable and wrap everything up but then flickable is not working.

    Here is the code

    import QtQuick 2.1
    
    Flickable {
        signal drag(string mouseY)
        id: flickable
        contentWidth: itemscontent.width
        contentHeight: 712
        flickableDirection: Flickable.VerticalFlick
        clip: true
        width: parent.width
        interactive: true
        boundsBehavior: Flickable.StopAtBounds
        anchors.fill: parent
    
        MouseArea {
            anchors.fill: parent
            onWheel: flickable.drag(mouse.y)
        }
        Rectangle {
            id:itemscontent
            anchors.centerIn: parent
            width:parent.width
            color: "transparent"
        }
    }
    

    Thank you.

    Edited: Please surround the code with ``` (3 backticks)


  • Moderators

    Hi @ajvanho6 and Welcome
    Flickable will allow flicking on mouse wheel events or otherwise automatically if the contentWidth and contentHeight is greater than it's width and height. You don't have to add a MouseArea explicitly.
    Try following example:

    import QtQuick 2.4
    
    Flickable {
        id: flickable
        clip: true
        width: 200
        height: 480
        contentWidth: itemscontent.width
        contentHeight: itemscontent.height
        boundsBehavior: Flickable.StopAtBounds
    
        Rectangle {
            id:itemscontent
            anchors.centerIn: parent
            width: 100
            height: 680
            color: "red"
            Text {
                anchors.centerIn: parent
                text: "MyText"
            }
        }
    }
    


  • Hello @p3c0 thank you for helping. Unfortunately i did try as you suggested but no luck so far. Mouse wheel is not responding it just wok when i press and drag Don't know what could be the issue. I must check other files of my app maybe something is interfering with this file.



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