Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 313
tuxmania Avatar asked Nov 27 '25 18:11

tuxmania


1 Answers

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:\\"));  
like image 63
zhangxaochen Avatar answered Nov 30 '25 09:11

zhangxaochen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!