PDA

View Full Version : How to populate delegate with model data.



kaushal_gaurav
4th August 2008, 09:09
Hi,

I have a class ComboBoxDelegate derived from QItemDelegate
I have a model class 'FrequencyRangeModel' derived from QAbstractProxyModel
I have a BandPlanning for UI which contains both ComboBoxDelegate and FrequencyRangeModel as members.

BandPlanning has a QTableView which is using ComboBoxDelegate to show combobox in each table cell.
My requirement is that i need to populate each combo cell with the data from the model FrequencyRangeModel.
How can i do it.

caduel
4th August 2008, 09:30
Create a QComboBox in QItemDelegate::createEditor() and call QComboBox::setModel() on it with your model?

HTH

aamer4yu
4th August 2008, 09:31
As far as I understand, you are showing a list of items for a particular cell/index/row-col . Am I right ?

In that case you will need to store the list in model. You can use QModelIndex::internalPointer to store whatever data u want and populate the combo box from the pointer returned by internalPointer. In the delegate function, you are passed a QModelIndex.
You may refer Simple Tree Model or Simple DOM Model example in Qt Demo on how they use internalPointer .
Hope this helps :)