Important: Please read the Qt Code of Conduct -

QT force ListView to beginning after suspending mouse input

  • I am running a qt application on an embedded linux display. When a function is called, I suspend the mouse input temporarily. When this happens, our listview will get stuck between 2 items. What I want to happen is for the listview to return to the beginning element. Is there any way I can do this? Here is my code below that I have tried:


    void MyApp::tempDisableTouch()

    ListView {
        id: flickable
        property bool indexChanged: false
        anchors.fill: parent
        focus: true
        highlightRangeMode: ListView.StrictlyEnforceRange
        orientation: ListView.Horizontal
        snapMode: ListView.SnapOneItem
        boundsBehavior: Flickable.StopAtBounds
        flickableDirection: Flickable.HorizontalFlick
        model: list
        onContentXChanged: {
            if (myApp.isTouchDisabled) {
                flickable.positionViewAtIndex(0, ListView.Beginning);

    From my understanding, positionViewAtIndex inside onContentXChanged should be what I want to use to force the listview to return to the first element. However, there are occasions when the listview will get stuck in the middle of index 0 and index 1. Is there something I am missing? Anything else I can try to force the lisview to return to the first element after disabling the mouse. Any help would be greatly appreciated.