Hi,
I have the following class in a static lib:
{
....
....
};
Q_DECLARE_METATYPE(ITGraphic);
class ITGraphic : public QPixmap
{
....
....
};
Q_DECLARE_METATYPE(ITGraphic);
To copy to clipboard, switch view to plain text mode
Thereafter I am returning ITGraphic object in another static library from model class in data function:
{
if (!index.isValid())
if (role == Qt::DecorationRole)
{
ITGraphic *graphic = GetBitmap(index.row());
if(graphic != NULL)
{
QPixmap tmpPixmap
= graphic
->scaled
(iconSize,Qt
::KeepAspectRatio);
}
else
}
else if (role == Qt::UserRole)
{
return *(GetBitmap(index.row()));
}
}
QVariant ITPictureList::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
return QVariant();
if (role == Qt::DecorationRole)
{
ITGraphic *graphic = GetBitmap(index.row());
if(graphic != NULL)
{
QPixmap tmpPixmap = graphic->scaled(iconSize,Qt::KeepAspectRatio);
return QIcon(tmpPixmap);
}
else
return QVariant();
}
else if (role == Qt::UserRole)
{
return *(GetBitmap(index.row()));
}
return QVariant();
}
To copy to clipboard, switch view to plain text mode
I am trying to get this object like this:
QVariant value = picList->data(index,Qt::UserRole);
res = qVariantCanConvert<ITGraphic>(value);
ITGraphic pGraphic = qvariant_cast<ITGraphic>(value);
res = qVariantCanConvert<ITGraphic>(value);
ITGraphic pGraphic = qvariant_cast<ITGraphic>(value);
To copy to clipboard, switch view to plain text mode
qVariantCanConvert returns false here and I am not able to get the proper object here. But if I try the following, it works:
QPixmap pGraphic
= qVariantValue<QPixmap>
(picList
->data
(index, Qt
::UserRole));
QPixmap pGraphic = qVariantValue<QPixmap>(picList->data(index, Qt::UserRole));
To copy to clipboard, switch view to plain text mode
Can someone help me, how to get the ITGraphic object here?
Regards,
Manoj
Bookmarks