Qt Qml Interactive Grid View + Mouse Area not working



  • I have an Interactive Grid View with a Mouse Area.

    It works perfectly fine. But, If I flick the Grid View after adding dynamic rows, the index selected are being wrong.

    Please help me out. I hope the problem is with Mouse area.

    @

    GridView {

        property int firstIndexDrag: -1
    
        x: 22
    
        y: 139
    
        id: grid
    
        interactive: loc.currentId == -1
    
        width: 734
    
        height: 775
    
        highlightFollowsCurrentItem: true
    
        snapMode: GridView.NoSnap
    
        keyNavigationWraps: false
    
        smooth: true
    
        contentHeight: 1500
    
        anchors.rightMargin: 12
    
        anchors.leftMargin: 22
    
        contentWidth: 0
    
        anchors.topMargin: 139
    
        anchors.bottomMargin: 110
    
        anchors.fill: parent
    
        cellWidth: 237; cellHeight: 118
    
    
    
    
    
        model: widgetModel
    
        delegate: widgetdelegate
    
    
    
             MouseArea {
    
            id: loc  
    
            width: grid.width
    
            height: 1500
    
            smooth: true
    
            visible: true
    
            clip: false
    
            anchors.fill: parent
    
            property int currentId: -1                       // Original position in model
    
            property int newIndex                            // Current Position in model
    
            property int index: grid.indexAt(mouseX, mouseY)
    
            property bool active: true
    
            onPressAndHold:
    
            {
    
                currentId = widgetModel.get(newIndex = index).gridId
    
            }
    
            onReleased: loc.currentId = -1
    
            onMousePositionChanged:
    
                if (loc.currentId != -1 && index != -1 && index != newIndex)
    
                {
    
                    widgetModel.move(newIndex, newIndex = index, 1)
    
                }@

Log in to reply
 

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