QT TableView

28 views
Skip to first unread message

Egipcio

unread,
Mar 15, 2014, 9:44:03 AM3/15/14
to andro...@googlegroups.com

I'm having problems, show Qicon in rows.

now:

like :)

my code. But the icon does not appear and there is no compiler error:

class MySubClassedSqlTableModel : public QSqlTableModel
      {
          Q_OBJECT
          public:
             MySubClassedSqlTableModel(QObject * parent = 0, QSqlDatabase db = QSqlDatabase())
             : QSqlTableModel(parent,db) {;}
             QVariant data ( const QModelIndex & index, int role = Qt::DisplayRole ) const
             {
                if(role==Qt::BackgroundColorRole)
                {
                   const QVariant value(data(index,Qt::DisplayRole));

                                       if(value.toString()=="yes"){
                                          return QIcon(":/img/icons/yes.png");
                                       }else{
                                          return QIcon(":/img/icons/no.png");
                                       }
                }
                return QSqlTableModel::data(index,role);
             }
      }; 

Could someone help me?




Jean

unread,
Mar 17, 2014, 3:55:08 AM3/17/14
to andro...@googlegroups.com
What works for me is: qTableView::setIconSize(), and after that model->setItem(row, col, qpixmap);
Reply all
Reply to author
Forward
0 new messages