QMimeData problems between a QTableWidget and a QTreeWidget
Hello, i am trying to make it so when you drag from a table view to a tree view you can send some data and add an item to the tree view. I searched on the web and programmed something that i feel should work but, alas, it is not.
This is the treeview class.
Code:
Favorites
::Favorites(QWidget *parent
){
//building the part for the favorites list
favoritesItem->setText(0,"Favorites");
this->addTopLevelItem(favoritesItem);
favoritesItem->setExpanded(true);
this->setAcceptDrops(true);
addPathToFavorites
(QString("asdsadasd"));
refreshFavorites();
}
qDebug()<< event->mimeData()->text(); // just prints out ""
if (event->mimeData()->hasText())
event->acceptProposedAction();
}
qDebug()<< event->mimeData()->text();
addPathToFavorites(event->mimeData()->text());
}
And this is the table
Code:
TableWidget
::TableWidget(QWidget *parent
){
//i've enabled drag in the main class
}
if(event->button() == Qt::LeftButton)
poss = event->pos();
else { ;}
}
if(!event->buttons() & Qt::LeftButton)
else
if((event
->pos
() - poss
).
manhattanLength() <
QApplication::startDragDistance()) else{
if(item){
mimeData->setText(item->text());
drag->setMimeData(mimeData);
qDebug()<<drag->mimeData()->hasText()<<drag->mimeData()->text();//print's what it should
}
}
}
What am I doing wrong? Any help will be greatly appreciated. Thank you.
Re: QMimeData problems between a QTableWidget and a QTreeWidget
Hi!
No time to look into it thoroughly. Aren't you missing drag->exec() ?
What happens when you drag some text from another source/application? That way you can separate source and destination problems..
If nothing works - Post a minimal compilable example, please!
HIH
Johannes
Re: QMimeData problems between a QTableWidget and a QTreeWidget
I am a bit shocked I missed that. It works now.
But I have a follow-up question: just by using drag->exec(), it works, but when I am over the place I want to drop the data, it shows a blocked-like icon(i can't take a screenshot of it); any ideas why this is happening? should i pass something in the exec method call ?
Thanks again for the help.
Re: QMimeData problems between a QTableWidget and a QTreeWidget
Thats a destination problem - should also happen, when you try tro drag text from let's say notepad..
You need to accept the drag in the dragMoveEvent, too.
Code:
{
if (event->mimeData()->hasText())
{
event->accept();
}
}
And call the inherited dragEnterEvent, also!
HIH
Johannes