PDA

View Full Version : How to restrict directory viewing to a subtree?



xfurrier
10th April 2009, 14:20
I have a directory viewer which uses QDirModel and QTreeView. However, rather than inspecting a whole drive, I'd like to restrict the viewing/editing/etc to a particular folder, say "/tmp". I don't want users to see anything else but that subtree.

Is that possible to achieve using the default QDirModel and QTreeView (if so, how?), or should I implement a new custom model (if so, any tips/code would be extremely helpful)?

faldzip
10th April 2009, 14:59
If you have such code:


QDirModel * model = new QDirModel;
QTreeView * tree = new QTreeView(this);
tree->setModel(model);
then you can do:


tree->setRootIndex(model->index("/tmp"));

and the root index of your tree would be the /tmp directory.

xfurrier
10th April 2009, 16:29
thanks for that - completely missed that in the documentation