[Qt-interest] drag and drop of standard Qt's widgets
Bo Thorsen
bo at fioniasoftware.dk
Wed May 11 07:14:54 CEST 2011
Den 10-05-2011 16:26, George Brink skrev:
> I would like to DnD an item from a QTreeWidget into another widget (in
> the same application.
> The "drag" part of DnD works perfectly, but I do not understand how to
> extract the dragged QTreeWidgetItem from the QMimeData object?
> -------------------
> void MyWindow::dropEvent(QDropEvent *e) {
> if( e->mimeData()->hasFormat(
> "application/x-qabstractitemmodeldatalist")) {
>
> QByteArray ba = e->mimeData()->data(
> "application/x-qabstractitemmodeldatalist");
> QTreeWidgetItem twi = ba; // ???? how?
>
> qDebug()<< twi.text(0);
> e->acceptProposedAction();
> }
> }
> -------------------
> Where is the manual which describes relationship between Qt's widgets
> and QMimeData?
You have this slightly wrong. A widget isn't drag'n'dropped, the
contents are. So the drop contains what the treeitem contains. If you
want to control what's dragged, you can do this from the tree model.
The widget can't be dragged because widget objects can't be copied.
Bo Thorsen,
Fionia Software.
--
Expert Qt and C++ developer for hire
Contact me if you need expert Qt help
http://www.fioniasoftware.dk
More information about the Qt-interest-old
mailing list