QFileSystemModel
具有以下data
函数:
Variant QFileSystemModel::data(const QModelIndex &index, int role) const
{
Q_D(const QFileSystemModel);
if (!index.isValid() || index.model() != this)
return QVariant();
switch (role) {
case Qt::EditRole:
case Qt::DisplayRole:
switch (index.column()) {
case 0: return d->displayName(index);
case 1: return d->size(index);
case 2: return d->type(index);
case 3: return d->time(index);
我想知道如何访问 DisplayRole
并在 QML TableViewColumn
中指定我想要的列。
我想用在
TableView {
model: fileSystemModel
TableViewColumn {
role: //what comes here?
}
}
最佳答案
如果您想在委托(delegate)中访问,您必须使用返回 QModelIndex
的 styleData.index
并将角色的值传递给它,在本例中为 Qt::DisplayRole
根据docs是 0
:
view.model.data(styleData.index, 0)
如果知道父级的行、列和QModelIndex:
view.model.data(view.model.index(row, colum, ix_parent), 0)
关于c++ - 如何访问 Qt::DisplayRole 并在 TableView 中指定列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50218276/