jmichiel
17th June 2011, 22:37
I'm trying to get dragging to work using a QTreeView and a custom ProxyModel that contains a QSqlQueryModel. I'm using the ProxyModel to do grouping based on the values of some column of the data.
Now I want the user to be able to drag leafs of the tree out of the tree to another widget in my app.
I read http://doc.qt.nokia.com/4.7/model-view-programming.html#using-drag-and-drop-with-item-views and did everything stated there, but dragging (and dropping for that matter) doesn't work in the least: the drag is never started, startDrag() is never called (placed a breakpoint in QAbstractItemView code). The only thing that happens is that the item is selected.
What could I be doing wrong?
I don't need to subclass QTreeView since it should be able to handle it out-of-the-box, right?
The QTreeView is inside a QDockWidget, if that matters.
The drag and drop examples work, but they don't use a View, just plain Widgets.
Added after 50 minutes:
If I set the selectionBehaviour to SelectItems, it works...
Can it have something to do with the fact that I remove columns in my proxymodel, so that SelectRows has trouble selecting the entire row somehow?
Should I override mapSelectionFromSource/mapSelectionToSource to make it work on rows perhaps?
Now I want the user to be able to drag leafs of the tree out of the tree to another widget in my app.
I read http://doc.qt.nokia.com/4.7/model-view-programming.html#using-drag-and-drop-with-item-views and did everything stated there, but dragging (and dropping for that matter) doesn't work in the least: the drag is never started, startDrag() is never called (placed a breakpoint in QAbstractItemView code). The only thing that happens is that the item is selected.
What could I be doing wrong?
I don't need to subclass QTreeView since it should be able to handle it out-of-the-box, right?
The QTreeView is inside a QDockWidget, if that matters.
The drag and drop examples work, but they don't use a View, just plain Widgets.
Added after 50 minutes:
If I set the selectionBehaviour to SelectItems, it works...
Can it have something to do with the fact that I remove columns in my proxymodel, so that SelectRows has trouble selecting the entire row somehow?
Should I override mapSelectionFromSource/mapSelectionToSource to make it work on rows perhaps?