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

10th April 2009, 15: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)?

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

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


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

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