I have an user interface that uses a TableView. It has 3 columns. The last column has a comboBox. All the data is inserted with the delegate. The problem is I can not find a method to send a signal to a public slot of the user interface class when the combobox index is changed. With the delegate I already know the current index. Do someone know a method to send this index to the ui? I do not think the only possible solution is with signals and slots. Is a direct solution to extract this data?
EDIT
What I understand it is I have to do something like this:
void Delegate :: setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
{
if(index.column() == COL_Coordonate) // test if we are at the last column
{
QComboBox *comboBox = static_cast<QComboBox*>(editor);
model -> setData(index, comboBox -> currentIndex(), Qt::EditRole);
emit dataChanged(comboBox -> currentIndex(),comboBox -> currentIndex()); // something like this you have in mind?
}
}
And how can I receive that index in the user interface? I create my model in there something like:
QStandardItemModel *model;
Delegate *mydelegate;
And use them like:
mydelegate = new Delegate(this);
model = new QStandardItemModel(0, 3, this); // I add rows dynamically
ui -> tableView -> setModel(model);
ui -> tableView -> setItemDelegate (mydelegate);
I add data with the delegate when I press a button. Do I need do trigger a slot from this interface? If so someone can please provide a sample of code about how do I do this?
connect(model, &QAbstractItemModel::dataChanged, this, [=](const QModelIndex & index){ /* your code here */ });
– Kuba hasn't forgotten MonicaQAbstractItemModel
orQStandardItemModel
orQListView
orQTableView
. – Kuba hasn't forgotten Monica