PDA

View Full Version : table with combobox cells



mgurbuz
9th May 2006, 08:41
Is there anyway to create a table includes combobox cells in Qt 4.1.1 version?
I followed the "delegatespinbox" example to add combobox but wasn't successful.

372

373

374

Thank you for any help

jpn
9th May 2006, 09:30
There is some extra parameter "int col" in DelegateSpinBox::createEditor(), and that's why createEditor() never gets called.

virtual QWidget* QItemDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const (http://doc.trolltech.com/4.1/qitemdelegate.html#createEditor)

Just to get the concept right:
- createEditor() is supposed to create and initialize the editor for the given index. Add combo items, set spin ranges, etc here.
- setEditorData() is supposed to set correct content to the editor when the editing mode starts, you don't need to initialize and/or set editor properties anymore.
- setModelData() is supposed to exchange the data from the editor to the model when the editing mode ends, you don't need to initialize and/or set editor properties here either. (Oh, and btw check DelegateSpinBox::setModelData(), in "index.column() == 3", 3 should be 2).

mgurbuz
10th May 2006, 12:12
Thank you for your help.
It works just fine...



There is some extra parameter "int col" in DelegateSpinBox::createEditor(), and that's why createEditor() never gets called.

virtual QWidget* QItemDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const (http://doc.trolltech.com/4.1/qitemdelegate.html#createEditor)

Just to get the concept right:
- createEditor() is supposed to create and initialize the editor for the given index. Add combo items, set spin ranges, etc here.
- setEditorData() is supposed to set correct content to the editor when the editing mode starts, you don't need to initialize and/or set editor properties anymore.
- setModelData() is supposed to exchange the data from the editor to the model when the editing mode ends, you don't need to initialize and/or set editor properties here either. (Oh, and btw check DelegateSpinBox::setModelData(), in "index.column() == 3", 3 should be 2).