How to decode “application/x-qabstractitemmodeldatalist” in Qt for drag and drop?

前端 未结 3 1507
醉梦人生
醉梦人生 2020-12-10 03:48

I\'ve created a child class of QTreeWidget that I want to be able to drag items from another tree widget too (I want to handle the insertion myself though), as well as from

3条回答
  •  北荒
    北荒 (楼主)
    2020-12-10 04:20

    You can decode it as follows:

    QByteArray encoded = qMimeData->data("application/x-qabstractitemmodeldatalist");
    QDataStream stream(&encoded, QIODevice::ReadOnly);
    
    while (!stream.atEnd())
    {
        int row, col;
        QMap roleDataMap;
        stream >> row >> col >> roleDataMap;
    
        /* do something with the data */
    }
    

    The QMap is what is returned by QAbstractItemModel::itemData(index) for the index representing (row, col).

提交回复
热议问题