这是一个创建于 2092 天前的主题,其中的信息可能已经有所发展或是发生改变。
试了好多方式,
使用这个 combobox->view()->selectionModel()->select(index,QItemSelectionModel::SelectCurrent)也不行
第 1 条附言 · 2019-01-16 14:17:23 +08:00
解决了,用 setcurrentText 只能设置第一层节点,所以自己实现了下
``` cpp
void TreeCombobox::setCurText(QString text)
{
QAbstractItemModel *model = this->view()->model();
QModelIndexList Items = model->match(model->index(0, 0),Qt::DisplayRole,QVariant::fromValue(text), 2, Qt::MatchRecursive); // look *
for(QModelIndex index : Items){
this->setRootModelIndex(index.parent());
this->setModelColumn(index.column());
this->setCurrentIndex(index.row());
this->setRootModelIndex(QModelIndex());
this->view()->setCurrentIndex(index);
}
}
```