[Qt-interest] Reordering items from QFileSystemModel presented in QTreeView
Strahinja Markovic
strahinja.markovic at gmail.com
Mon Dec 21 00:25:54 CET 2009
Hi all,
So I have a QFileSystemModel and a QTreeView. The tree view presents the
items from the model as a nice file system hierrachy. I'd like the user to
be able to reorder the way the files are displayed.
For instance, let's say the tree looks like this:
folder
file1
file2
file3
I want the user to be able to click on file1 and drag it between file2 and
file3, so the view looks like this.
folder
file2
file1
file3
Naturally, the files and the folder would be unchanged on disk. It's just
the display that would change.
Currently, no matter what I try, when you try to drag-and-drop a file within
its own folder, there's no change in the order of the items.
I've turned off sorting everywhere. On the tree view, I have:
tree->setSortingEnabled( false );
tree->sortByColumn( -1 );
and drag is enabled along with AcceptDrops and DropIndicatorShown. I've also
created a subclass of QFileSystemModel and overridden the sort() method with
an empty implementation. Nothing I try seems to work.
I've looked at the "Using Drag and Drop with Item Views" page and done
what's required, and I *know* I can make this work for say a subclass of
QStandardItemModel. But I really don't want to roll my own version of a file
system model when one already exists.
I'd love to hear any suggestions regarding this matter.
Sincerely,
Strahinja Markovic
More information about the Qt-interest-old
mailing list