[Qt-interest] Drag & Drop with custom Model in QTreeView

Sebastian Fischer creat at gmx.net
Sun Dec 14 01:06:37 CET 2008


Hi,

first, I'm using Qt Creator (snapshot 200812120314) and the Qt version
that comes bundled for the windows version (4.4.3). I already had the
problem with the alpha though (makes sense since I don't think the
bundled Qt version was changed since then).

Now for the actual issue:
I have a very confusing problem with Drag & Drop. I have reimplemented
a tree model based on QAbstractItemModel and use the default
QTreeView to display the contents. It has 3 columns, but only the
first column has the Qt::ItemIsSelectable flag set. I want to be able
to move items to a new location.
Now everything works fine if I set the QTreeView's selectionBehavior
to SelectItems EXCEPT the moved items aren't removed (reading a bit of
Qt code it turns out that removeRows is only called if complete rows
are selected).
If I set the selectionBehavior to SelectRows that part works perfectly
and all Drag&Drop operations work as expected EXCEPT I can't drag
anything that's not a top-level-item (meaning it's parent is the
invisible root item). Debugging into Qt code shows that for some
reason startDrag in qabstractitemview.cpp aborts due to
selectedIndexes() returnung an empty selection (line 3054).

Changing the MyModel::flags return value doesn't change this behavior,
so that's not the problem (I tried returning all of [selectable, editable,
drag, drop, enabled] set with the same result). Also different
DragModes and quite a few other things. I don't think the
SelectionModel (which I haven't subclassed/changed btw) is supposed to
return an empty list in that case.

This doesn't change if I return 1 for columnCount (while it obviously
changes the behaviour with selectItems, since there is only one column
so there are always complete rows selected)

Any ideas? Or did I just screw up somewhere?

bye
Sebastian Fischer
mailto:creat at gmx.net





More information about the Qt-interest-old mailing list