PDA

View Full Version : How to get a QComboBox string from within setData



jmalicke
18th October 2014, 18:50
I have a custom delegate that renders a QComboBox in a table cell.

In my custom table model I have an implementation of setData:


bool ParametersMapTableModel::setData(const QModelIndex & index, const QVariant & value, int32_t role)
{
...

if (index.column() == COL_COMBO_BOX)
{
theDataSource.theSelectedString = value.toString();
}

The problem is that value.toString() returns the value of the selected index, not the string value in the QComboBox.

What is the best way to get the string of the selected index from within setData()?

Of course I can maintain my own QStringList of indexes to strings. I am not sure how to maintain my own list without tightly coupling the model to the view.

ChrisW67
18th October 2014, 22:53
Your delegate's QItemDelegate::setModelData() knows about the combobox, can extract the currentText(), and apply that to the underlying model. Your ParameterMapTable model does not need to know anything about the combo box or how to get the text.