Nominate our 2022 Qt Champions!

Drag and Drop between QTableWidgets

  • I want to know how to retrieve the source QTableWIdget of a drag and drop operation
    when reimplementing the dropMimeData(int row, int column, const QMimeData *data, Qt::DropAction action) method.

    Answer : I find it in the DropEvent->source but how to get the row & column coordinates of the DragItem?

  • I finally solved the issue in reimplementing the dropEvent like that :
    if (event) {
    // Get QTableWidget
    QTableWidget *table = qobject_cast<QtableWidget *>(event->source());

    // Decode Mime Data
    QString format = QLatin1String("application/x-qabstractitemmodeldatalist");
    QByteArray encoded = event->mimeData()->data(format);
    QDataStream stream(&encoded, QIODevice::ReadOnly);

    // Decode format (row, column) to get row & column coordinates
    int row,column;
    stream >> row >> column;