I have tried numerous ways to display a QIcon in a QTableWidget cell and I am not sure why it is not working. I have a button that when pressed adds a row to the table. Here is the code...
void MainWindow::pressed()
{
QTableWidgetItem *item = new QTableWidgetItem("Hello, world!");
QTableWidgetItem *icon_item = new QTableWidgetItem;
QIcon icon("/verified/path/to/icon.png");
icon_item->setIcon(icon);
int row = ui->tableFeed->rowCount();
ui->tableFeed->insertRow(row);
ui->tableFeed->setItem(row, 0, icon_item);
ui->tableFeed->setItem(row, 1, item);
}
And it just doesn't work. Nothing is displayed in that cell. Any ideas?
EDIT: the setItem call where I set it to icon
was a typo. The actual code sets it to the QTabeWidgetItem icon_item
. I have corrected it in the code above.