I made a QListView which has a source of QStandardItemModel. I set the view to have the following settings
setSpacing(5);
setMovement(QListView::Snap);
setResizeMode(QListView::Adjust);
setSpacing(5);
setViewMode(QListView::IconMode);
To copy to clipboard, switch view to plain text mode
My model's item is a QStandardItem and i added my "metatype registered value" at Qt::UserRole + 1. When I started draging the item in my view the whole things just crushes, but when i took my metatype registered value in my item it works fine. This will only happen when i drag those icons. I have accessed and displayed my custom data through the modelIndex and its fine no crushes.
below is how i declare my metatype value
struct s_SqlListInfo
{
QList <QString> reqTableList;
};
// Qt MetaType Declaration
Q_DECLARE_METATYPE(s_SqlListInfo)
//spot where i added my value to the item
QVariant myVal
= hander
->list
().
at(0);
// hander->list() ,returns a QList of Qvariant with my custom data if (myVal .canConvert<s_SqlListInfo>())
{
s_SqlListInfo info = myVal .value<s_SqlListInfo>();
item->setData(info.queryName.toString(),Qt::DisplayRole);
item
->setData
(QIcon(":/ListIcon.png"),Qt
::DecorationRole);
item->setData(myVal ,Qt::UserRole+1); // spot where i added my custom data
item->setData(info.sqlStatement,Qt::ToolTipRole);
item->setFlags(item->flags()& ~Qt::ItemIsEditable);
m_userListModel->appendRow(item);
}
struct s_SqlListInfo
{
QVariant queryName;
QVariant dataBaseName;
QList <QString> reqTableList;
QString sqlStatement;
};
// Qt MetaType Declaration
Q_DECLARE_METATYPE(s_SqlListInfo)
//spot where i added my value to the item
QVariant myVal = hander->list().at(0); // hander->list() ,returns a QList of Qvariant with my custom data
if (myVal .canConvert<s_SqlListInfo>())
{
s_SqlListInfo info = myVal .value<s_SqlListInfo>();
QStandardItem* item = new QStandardItem();
item->setData(info.queryName.toString(),Qt::DisplayRole);
item->setData(QIcon(":/ListIcon.png"),Qt::DecorationRole);
item->setData(myVal ,Qt::UserRole+1); // spot where i added my custom data
item->setData(info.sqlStatement,Qt::ToolTipRole);
item->setFlags(item->flags()& ~Qt::ItemIsEditable);
m_userListModel->appendRow(item);
}
To copy to clipboard, switch view to plain text mode
Bookmarks