Further to my previous post, I've tried to solve this one on my own, however I've hit another hurdle. So I've subclassed QListWidget (called it BookMarkList) in order to intercept the drag&drop and hopefully ignore any drops of existing text. However I can't seem to get the value of the drag text. When I run the program I only seem to get a blank string in 'itemString'. Note that the msgBox is only being used for debugging.
Q_DECLARE_METATYPE(QModelIndex);
//at start of BookMarkList.cpp file (after #includes)
bool BookMarkList
::dropMimeData(int index,
const QMimeData *data, Qt
::DropAction action
) {
QByteArray dropData
= data
->data
("application/x-qabstractitemmodeldatalist");
int iNum = 0;
while (!stream.atEnd())
{
stream >> qVar;
if ( stText == "QModelIndex" )
{
itemString = item.data().toString();
break;
}
iNum++;
}
msgBox.setText( itemString );
msgBox.exec();
//QListWidget::dropMimeData(index, data, action);
return true;
}
Q_DECLARE_METATYPE(QModelIndex); //at start of BookMarkList.cpp file (after #includes)
bool BookMarkList::dropMimeData(int index, const QMimeData *data, Qt::DropAction action)
{
QByteArray dropData = data->data("application/x-qabstractitemmodeldatalist");
QDataStream stream(&dropData, QIODevice::ReadOnly);
QString itemString;
int iNum = 0;
while (!stream.atEnd())
{
QVariant qVar;
stream >> qVar;
QString stText = qVar.typeName();
if ( stText == "QModelIndex" )
{
QModelIndex item = qVar.value<QModelIndex>();
itemString = item.data().toString();
break;
}
iNum++;
}
QMessageBox msgBox;
msgBox.setText( itemString );
msgBox.exec();
//QListWidget::dropMimeData(index, data, action);
return true;
}
To copy to clipboard, switch view to plain text mode
Any help would be greatly appreciated as I have not been able to find any information on this.
Thanks!!
Bookmarks