PDA

View Full Version : Qtreeview : To get File name and path from Tree View



augusbas
4th March 2010, 13:41
Hi ,

I am using the below code to show a particular path in tree view. Now when i click a file or select or focused file , i need to get the file path location and file info. How do i get it? Help me


QDirModel model;
QTreeView tree;
tree.setModel(&model);

// Demonstrating look and feel features
tree.setAnimated(true);
tree.setIndentation(20);
tree.setSortingEnabled(true);

tree.setAllColumnsShowFocus(false);


QString directory = "/mnt";
tree.setRootIndex(model.index(directory));

tree.setWindowTitle(QObject::tr("Dir View"));
tree.resize(320, 240);
tree.show();

tree.hideColumn(1);
tree.hideColumn(2);
tree.hideColumn(3);

return app.exec();

Lykurg
4th March 2010, 14:14
See QDirModel::fileInfo() or QDirModel::filePath() in conjunction with the current selected index or any other index. E.g. QAbstractItemView::activated().