View Full Version : Drag & Drop rows in a QTableWidget

28th April 2008, 23:18
Here's another one for you guys to point me to where I messed up :)

I'm trying to get DnD to work on rows of a QTableWidget. I've gotten it to Drag & Drop the row (by turning off dragenable & dropenable except on the first column -- which probably isn't very user friendly, but keeps it from shifting all the bloody data)... but even with setDragDropOverwriteMode(false), the data in the drop target is overwritten (instead of having the moved row inserted, like the docs say). :confused:

I suspect I'll have to derive from the QTableWidget to get the data not allowed to drop off the table (i.e. it'd vanish) -- but do I need to derive to get the row move properly? :crying:

I'll post code if needed, but it's really just the QTableWidgetItem creations & the table & settings are from designer (and, yes, I tried to put the Overwrite Mode thing in my code... but no difference between true or false).


29th April 2008, 00:56
First of all try dropping between rows instead of dropping on a row. If you have the drop indicator activated, it should be displayed as a line between rows instead of a frame around a cell of the table. You can make sure you can't drop on a cell (instead of between cells) by removing the ItemIsDropEnabled flag.

29th April 2008, 13:25
I've tried the following:


With the items:

item->setFlags(item->flags() & ~(Qt::ItemIsDropEnabled));

But I can't get it to drop on the line (unless that's the '+' indicator)... and the cell under/near the drop is still overwritten. Using 4.3.2, if that makes any difference (bug?).

29th April 2008, 16:34
Could you prepare a minimal compilable example reproducing the problem?

17th January 2012, 13:17
It appears you have to use model/view stuff for such a basic thing. And that sucks.

17th January 2012, 14:00
What kind of "basic thing"?

18th January 2012, 15:58
Draging the table row with a mouse to a new place in the same table without deleting previous content.

19th January 2012, 01:01
No, you can do that with QTableWidget as well. That's what InternalMove does by default, anyway. Unless you mean you want to copy the item, then internal move, as the name suggests, does something different.