Results 1 to 2 of 2

Thread: add Pixmap to QueryModel

  1. #1
    Join Date
    Mar 2008
    Posts
    141
    Thanks
    10
    Thanked 9 Times in 9 Posts

    Default add Pixmap to QueryModel

    Hi,
    I get a bool from the database and would like to display an image instead. But returning a Pixmap (or Icon) shows an empty cell. If i return the pic for the DecorationRole it is displayed. Any idea?
    I have a subclass of QSqlQueryModel an the data() funktion looks like this:

    Qt Code:
    1. QVariant SqlQueryModel::data(const QModelIndex & index, int role) const
    2. {
    3. QString curr(QSqlQueryModel::data(index, Qt::DisplayRole).toString());
    4.  
    5. if ( index.column() == 2 && role == Qt::DisplayRole ){
    6.  
    7. // return QVariant(QString("sometext")); // is displayed
    8. return QVariant(QPixmap(":/somepic.png")); // is not displayed
    9.  
    10. }else{
    11.  
    12. return QSqlQueryModel::data(index, role);
    13. }
    14. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: add Pixmap to QueryModel

    DisplayRole is meant to hold text and text only. Icons are displayed using DecorationRole. If you want to change this behaviour, you'll have to provide your own item delegate or use a proxy model that will take the icon from DisplayRole and return it as DecorationRole.

Similar Threads

  1. Qt 3.3.8 pixmap to/from image error
    By ksierens in forum Qt Programming
    Replies: 1
    Last Post: 15th April 2008, 07:46
  2. finding maximum scaling of a pixmap
    By babu198649 in forum Newbie
    Replies: 1
    Last Post: 31st March 2008, 15:32
  3. empty pixmap as a QLabel
    By tommy in forum Qt Programming
    Replies: 16
    Last Post: 11th December 2007, 22:15
  4. Invalid pixmap
    By munna in forum Newbie
    Replies: 2
    Last Post: 8th June 2006, 09:00
  5. Paint XP radio button to pixmap
    By Ben.Hines in forum Qt Programming
    Replies: 2
    Last Post: 26th April 2006, 22:15

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
  •  
Qt is a trademark of The Qt Company.