谢谢大家的指教,还是不行。
调试了一下:貌似 QModelIndex current = tree.currentIndex(); 返回的是QModelIndex(-1,-1,0x0,QObject(0x0) )。所以setCurrentIndex(current, QItemSelectionModel::SelectCurrent);就没用了。
怎么才能获得“aa"这项的index呢?
借用alexltr的方法,改进一下,也是不行的。
QModelIndex current = tree.rootIndex();
qDebug() << current;
QString path = model.filePath(current);
qDebug() << "a::::"<<path;
path += "/aa";
QModelIndex cc = model.index(0, 0, current);
// QModelIndex cc = model.index(path, 0);
qDebug() << cc;
path = model.filePath(cc);
qDebug() << "a::::"<<path;
tree.setCurrentIndex(cc);