[Qt-interest] QTableView drag and drop
Jason Wood
jason at comp.leeds.ac.uk
Fri Oct 30 16:27:21 CET 2009
Hi,
I'm pretty new to Qt but am trying to use QTableView to
display a a set of data that has 3 columns and a number of
rows. I can get display and edit (of entries) to work,
but now I want to be able to re-arrange the rows and thought
that dragging and dropping would be nice. The documentation
seems to suggest it will do what I want but I just don't
seem to get the results I am after.
I have used the following settings (on a QTableView *tableW)
tableW->setDragEnabled(true);
tableW->setDragDropOverwriteMode(false);
tableW->setDragDropMode(QAbstractItemView::InternalMove);
tableW->setSelectionMode(QAbstractItemView::SingleSelection);
tableW->setSelectionBehavior(QAbstractItemView::SelectRows);
What I thought this would let me do was select a whole row,
drag it up or down and drop it between 2 other rows and
have it insert itself there. Which it does do, however,
only if you get the indicator that says it is exactly between
2 rows. If you are not exactly between 2 rows so that one or
other of the adjacent rows is highlighted then the dragged row
vanishes when dropped.
Also, if you insert it offset to the right, then the
entry from the first column is offset to the right (say in the
second column), the first coumn for the inserted row is empty and
every entry of the dropped row is shifted accross with the last entry
creating a new column.
I am using Qt 4.5.3 on linux.
Any thoughts on whether I am after the impossible, have a setting of
QTableView wrong ?
-------------
jason
More information about the Qt-interest-old
mailing list