Adding QComboBox to QTableWidget very slow
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:
Code:
void TextFileImporter
::importData(const QStringList &lineList
) {
dataTable->setRowCount(lineList.count()+1);
for(int i = 0; i < lineList.count(); ++i){
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)
{
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?
Re: Adding QComboBox to QTableWidget very slow
Someone 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
Re: Adding QComboBox to QTableWidget very slow
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.