Hi,
If we add a pixmap to the QTableWidgetItem the cell of the TableWidget displays the icon as well as the text. In the above case the text value is empty. In order to check u can double click your icon cell and see that you can edit the text.
For the above requirement one approach can be to create a delegate and override the paint() method then set the delegate to the TableWidget
Eg:
.h
@class TableDelegate : public QStyledItemDelegate
{
Q_OBJECT
public:
explicit TableDelegate(QObject *parent = 0);
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
};@
.cpp
@void TableDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
//here you can write the logic for painting each row with different color gradients.
if(index.column()==1)
painter->fillRect(option.rect,Qt::red); //painting the whole cell if column count ==1
}@
then in the constructor of your class you can give:
@delegate = new TableDelegate();
ui->tableWidget->setItemDelegate(delegate);@
You can also make the color column as non-editable.
Regards
Soumitra