2 Attachment(s)
Drag an drop between differents QTableWidget...
Hello,
I have some problems with drag and drop between differents QTableWigdet.
Table A is source information, where I selected and drag the entire row but the last cell.
Attachment 9035
Now, I would like to drop this information in Table B. (botton QTableWidget).
I have implemented dragEnterEvent, dragMoveEvent, dropEvent and dragLeaveEvent and it works fine.
Code:
#include <QtGui>
#include <QDebug>
#include "LeiTableWidget.h"
LeiTableWidget
::LeiTableWidget(QWidget *parent
) {
setAcceptDrops(true);
setAutoFillBackground(true);
clear();
}
{
// qDebug() << "dragEnterEvent";
event->acceptProposedAction();
}
{
// qDebug() << "dragMoveEvent";
event->acceptProposedAction();
}
{
qDebug() << "dropEvent";
QTableWidget* table
= qobject_cast<QTableWidget
*>
(event
->source
());
if(table->currentItem() != NULL)
{
// Tengo las coordenadas del elemento que se ha arrastrado desde su origen
//**************************************************************************
old_coordinates
= QPoint( table
->currentItem
()->row
(), table
->currentItem
()->column
() );
}
qDebug() << table->currentItem()->row() << "-" << table->currentItem()->column() ;
qDebug() << "mine data " << event->mimeData()->text();
event->acceptProposedAction();
}
{
// qDebug() << "dragLeaveEvent";
event->accept();
}
void LeiTableWidget::clear()
{
}
but now I have some problems:
1.- If a drop in a cell different than column 0, write incorrect data in table.
Attachment 9036
2.- How can I detect what information or items has drop action?
3.- How can I detect what row is select to drop?
Best regards.
Re: Drag an drop between differents QTableWidget...
Try implementing dropMimeData instead of dropEvent
See if this works
Code:
bool LeiTableWidget
::dropMimeData (int row,
int column,
const QMimeData * data, Qt
::DropAction action
) {
}