PDA

View Full Version : QPixmap from data in QStandardItemModel (QVariant)



Talei
25th August 2010, 08:44
Hello,
I have QStandardItemModel with some QPixmap (thumbnails) in it. What I want to do is to display that QPixmap into i.e. QLabel (setPixmap()) but I can't do that because model data() gave me a QVariant instead of QPixmap.
How can I convert/retrieve data from the model to QPixmap (data in model is as QPixmap).
Example:

ui->label_Img->setPixmap( model->data( model->index( 0, 1 ), Qt::DecorationRole ) );
Error, data is returned as QVariant.

Regards

Lykurg
25th August 2010, 08:50
A quick search in the docs would have lead you to QVariant::value().
QVariant variant;
...
QPixmap pix = variant.value<QPixmap>();

Talei
25th August 2010, 08:56
Hehe.. i had variant.value<QPixmap> without ().... :o
I need some sleep :).