简体   繁体   中英

How to access data in QML TableViewColumn delegate?

How to access the current item in a TableViewColumn ?

TableView {
    id: atcTableView
    model: myatclist
    ...
    TableViewColumn {
        ...
    }
    TableViewColumn {
        id: atcTableViewColFreq
        role: "frequency"
        title: "Frequency"
        width: 120
        delegate: Component {
            Text {
                text: "Freq is " + currentItem / model / model.frequency
            }
        }
    }

As of this similar question " How do you access the roles of the currentItem from a listview in QML? " I have tried all kind of combinations model , modelData , currentItem , and something like model.role .

If I remove the delegate entirely, frequency displays correctly. Model is based on QAbstractListModel . Any hints?

Btw, can I see in QML debugging what properties are available in a delegate?

-- Edit based on Kakadu's comment --

        delegate {
            Text {
                text: "freq is " + frequency
            }
        }

gives me: ReferenceError: frequency is not defined

delegate: Text { text: view.model.get(styleData.row).frequency }

Try to use styleData.value:

delegate: {
   Text { text: styleData.value }
}

It's described here (look for itemDelegate property)

Yow must to define the role in te QAbstractItemModel.

QHash YourClassModel::roleNames() const {

 roles[Qt::UserRole + 1] = "frequency"; return roles;

}

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