Still something strange about the dropping...
Explain that: When I reimplement the dragMoveEvent() (even with an empty function), I can drop anywhere in my table. If I don't reimplement it, I can only drop when the cursor is exactly on the frame around the content rows (so at the bottom of the header row and at the top of the horizontal scroll bar). That's weird, if you ask me.
So, the recipe for dropping on QTableWidget is:
1. setup your table in the constructor
setAcceptDrops(true);
setDragDropMode(QAbstractItemView::DropOnly);
setAcceptDrops(true);
To copy to clipboard, switch view to plain text mode
2. re-implement the functions dragEnterEvent(...), dragMoveEvent(...) and dropEvent(...), for example:
{
if (event->mimeData()->hasUrls()) {
event->acceptProposedAction();
}
}
// nothing to do, function just has to exist...
}
{
if (event->mimeData()->hasUrls()) {
QList<QUrl> urls = event->mimeData()->urls();
for (int i=0; i<urls.count(); ++i) {
int row = rowCount();
insertRow(row);
setItem(row, 0, newItem);
}
event->accept();
}
}
void MyTable::dragEnterEvent(QDragEnterEvent *event)
{
if (event->mimeData()->hasUrls()) {
event->acceptProposedAction();
}
}
void MyTable::dragMoveEvent ( QDragMoveEvent * ) {
// nothing to do, function just has to exist...
}
void MyTable::dropEvent(QDropEvent *event)
{
if (event->mimeData()->hasUrls()) {
QList<QUrl> urls = event->mimeData()->urls();
for (int i=0; i<urls.count(); ++i) {
int row = rowCount();
insertRow(row);
QTableWidgetItem *newItem = new QTableWidgetItem(urls[i].toString());
setItem(row, 0, newItem);
}
event->accept();
}
}
To copy to clipboard, switch view to plain text mode
At least that's what worked for me.
Bookmarks