Bump. ghorwin 'hijacked' my thread!
Bump. ghorwin 'hijacked' my thread!
Israa: Sorry for hijacking, but you asked excactly the same question that I had, so figured opening a new thread would be non-sense.
Jpn: dragMoveEvent() is called correctly.
So it seems something prevents the dropping...
If I read the documentation correctly, only the widget itself, that should accept the drop, needs to call setAcceptDrop(), right? Or do I also have to tell the parent dialog to accept drops?
Anyway, I'm clueless. Should I post a simple test-program?
Andreas
Guys, got it to work!!!
The trick is to call
in addition toQt Code:
To copy to clipboard, switch view to plain text mode
(wasn't mentioned in the docu, but I just went back to the abstract view class)...
Now dropEvent is called alright!
Andreas
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
Qt Code:
setAcceptDrops(true);To copy to clipboard, switch view to plain text mode
2. re-implement the functions dragEnterEvent(...), dragMoveEvent(...) and dropEvent(...), for example:
At least that's what worked for me.Qt Code:
{ 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(); } }To copy to clipboard, switch view to plain text mode
Andreas
I still haven't gotten an answer to my question, would anyone know what I need to do to enable drag & drop to and from 2 QTableWidgets? I create a class that inherits QTableWidget and I place the two objects on either side of a QSplitter. I can drag & drop in the same table, but not to the other table.
Using Drag and Drop with Item Views - Using Convenience Views:
The same applies for a table widget.For example, we can enable drag and drop in a list widget with the following lines of code:
Qt Code:
listWidget->setDragEnabled(true); listWidget->setAcceptDrops(true); listWidget->setDropIndicatorShown(true);To copy to clipboard, switch view to plain text mode
J-P Nurmi
I am having the same problem, trying to drag&drop from one table to another.
I am having trouble following the page you linked. I have tried the function calls that enable drag&drop functionality, but I am still having issues dropping to a different table than was dragged from. Is there any way some short example code could be provided? Nothing complicated, I'd just like to see a working example.
Thanks.
Does this work for you?
Qt Code:
#include <QtGui> { tableWidget->setDragEnabled(true); tableWidget->setAcceptDrops(true); tableWidget->setDropIndicatorShown(true); return tableWidget; } int main(int argc, char* argv[]) { QSplitter splitter; splitter.addWidget(createTableWidget(&splitter)); splitter.addWidget(createTableWidget(&splitter)); splitter.show(); return a.exec(); }To copy to clipboard, switch view to plain text mode
J-P Nurmi
Bookmarks