PDA

View Full Version : QTableView and drag & drop



salvaste
18th January 2010, 12:52
Hi, I'm new here and I have a problem that it's making me crazy.

I'm trying to enable drag and drop between two QTableView widgets connected to a QTableModel model. No matter what I try but nothing seems to work, e.g.: holding the mouse over a row and dragging simply select other rows without dragging nothing.

I tryed to build a minimal working example starting from tablemodel example and enabling drag in every manner I found, but I'm not able to enable dragging.

I've read every piece of documentation I found around.

Someone more skilled than me can explain me what I have to change in the tablemodel example to enable drag ?

Thank you in advance.

salvaste
18th January 2010, 13:01
two QTableView widgets connected to a QTableModel model.

ops, it's QSqlTablelModel and sql/tablemodel. sorry.

nikhilqt
18th January 2010, 13:42
you have to set the acceptDrops to true, then your dragEnter event works


tableView->setAcceptDrops(true);

after, you have to set the action of proposed action i.e., setDropAction(...) and call the acceptProposedAction () of the QDropEvent in dragEvent handler.

Then handle the data however you want to do in the dropEvent handler.

salvaste
18th January 2010, 14:11
after, you have to set the action of proposed action i.e., setDropAction(...) and call the acceptProposedAction () of the QDropEvent in dragEvent handler.

Then handle the data however you want to do in the dropEvent handler.

Thank you for your response. I still can not see the light ... Trying to make a summary:

1. subclass QTableView and override dragEnterEvent and dragMoveEvent, putting there e->accept() or e->acceptProposedAction() (which one? ...)
2. set tableView->setEnableDrags(true)
3. set tableView->setAcceptDrops(true)
4. anything else ?

salvaste
18th January 2010, 16:51
I found out


4. anything else ?

subclass QSqlTableModel::flags and add the flag Qt::ItemIsDragEnabled, default is to have drag disabled on the side of the model.