2

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?

Maxim Makhun
  • 2,197
  • 1
  • 22
  • 26
tuxmania
  • 906
  • 2
  • 9
  • 28

1 Answers1

5

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:\\"));  
zhangxaochen
  • 32,744
  • 15
  • 77
  • 108
  • ok i guess i experiment a little bit more since i cannot find a "good" tutorial on this QT Widgets but thanks anyway – tuxmania Jan 08 '14 at 12:28
  • 2
    You should note that the docs state `The usage of QDirModel is not recommended anymore. The QFileSystemModel class is a more performant alternative.`. – thuga Jan 08 '14 at 12:33
  • 1
    Is there a way to set on click handlers for the items in a pure QTreeView? I only find solutions for QTreeWidget – tuxmania Jan 08 '14 at 12:48