Again QTableWidget and QComboBox delegate
I've gone through the older threads about this subject but didn't find anything regarding my problem at hand:
So I'm creating a QTableWidget which has some of its columns using a custom delegate which returns a QComboBox editor. My problem is that I cannot get it to work in all situations.
For example, I have my own ExcelDlg Dialog and in its constructor I create a QTableWidget and set it to using my delegate.
Like this:
Code:
values
<< "DESC"
<< "POS"
<< "ABNORMAL INTERRUPTION"
<< "TESTI VAAN"
<< "VIELÄ YKS";
cDropdownTableWidgetItemDelegate delegate;
delegate.setValues(values);
table->setItemDelegate(&delegate);
lo->addWidget(table);
Unfortunately the result is an empty table, no cells of any kind, only horizontal and vertical header items are displayed correctly.
But when I use it in a newly created dialog, for example:
Code:
values
<< "DESC"
<< "POS"
<< "ABNORMAL INTERRUPTION"
<< "TESTI VAAN"
<< "VIELÄ YKS";
cDropdownTableWidgetItemDelegate delegate;
delegate.setValues(values);
table->setItemDelegate(&delegate);
dlg->exec();
It works fine. What is happening? Why is it not working in the upper example?
If needed, i can post the code to my delegate.
Re: Again QTableWidget and QComboBox delegate
In the first case the item delegate goes out of scope (you might want to allocate it on the heap instead). In the second case QDialog::exec() blocks so the stack object remains valid until the dialog is accepted or rejected.
Re: Again QTableWidget and QComboBox delegate
It works! I should've seen that happening myself, though...
Thank you for your help!