Results 1 to 3 of 3

Thread: QPixmap from data in QStandardItemModel (QVariant)

  1. #1
    Join Date
    Dec 2008
    Location
    Poland
    Posts
    383
    Thanks
    52
    Thanked 42 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Android

    Default QPixmap from data in QStandardItemModel (QVariant)

    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:
    Qt Code:
    1. ui->label_Img->setPixmap( model->data( model->index( 0, 1 ), Qt::DecorationRole ) );
    To copy to clipboard, switch view to plain text mode 
    Error, data is returned as QVariant.

    Regards

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QPixmap from data in QStandardItemModel (QVariant)

    A quick search in the docs would have lead you to QVariant::value().
    Qt Code:
    1. QVariant variant;
    2. ...
    3. QPixmap pix = variant.value<QPixmap>();
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to Lykurg for this useful post:

    Talei (25th August 2010)

  4. #3
    Join Date
    Dec 2008
    Location
    Poland
    Posts
    383
    Thanks
    52
    Thanked 42 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QPixmap from data in QStandardItemModel (QVariant)

    Hehe.. i had variant.value<QPixmap> without ()....
    I need some sleep .

Similar Threads

  1. Replies: 6
    Last Post: 20th January 2010, 04:16
  2. Using QVariant with custom data type
    By QAlex in forum Qt Programming
    Replies: 3
    Last Post: 4th December 2009, 12:04
  3. QPixmap and QVariant
    By cafu in forum Qt Programming
    Replies: 16
    Last Post: 27th October 2009, 13:23
  4. Display data from QStandardItemModel in QTreeView
    By jprice01801 in forum Qt Programming
    Replies: 7
    Last Post: 10th January 2007, 09:34
  5. Use QVariant with custon data types
    By mcosta in forum Qt Programming
    Replies: 4
    Last Post: 11th January 2006, 14:55

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.