简体   繁体   English

所选行的QML Tableview显示值

[英]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". 我有一个表格视图,我想在一行的onPressAndHold上打开一个对话框,并显示“ orderNumber”行的单元格值。 But i get the Error message: ReferenceError: row is not defined 但我收到错误消息: ReferenceError:未定义行

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 : row存在于onPressAndHold的上下文中,因此它不存在于其外部,要获取该行,我们必须使用TableViewcurrentRow属性:

currentRow : int currentRow:int

The current row index of the view. 视图的当前行索引。 The default value is -1 to indicate that no row is selected. 默认值为-1,表示未选择任何行。

In your case: 在您的情况下:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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