PDA

View Full Version : Adding QComboBox to QTableWidget very slow



munna
13th July 2006, 11:07
Hi,

I read a text (csv) file to populate a QTableWidget. The first row contains QComboBox in all the columns. I see that when I do not add any combo box, the table is populated very quickly whereas when I add combo box, it takes a very long time for the table to get populated.

Is there a solution to this?

Here is the code:




void TextFileImporter::importData(const QStringList &lineList)
{
dataTable->setRowCount(lineList.count()+1);

for(int i = 0; i < lineList.count(); ++i){
QStringList columnList = lineList.at(i).split(",");
for(int j = 0; j < columnList.count(); ++j){
if(dataTable->columnCount() == 0){
dataTable->setColumnCount(columnList.count());
}
if(i == 0){
dataTable->addFieldCombo(j);//If comment this line then things are very fast
}
QString cellString = columnList.at(j);
cellString.remove("\"");
dataTable->insertItemAt(i+1,j,cellString);
}
}
}

void DataTable::addFieldCombo(const int column)
{
QComboBox *fieldCombo = new QComboBox(this);
populateFieldCombo(fieldCombo);//This line is not making much a difference

setCellWidget(0,column,fieldCombo);
}


In the debug window I get the following message (lots of time)

QComboBox::setProperty("text", value) failed: property invalid, read-only or does not exist

Any Idea?

munna
13th July 2006, 12:23
Someone (http://lists.trolltech.com/qt-interest/2006-03/thread01790-0.html) else is also having a similar problem but there has not been a reply to it.

Can some one please help me?

Thanks a lot

yogeshm02
13th July 2006, 15:45
QTableWidget is trying to initialise the widget (which you set) by setting the text property, which QComboBox does not has, so the said messages occur. You can verify this by using QLineEdit (or any widget which has the text property). I think Qt will have to have some changes in the behaviour setCellWidget() and other related functions operate. Someone please correct me if I am wrong, as I've not used this feature yet.

What purpose do the combo box serve? If you are using them for editing (via selecting from a list of possible values) you can consider having a custom item delegate, I'm using same method for myself with success.