[Qt-interest] if i use QAbstractItemModel::beginMoveRows will selection track moved rows?
Stephen Kelly
steveire at gmail.com
Tue Jun 14 15:33:49 CEST 2011
Ross Bencina wrote:
> <snip>
>
> My problem is that after the drag and drop operation, item A is no longer
> selected because I am using emit dataChanged() in my model to invalidate
> the rows. Question: if I instead used beginMoveRows()/endMoveRows() then
> would the selection update correctly?
Yes. The begin/endMoveRows methods update the QPersistentIndexes, which is
what the QItemSelection uses to keep the selection up to date. I think I saw
that use of dataChanged to handle moves in a book last year, but it is
completely wrong for the reason you just hit. In the model, data changes and
structural changes are entirely separate.
>
> In any case, the above example is not a contiguous move since
> source={1,2,3,4} and destination={4,1,2,3}. How can I deal with this? or
> should I just hack my model to directly modify the selection after a
> drag-and-drop operation?
if (!beginMoveRows(0, 0, QModelIndex(), 4, QModelIndex()))
return; // Invalid move attempted.
Node *n = myVector.takeFirst();
myVector.append(n);
endMoveRows();
>
> Thanks
>
> Ross.
More information about the Qt-interest-old
mailing list