View Full Version : fill cells in a tableWidget
edgar
27th August 2009, 17:18
hi..
I'm starting with Qt
I don't know how can I fil a TableWidget with values.
Can u help me?
thanks....
vfernandez
27th August 2009, 18:55
As the documentation states (http://doc.trolltech.com/4.5/qtablewidget.html#details):
Items are created ouside the table (with no parent widget) and inserted into the table with setItem():
QTableWidgetItem *newItem = new QTableWidgetItem(tr("%1").arg(
(row+1)*(column+1)));
tableWidget->setItem(row, column, newItem);
First you have to specify how many rows and columns should the table have using setRowCount() and setColumnCount().
Example:
tableWidget->setRowCount(10);
tableWidget->setColumnCount(3);
for(int row = 0; row < 10; row++) {
for(int column = 0; column < 3; column++) {
QString text = QString::number(row) + "," + QString::number(column);
QTableWidgetItem *item = new QTableWidgetItem(text);
tableWidget->setItem(row, column, item);
}
}
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.