我正在使用QTreeView和QFileSystemModel创建文件浏览器。必须选择它,然后将树自动滚动到所选项目。但是如果没有键盘,它无法自动滚动。
QString strFile = "/usr/bin/qmake";
QFileInfo fi(strFile);
QString dirFile = fi.dir().absolutePath();
QFileSystemModel model;
model.setRootPath("/");
model.setFilter(QDir::AllEntries | QDir::NoDotAndDotDot);
QTreeView view;
view.setModel(&model);
tree.setCurrentIndex(model.index(strFile));
tree.scrollTo(model.index(strFile));
view.show();
执行以上代码时,滚动是顶部,但是文件已选择。
不滚动到所选项目有什么问题?