PDA

View Full Version : QDirModel displaying Desktop and Documents



JimDaniel
5th February 2008, 17:27
Hi, I'm using a QDirModel with a treeview to implement a windows explorer-like interface. I'd like to be able to also add directories for Desktop and MyDocuments (or equivalent) in the parent directory, where it shows the hard drives.

I'm totally new to using a model/view type interface. Can someone point me in the right direction to be able to do this?

Just to test, I hard coded myDirModel->index("desktopfilepath") and then use the returned QModelIndex to create a new directory by calling myDirModel->mkdir(returnedIndex, "name"); This did not work, however. What am I doing wrong?

Thanks, Daniel

wysota
7th February 2008, 11:22
You can't just add new entries to the directory tree on the root level. Unfortunately QDirModel doesn't show Desktop and My Documents entry and there is no easy way to make it work. You have to subclass the model and handle those entries in the subclass or implement a proxy model that would map proper indexes. It's not a 10 minute task, though. If you decide to do it, I'd go for the proxy approach. Also search the forum, there was a thread describing a similar problem about 2 months ago.

JimDaniel
8th February 2008, 04:45
Thanks for the advice, it was time-sensitive so I ended up just emulating the filesystem with a QTreeWidget. Wasn't as much trouble as I thought it'd be.