Drag and Drop from WTableView1 to WTableView2
Added by David Betz about 11 years ago
I have a use case in which I would like users to be able to select from a long list of rows in WTableView1, and drag them over to WTableView2. WTableView1 and WTableView2 use WAbstractTableModel. WTableView1 is setDragEnabled, and WTableView2 is acceptDrops(VirtualModel1->mimeType()).
There is a cryptic comment in the documentation that "the current selection may be dragged, but only when all items in the selection indicate support for dragging". I guess "items" in this sentence refers to WStandardItems. Does this mean I have to modify VirtualModel?
It seems that one shouldn't be using WAbstractTableModels at all, but should instead use WStandardItemModel if one wants to implement dragging and dropping between tables. Is that correct?
The documentation in this area is difficult for me to understand.
Test_Harness.cpp (3.94 KB) Test_Harness.cpp | Feeble attempt at between table drag and drop |
Replies (1)
RE: Drag and Drop from WTableView1 to WTableView2 - Added by Koen Deforche about 11 years ago
Hey,
You need to make sure that the flags return Wt::ItemIsDropEnabled for each item. If you want to start from VirtualModel then indeed you will need to extend it. The 'item' refers to a WAbstractItemModel item, not specifically to a WStandardItemModel. All descendants from WAbstractItemModel contain items.
You need to extend the model also to specialize dropEvent() to handle the actual drop event. See also the treeview-dragdrop example.
Regards,
koen