[Qt-interest] How to detect drag drop on a QListWidget (Signal?)
Andreas Pakulat
apaku at gmx.de
Fri Aug 6 15:18:13 CEST 2010
On 06.08.10 14:42:09, Matthias Pospiech wrote:
> Andreas Pakulat schrieb:
> > On 06.08.10 12:45:55, Matthias Pospiech wrote:
> >
> >> I could find out that drag and drop can be enabled using this code:
> >> ui->listWidget_MacroCommands->setDragEnabled(true);
> >> ui->listWidget_MacroCommands->setDragDropMode(QAbstractItemView::InternalMove);
> >>
> >> However I can not find any signal which indicates that such a move has
> >> happened.
> >> All I want to know is which index moved to which different index.
> >>
> > There's no way to get that, except by either subclassing or installing an
> > event filter to listen to the drag/drop events. Then you'd have to find out
> > the indices from the events x/y coordinates.
> >
> You mean that I have to evaluate pixels from the screen ???
No, there's api to find out which widget is at which pixel position. But
you'll need to use that api.
> I mean the widget isself has moved for example index 6 to inbetween 2
> and 3, so 6 becomes 3.
> If the widget knows about that I want to get to know that too.
See above, subclass/eventfilter and then ask the list which widget is at
the position of the drag-start and the drop.
> > Also I doubt the indices are being moved, I'd rather expected the data to
> > be moved (and new indices to be created for the data that is being moved)
> >
> >
> >> Can somebody give me a hint where to learn how to use drag and drop the way
> >> I want to use it - I only want to be able to rearrange elements in a
> >> QListWidget.
> >>
> >
> > Then why are you interested in which change occurs? The listwidget allows
> > dragging around elements already after the above setters are called.
> >
> >
> maybe I described it too simple. I only want to move the items in the
> widget _and_ rearrange the data in the
> container filling the widget in the same way. Otherwise the whole widget
> is refilled with the data structure
> in the container class an all the reordering is lost.
Then maybe you shouldn't be using a listwidget, but rather a view+model.
Then you'd get to know this very easily as you'd have to implement the
mimeData and dropMimeData functions (unless Qt also does this and falls
back to insert/removeRows+setData for internal moves).
Andreas
--
You have the body of a 19 year old. Please return it before it gets wrinkled.
More information about the Qt-interest-old
mailing list