我不知道为什么当我尝试插入Qt::UserRole
项目QTreeView
时它总是返回 false 但当我输入时却没有,Qt::EditRole
这是代码:
void TreeVieweX::insertRow(QString& slink)
{
QModelIndex index = this->selectionModel()->currentIndex();
QAbstractItemModel *model = this->model();
int iRowCount = this->model()->rowCount();
if (!model->insertRow(iRowCount, index.parent()))
return;
QModelIndex child = model->index(iRowCount,0, index.parent());
bool bEditRole = model->setData(child, QVariant(slink), Qt::EditRole); // working great can fetch the data later
QHash<QString, QVariant> indexSelectedMap;
indexSelectedMap.insert("site_name",QVariant(slink));
QMap<int, QVariant> roles;
roles.insert(Qt::UserRole,indexSelectedMap);
bool bUserRole = model->setItemData( index.parent(),roles); //returns false , cant fetch data later
}