PDA

View Full Version : Qtablewidget example



thefatladysingsopera
30th May 2011, 12:28
I have designed a ui with a qtablewidget and i now want to write the code for it for populating it with data.

How will my function look like responsible for populating qtablewidget with data look like?.

wysota
30th May 2011, 14:08
You need to implement a model and attach it to your view.

Ceaser88
29th July 2011, 09:27
i'm very new to Qt(only been working on it for a couple of weeks now) so i don't guarantee this is the best solution but it works for me:

ui->tableWidget->setRowCount(5); //just make sure your table has rows for you to populate

QTableWidgetItem* item= new QTableWidgetItem("whatever text u want");
ui->tableWidget->setItem(0,1,item); //choose the cell u want for your item

for icons use:
QTableWidgetItem* icon = new QTableWidgetItem();
realEstateIcon->setIcon(QIcon(QPixmap(":/images/RealEstate.png")));
ui->tableWidget->setItem(0,0,icon);

you can create a loop that inserts as many as you want by changing the rows and columns in the setItem function