#include <QtGui>
#include <QApplication>
int main(int argc, char **argv)
{
for (int row = 0; row < table.rowCount(); ++row) {
for (int column = 0; column < table.columnCount(); ++column) {
table.setItem(row, column, newItem);
model
->setData
(index,
QColor(qrand
()%255, qrand
()%255, qrand
()%255
), Qt
::BackgroundRole);
}
}
table.show();
return app.exec();
}
#include <QtGui>
#include <QApplication>
int main(int argc, char **argv)
{
QApplication app(argc, argv);
QTableWidget table(10, 10);
QAbstractItemModel *model = table.model();
for (int row = 0; row < table.rowCount(); ++row) {
for (int column = 0; column < table.columnCount(); ++column) {
QTableWidgetItem *newItem = new QTableWidgetItem(QObject::tr("%1").arg((row+1)*(column+1)));
table.setItem(row, column, newItem);
const QModelIndex index = model->index(row, column);
model->setData(index, QColor(qrand()%255, qrand()%255, qrand()%255), Qt::BackgroundRole);
}
}
table.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks