adding items in qtablewidget
Hi, I am having problems to show cells in my qtablewidget. These are parts of code that I use to implement qtablewidgetitems:
tableTestSuits->setRowCount(0); // tableTestSuits is QTablewidget *
for (unsigned j=0; j<vTestCaseResults.size();j++)
{
.......
QTableWidgetItem *item=new QTableWidgetItem (tr(tempName.toLatin1()));
QTableWidgetItem *item3=new QTableWidgetItem (tr(tempVersion.toLatin1()));
QTableWidgetItem *item5=new QTableWidgetItem (tr(tempResult.toLatin1()));
QTableWidgetItem *item2=new QTableWidgetItem (tr(tempDate.toLatin1()));
QTableWidgetItem *item4=new QTableWidgetItem (tr(tempDuration.toLatin1()));
tableTestSuits->insertRow(j);
tableTestSuits->setItem(j,0,item2);
tableTestSuits->setItem(j,3,item4);
tableTestSuits->setItem(j,4,item5);
tableTestSuits->setItem(j,1,item3);
tableTestSuits->setItem(j,2,item);
}
I am pretty sure that strings for qtablewidgetitems are ok. So, there must be something else wrong, but I don't know what. Any suggestions welcomed.
Re: adding items in qtablewidget
What value did you set the columnCount to?
Re: adding items in qtablewidget
Re: adding items in qtablewidget
OK, do you see row and column labels on the table headers?
Re: adding items in qtablewidget
I see solumn headers, yes, but row headers no, because I've hide it with verticalHeader()->hide() method.
Re: adding items in qtablewidget
Quote:
Originally Posted by
Djony
I see solumn headers, yes, but row headers no, because I've hide it with verticalHeader()->hide() method.
Can you see them, if you comment out that line?
Re: adding items in qtablewidget
Re: adding items in qtablewidget
I'd still suspect the problem is with those strings. What happens if you replace:
with something like
?
Re: adding items in qtablewidget
I tried your stuff and it doesn't work, but found out very odd thing.
When I replace j with zero (that means this code):
tableTestSuits->insertRow(0);
tableTestSuits->setItem(0,0,item2);
tableTestSuits->setItem(0,3,item4);
tableTestSuits->setItem(0,4,item5);
tableTestSuits->setItem(0,1,item3);
tableTestSuits->setItem(0,2,item);
-----------------------------------------------
I get cell properly. I found this very odd. Have any ideas about it?
Re: adding items in qtablewidget
Quote:
Originally Posted by
Djony
When I replace j with zero [...] I get cell properly. I found this very odd. Have any ideas about it?
What is the value of "j" just before the insertRow() line?
Re: adding items in qtablewidget
j is parameter of for loop. Look my first post on this topic
Re: adding items in qtablewidget
Quote:
Originally Posted by
Djony
j is parameter of for loop. Look my first post on this topic
I see it, but there's also "......." in the beginning of the loop body --- maybe you do something with it there?
Re: adding items in qtablewidget
No, I don't do anything with it. Just use for indexing. Still, have no idea. Very odd...
Re: adding items in qtablewidget
Does this work on your system?
Code:
#include <QApplication>
#include <QTableWidget>
const int nRows = 10;
const int nCols = 10;
int main( int argc, char **argv )
{
tw.setColumnCount( nCols );
for( int i = 0; i < nRows; ++i ) {
tw.insertRow( i );
for( int j = 0; j < nCols; ++j ) {
tw.setItem( i, j, item );
}
}
tw.show();
return app.exec();
}
Re: adding items in qtablewidget
Yes, it runs OK. Funny, though, I've noticed some other things about my code for qtablewidget. For some iterations, qtablewidgets prints ok, and for some input not. I understand that strings are most suspicious, but, i've printed them with cout in console, and they are OK, just as they should be. Plus, if I just replace j with zero, code runs well. If I changed just index of rows, then strings aren't problem. Am I wright?
Re: adding items in qtablewidget
Quote:
Originally Posted by
Djony
but, i've printed them with cout in console, and they are OK,
What did you try to print exactly? "tr(tempName.toLatin1())" or only "tempName"?
Re: adding items in qtablewidget
i've printed tempName.toStdString()
Re: adding items in qtablewidget
Then try printing tr(tempName.toLatin1()).toStdString(). Maybe it gets translated to an empty string?