As janorcutt alluded to, ":/images/*.png" is not the name of an image file so you end up with a null QIcon. You want to load a single image file into each cell. Assuming your files are named img0.png through img8.png, then:
for (int r = 0; r < t.rowCount(); ++r)
{
for (int c = 0; c < t.columnCount(); ++c)
{
item->setBackgroundColor(Qt::black);
item->setIcon(
QString(":/images/img%1.png").
arg(r
* t.
columnCount() + c
) )
);
t.setItem(r, c, item);
}
}
for (int r = 0; r < t.rowCount(); ++r)
{
for (int c = 0; c < t.columnCount(); ++c)
{
QTableWidgetItem* item = new QTableWidgetItem;
item->setBackgroundColor(Qt::black);
item->setIcon(
QIcon(
QString(":/images/img%1.png").arg(r * t.columnCount() + c)
)
);
t.setItem(r, c, item);
}
}
To copy to clipboard, switch view to plain text mode
should be closer to what you thought you were doing.
BTW: Your initial screen shot shows a 4x3 grid not a 3x3 grid
Bookmarks