[quote author="DeVeL-2010" date="1331308421"]
I just recommended to have a function which maps your currentIndex into a QModelIndex.
If you use QAbstractItemModel instead of MyModel for m_pModel in the class QTableViewComboBox, you get rid of the casting. Of course, in this case you must use signal/slot mechanism. In this case it is better to direct connect currentIndexChanged with the slot(!) comboBoxChanged().
[/quote]
Yep! That works - and no nasty casts from const * to * and no connecting of signals and slots on the same object. Thanks for the advice. So the createEditor method in my subclassed combo box now looks like this:
@
QWidget ComboBoxDelegate::createEditor(QWidget parent,
const QStyleOptionViewItem &/ option/ ,
const QModelIndex &index) const
{
const QAbstractItemModel *pModel = index.model();
QTableViewComboBox *editor = new QTableViewComboBox(pModel , index , parent);
/*......*/
connect( editor , SIGNAL( currentIndexChanged(QString)),pModel, SLOT(comboBoxChanged(QString)));
/...../
return editor;
}
@
I was not sure I could 'connect()' with the comboBoxChanged using only a pointer to the base class - but obviously I can; it is taking a while for me to get used to this signal/slot mechanism.
[quote author="DeVeL-2010" date="1331308421"]
On the other hand, it should be possible to overwrite setModelData() of ComboBoxDelegate and call in this function setData(). Advantage: it works also with QSortFilterProxyModel.
Calling data() functions in comboBoxChanged() shouldn't be necessary, because the view will do this after receiving the dataChanged signal.[/quote]
Again you are correct, the data() methods in the comboxBoxChanged slot were not needed after all.
Many thanks - I am more than happy with the code now.
John T.