tuxmania
tuxmania

Reputation: 956

Showing filesystem in QTreeWidget

I have a simple Question. I want to show my filesystem in a QTreeWidget just like an common file explorer.

How can i achieve that? I guess searching through all files and add them manual is not the approach to chose, right?

Upvotes: 3

Views: 1433

Answers (1)

zhangxaochen
zhangxaochen

Reputation: 34047

use QDirModel and QTreeView instead of QTreeWidget, here is a code snippet:

QDirModel *model = new QDirModel;
QTreeView *tree = new QTreeView(splitter);  
tree->setModel(model);  
tree->setRootIndex(model->index("C:\\"));  

Upvotes: 6

Related Questions