I noticed this bug as well using Qt 4.5.3 on OpenSUSE 11.0.
I use the following workaround:
Instead of
function table->item(row,col)->setText("new text")
function table->item(row,col)->setText("new text")
To copy to clipboard, switch view to plain text mode
I use
((QLabel *)(function table
->cellwidget
(row,col
)))->setText
("new text")
((QLabel *)(function table->cellwidget(row,col)))->setText("new text")
To copy to clipboard, switch view to plain text mode
Ofcourse you have to change your code in such a way that it use QLabels instead of itemtext's.
Your new code will look like:
#include "bug.h"
#include <QApplication>
#include <QtGui>
Dialog::Dialog()
{
layout->addWidget(table);
layout->addWidget(pb);
connect(pb, SIGNAL(clicked()), this, SLOT(pbClicked()));
table->setRowCount(5);
table->setColumnCount(5);
for(int i=0; i<5; i++)
for(int j=0; j<5; j++){
label->setText("initial");
table->setCellWidget(i, j, label);
}
table->resizeRowsToContents();
}
Dialog::~Dialog()
{
}
void Dialog::pbClicked()
{
for(int i=0; i<5; i++)
for(int j=0; j<5; j++)
((QLabel *)(table
->cellWidget
(i,j
)))->setText
(tr
("Cell %1,%2 modified").
arg(i
).
arg(j
));
}
int main(int argc, char** argv)
{
Dialog dialog;
dialog.show();
return app.exec();
}
#include "bug.h"
#include <QApplication>
#include <QtGui>
Dialog::Dialog()
{
layout=new QVBoxLayout(this);
table=new QTableWidget();
pb=new QPushButton("Press me");
layout->addWidget(table);
layout->addWidget(pb);
connect(pb, SIGNAL(clicked()), this, SLOT(pbClicked()));
table->setRowCount(5);
table->setColumnCount(5);
for(int i=0; i<5; i++)
for(int j=0; j<5; j++){
QLabel *label=new QLabel();
label->setText("initial");
table->setCellWidget(i, j, label);
}
table->resizeRowsToContents();
}
Dialog::~Dialog()
{
}
void Dialog::pbClicked()
{
for(int i=0; i<5; i++)
for(int j=0; j<5; j++)
((QLabel *)(table->cellWidget(i,j)))->setText(tr("Cell %1,%2 modified").arg(i).arg(j));
}
int main(int argc, char** argv)
{
QApplication app(argc, argv);
Dialog dialog;
dialog.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks