PDA

View Full Version : how to add a complte row at a time in QTableWidget?



aurora
16th November 2011, 04:47
Hi all,

I creating a GUI, i have collection of text files, all these files have some headers and list of number under each header( but they are not actual table).
I want my program to read those files and whenever a user enters a file name, it must read that headers and content must display them in GUI in table format.
I already did the reading of header and content and i can also display the header as well.
Now i stuck with displaying content in the GUI table.

I'm trying to do the following

InserRow(rowNumber, Line)

here line is QStringList.
I dont want to keep count of collumn, as in a file fixed number of column will be there...
How can i do that?

Santosh Reddy
16th November 2011, 06:08
Not sure I understood your question. See if this helps

tableWidget->setColumnCount(Line.count());
for(int col = 0; col < Line.count(); col++)
{
int row = tableWidget.rowCount();
tableWidget->insertRow(row);
tableWidget->setItem(row, col, new QTableWidgetItem(Line.at(col)));
}

ChrisW67
16th November 2011, 06:11
A for() loop?

aurora
16th November 2011, 06:19
Not sure I understood your question. See if this helps

tableWidget->setColumnCount(Line.count());
for(int col = 0; col < Line.count(); col++)
{
int row = tableWidget.rowCount();
tableWidget->insertRow(row);
tableWidget->setItem(row, col, new QTableWidgetItem(Line.at(col)));
}


Thank u santosh...:) i did it...

Added after 6 minutes:

And how can i adjust the collumn width depending on the content?