TableView rowDelegate how to take row index?



  • import QtQuick 2.2
    import QtQuick.Controls 1.2
    import QtQuick.Controls 2.0
    import QtQuick.Dialogs 1.2
    
    TableView {
            id: tvMain
            
           rowDelegate: Rectangle {
                id: rdRow
                border.width: {
                    console.log("rowDelegate", styleData.row, styleData.value,
                                JSON.stringify(styleData) )
                    return 0
                }
    

    output is

    qml: rowDelegate undefined undefined {"objectName":"","alternate":true,"selected":false,"hasActiveFocus":false,"pressed":false}
    qml: rowDelegate undefined undefined {"objectName":"","alternate":false,"selected":false,"hasActiveFocus":false,"pressed":false}
    

    so, my question is:
    how I can take row index from rowDelegate? Looks like styleData.row not available(
    thanks



  • hmm, when row selected property "row" - available

    qml: rowDelegate {"objectName":"","row":0,"alternate":false,"selected":true,"hasActiveFocus":false,"pressed":true}
    qml: rowDelegate {"objectName":"","row":0,"alternate":false,"selected":true,"hasActiveFocus":false,"pressed":false}
    
    


  • but in MouseArea in row delegate styleData.row - available
    following code show right click menu for row in place where mouse clicked

    rowDelegate: Rectangle {
                id: rdRow
                height: 30
    
                MouseArea {
                    id: maRow
                    anchors.fill: parent
                    acceptedButtons: Qt.RightButton
                    onClicked: {
                        console.log("right click on row", styleData.row, mouseX,
                                    mouseY, tvMain.flickableItem.contentY)
                        if ((styleData.row || (styleData.row === 0))
                                && (mouse.button === Qt.RightButton)) {
                            currentRowIdxForMenu = styleData.row
                            cmRow.x = mouseX
                            cmRow.y = mouseY + styleData.row * rdRow.height
                                    - tvMain.flickableItem.contentY
                            cmRow.open()
                        }
                    }
                }
            }