[Qt-interest] Subclassed QTableWidget table does not show column header labels after setting them.
Sorin Lazarescu
Sorin.Lazarescu at jdsu.com
Tue Nov 10 19:42:49 CET 2009
Hi everybody
I wonder what could be wrong with my subclassed QTableWidget where after
I set custom column labels but still the table column header labels keep
showing 1, 2, 3,4,5,6,7.
class XmlTable : public QTableWidget
{
Q_OBJECT
public:
XmlTable(QWidget *parent = 0);
}
MainWindow::MainWindow()
{
xmlTable = new XmlTable(this);
//fill 7 column header labels
QStringList labels;
labels << tr("Zone") << tr("InnerDiameter") <<
tr("OuterDiameter") << tr("ResultDefects") << tr("CountDefects") <<
tr("AreaDefects") << tr("ResultScratches") ;
qDebug() << "column labels size is: " << labels.size()
<< endl;
//set number of rows and columns
xmlTable->setRowCount(0);
xmlTable->setColumnCount(labels.size());
//set column header labels here
xmlTable->setHorizontalHeaderLabels(labels);
//CHECK column headers below show that column headers
has been changed to "Zone", "InnerDiameter", "OuterDiameter" ,...
for ( int i = 0; i < labels.size(); i++ )
{
QTableWidgetItem *item =
xmlTable->horizontalHeaderItem(i);
QString text = item->text();
qDebug() << "Header Item Text: " << text
<< endl;
}
setCentralWidget(xmlTable);
}
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
MainWindow mainWin;
mainWin.show();
return app.exec();
}
I created a custom QTableWidget in a MainWindow then the use
QApplication to display it.
I could see that my column headers item contains the labels as they
have been set trough setHorizontalHeaderLabels() function but XmlTable
table display shows always column headers as 1,2,3, 4,5,6,7 instead of
"Zone", "InnerDiameter", "OuterDiameter"
Any idea why I could not see the new column headers labels?
Thanks
Sorin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20091110/f5098292/attachment.html
More information about the Qt-interest-old
mailing list