3

I have a QTreeView with a QFileSystemModel as its model.

I can't figure out how to limit the depth of the tree. I would have thought it would be a function of the model?

What I mean is, if I set the depth to 1, for example, only the top level items would be shown (i.e no expand buttons on folders)

A depth of one would make the tree look like bog-standard details view in windows explorer.

I'm using PySide, but I can understand answers in PyQt or C++.

1 Answers1

2

Not sure if this is what you're looking for, but if you're viewing the model with a QTreeView you can set the view's itemsExpandable and rootIsDecorated properties to false.

kenrogers
  • 1,350
  • 6
  • 17
  • That works fine. I'd found the itemsExpandable but couldn't for the life of me see setRootIsDecorated. Would have thought there'd be a setMaxDepth() or suchlike though. Cheers! – Karbon L. Forms Mar 01 '12 at 15:22
  • Glad it works for you. Of course, it doesn't allow you to set an arbitrary depth. You'd have to engineer something a lot more clever I think to do that. – kenrogers Mar 01 '12 at 15:52