我有一个QAbstractListModel
C++ 模型类和一个 QtQuick2 ListView
。
出于测试目的,我还创建了一个 QtWidgetsQListView
并附加到相同的模型以进行比较。
我想告诉视图应该使用覆盖的项目禁用哪些项目QAbstractListModel::flags()
,如下例所示:
Qt::ItemFlags flags(const QModelIndex& index) const
{
Qt::ItemFlags f = QAbstractListModel::flags(index);
if(index.isValid())
{
f |= Qt::ItemIsUserCheckable;
if(index.row() % 3 == 2)
f &= ~Qt::ItemIsEnabled;
}
return f;
}
遗憾的是 QtQuick2 ListVie 完全忽略了这个标志,而 QListView 没有:
我希望 item2 和 item5 在 QtQuick2 中也被禁用。如何做到这一点?