On Mon, Jun 10, 2019, 8:22 PM HarshadB <bari.hars...@gmail.com> wrote:
> Need some help and direction in understanding QSortFilterProxyModel. I am > creating a tool in Maya using PySide2 (Qt.py). > > *GOAL:* > I have already built a filebrowser QTreeView with a QFileSystemModel. > Folders and files are both displayed. > I have a filter for files with a certain extension on the source model. > (Maybe move this filter to proxy model..) > > The files are in this format: > > name.0001.ext > name.0002.ext > name.0003.ext > > > What I want to do is, show the versions of a file in a treeView like this: > > - name (not an actual folder, virtual row I want to insert) > --name.0001.ext > --name.0002.ext > --name.0003.ext > > > So the intention is that QTreeView will always display the files with the > names w/o versions. The user has to expand the name to see the version > files. > Further on I will implement something that imports the latest file when > the "name" is operated on. > > *HELP:* > I believe I can subclass QSortFilterProxyModel to do this. Is this right? > Can someone enlighten me on how to go about it? > > Another options is to subclass QAbstractItemModel. I have yet to look deep > into this. > I would prefer QSortFilterProxyModel (based on what I have read). But > suggestions are welcome. > > I will attach some code if required. I will have to extract it from my > tool code. > Thank you. > QSortFilterProxyModel is likely where you want to start subclassing. The other option is a QAbstractProxyModel, but that will require you to implement more of the methods, whereas the former is already usable. I've got use cases similar to what you subscribe, but it is a private code base so unfortunately I have nothing to share. But I can try to offer some high level advise for now and maybe some more detailed information once I get a chance to look over my code again. But basically you have to implement things like rowCount() to create a virtual new parent tier which is your name without the versions. And stuff like hadChildren(), index(), mapToSource(), and mapFromSource(), so that you can tell the view that your virtual names have children and how to map them to the real source index in the source model. The nice thing about using proxy models is that your source model remains the same and you can have multiple views to the same source with different proxies in between that transform the data in a non-destructive way. - Justin -- > 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+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/python_inside_maya/df3e4b4a-69e1-432e-9fd9-0164463d8d57%40googlegroups.com > <https://groups.google.com/d/msgid/python_inside_maya/df3e4b4a-69e1-432e-9fd9-0164463d8d57%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA0VRdv9Qm5fUg0cH_aRDsTy4_XGO7zm4NzSO_VH2APqYA%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.