PDA

View Full Version : Again QTableWidget and QComboBox delegate



Aki-Matti
4th March 2008, 12:53
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:


QStringList values;
values
<< "DESC"
<< "POS"
<< "ABNORMAL INTERRUPTION"
<< "TESTI VAAN"
<< "VIELÄ YKS";

cDropdownTableWidgetItemDelegate delegate;
delegate.setValues(values);

QTableWidget *table = new QTableWidget(2,3,this);
table->setItemDelegate(&delegate);

lo = new QHBoxLayout();
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:


QStringList values;
values
<< "DESC"
<< "POS"
<< "ABNORMAL INTERRUPTION"
<< "TESTI VAAN"
<< "VIELÄ YKS";

cDropdownTableWidgetItemDelegate delegate;
delegate.setValues(values);

QDialog *dlg = new QDialog();

QTableWidget *table = new QTableWidget(2,3,dlg);
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.

jpn
4th March 2008, 13:04
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.

Aki-Matti
4th March 2008, 13:40
It works! I should've seen that happening myself, though...

Thank you for your help!