简体   繁体   中英

QML Tableview display value from selected row

I have a tableview and I want to open a dialog box on onPressAndHold on a row and display the value of the cell of the row "orderNumber". But i get the Error message: ReferenceError: row is not defined

TableView {
    id: tableviewopenorders
    height: 180
    clip: false
    visible: true

    onPressAndHold: oocanceldialog.open()


    TableViewColumn {
        id: orderNumberColumn
        role: "orderNumber"
        title: "Order Number"
    }

    model: openordersModel
}

ListModel {
    id: openordersModel

    ListElement {
        orderNumber: "1223455"

    }
    ListElement {
        orderNumber: "111111"

    }
}


Dialog {
    id: oocanceldialog
    title: "Cancel confirmation"
    standardButtons: Dialog.Ok | Dialog.Cancel
    x: (parent.width - width) / 2
    y: (parent.height - height) / 2
    Label {
        text: openordersModel.get(row).orderNumber

    }

    onAccepted: console.log("Ok clicked")
    onRejected: oocanceldialog.close()
}

row exists in the context of onPressAndHold , so it does not exist outside of it, to get the row we must use the currentRow attribute of the TableView :

currentRow : int

The current row index of the view. The default value is -1 to indicate that no row is selected.

In your case:

Label {
    text: openordersModel.get(tableviewopenorders.currentRow).orderNumber
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM