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?.
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?.
Last edited by thefatladysingsopera; 30th May 2011 at 15:06. Reason: Had written Qtableview intead of Qtablewidget,the question changed completely as a result.
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
Bookmarks