QFileSystemModel - list only contents of certain directory?

711 views
Skip to first unread message

Panupat Chongstitwattana

unread,
Apr 7, 2015, 1:00:17 AM4/7/15
to python_in...@googlegroups.com
If I set my rootPath to ......./project. And here's the folder structure under it.

project
|-- foo
|-- bar
|-- asset
....|---- item1
....|---- item2

I want my QTreeView to display item1 and item2 under project without showing asset. Also ignore foo bar completely.

project
|---- item1
|---- item2

Would this be possible with QFileSystemModel? Could anyone show me some example please?

thank you!

Best regard,

Justin Israel

unread,
Apr 7, 2015, 2:04:50 AM4/7/15
to python_in...@googlegroups.com
I don't have an example to show you off the bat, but you would need to use a proxy model in between, which would handle listing the children of 'project'. Proxy models can do whatever they want, to remap the data coming from its source model, and representing it differently to any views asking for root level items, and then the children for those items, if any.



--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/a3b9c833-d8d4-4b03-9209-e9025cea0d5a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Panupat Chongstitwattana

unread,
Apr 7, 2015, 2:11:45 AM4/7/15
to python_in...@googlegroups.com
Hi Justin. Is it the QAbstractProxyModel that I need to look into?
http://doc-snapshots.qt.io/4.8/qabstractproxymodel.html
Thank you.


On Tuesday, April 7, 2015 at 1:04:50 PM UTC+7, Justin Israel wrote:
I don't have an example to show you off the bat, but you would need to use a proxy model in between, which would handle listing the children of 'project'. Proxy models can do whatever they want, to remap the data coming from its source model, and representing it differently to any views asking for root level items, and then the children for those items, if any.



On Tue, Apr 7, 2015 at 5:00 PM Panupat Chongstitwattana <panu...@gmail.com> wrote:
If I set my rootPath to ......./project. And here's the folder structure under it.

project
|-- foo
|-- bar
|-- asset
....|---- item1
....|---- item2

I want my QTreeView to display item1 and item2 under project without showing asset. Also ignore foo bar completely.

project
|---- item1
|---- item2

Would this be possible with QFileSystemModel? Could anyone show me some example please?

thank you!

Best regard,

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.

Marcus Ottosson

unread,
Apr 7, 2015, 2:11:53 AM4/7/15
to python_in...@googlegroups.com
How about setting the rootPath to your `asset` folder instead? Otherwise, like Justin said, a proxy model should do the trick though I'm not sure how straightforward rearranging hierarchy is.


For more options, visit https://groups.google.com/d/optout.



--
Marcus Ottosson
konstr...@gmail.com

Panupat Chongstitwattana

unread,
Apr 7, 2015, 2:24:36 AM4/7/15
to python_in...@googlegroups.com
I thought about that too. Since I store the base path of each project in database, I could load them into a combo box and set the root path according to user input.

If I am able to do this with 1 QTreeView tho it would be real nice because there are couple more folders in between that I'd like to apply this trick.

Justin Israel

unread,
Apr 7, 2015, 2:32:23 AM4/7/15
to python_in...@googlegroups.com
Yea it would either be using an AbstractProxyModel (or QSortProxyModel), or splitting them up into multiple views at different root paths. Then it might be a matter of reimplementing: 
hasChildren()
canFetchMore()
fetchMore()
rowCount()

...so that when you are given the 'parent' item, you would return the correct number of grandchildren and or if the parent has grandchildren, and returning the grandchildren.


On Tue, Apr 7, 2015 at 6:24 PM Panupat Chongstitwattana <panu...@gmail.com> wrote:
I thought about that too. Since I store the base path of each project in database, I could load them into a combo box and set the root path according to user input.

If I am able to do this with 1 QTreeView tho it would be real nice because there are couple more folders in between that I'd like to apply this trick.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages