Frage

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

War es hilfreich?

Lösung

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

Andere Tipps

Yow must to define the role in te QAbstractItemModel.

QHash YourClassModel::roleNames() const {

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

}

Try to use styleData.value:

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

It's described here (look for itemDelegate property)

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top