PDA

View Full Version : ComboBox of bmp:s



SailinShoes
5th March 2008, 14:41
I am trying to get a delegate with a combobox of bmp:s to work in a qtablewidget.

My problem is QVariant. I can get the combobox to work with strings, int, double...but not with a QIcon.

It is not possible to do it this way, since QVariant dont take a QIcon.


QIcon icon(QPixmap("./icons/check.bmp"));
item1->setIcon(icon);
item1->setData(Qt::EditRole, QVariant(icon));

and in the delegates setModelData...


ComboBox *comboBox = static_cast<ComboBox*>(editor);
int pos = comboBox->currentIndex();

QIcon icon = comboBox->itemIcon(pos);
model->setData(index, icon, Qt::EditRole);

How can I solve this?

wysota
5th March 2008, 15:15
Use Qt::DecorationRole instead of Qt::EditRole.

SailinShoes
5th March 2008, 15:22
Thank you very much wysota...