View Full Version : How to programmatically change the current Index of QTableView's comboBox ?

Ahmed Abdellatif
31st October 2018, 00:04
I have a tableView that has in its first column a comboBox that works as item delegate. The combo box contains QString values.
When the user double clicks the comboBox item, the comboBox appears and when the user select a value (QString) from the drop Down list, the functions createEditor, setEditorData, setModelData, are called properly and execute code that is depending on the QComboBox current value (current string). That code is found inside the following function
setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index){ ... }
My Problems are:
1. I want to set the value (string ) of the combobox programmatically as if the combobox was clicked by the user from the ui. The problem is that i have no handler to that comboBox to call the function that will set the value of the combobox.

2. if i have the handler to that combobox, which function should i call to set the combo box current text

Please note that:
1.the combobox set value function that will be used is required to be called to do the same effect as the user click
2. the set value function is required to be be called outside the 3 stated functions
3. I have tried the following code :

ui->tableView->model()->setData ( ui->tableView->model()->index(0,0), "item1", Qt::EditRole);

But it only set the combo box value to "item1" but did not call the 3 functions createEditor, setEditorData, setModelData that contains the extra code to be executed.
Any help is appreciated