Add items to combobox depending on another combobox in a tableview set to delegate
Solved
General and Desktop
-
I am using tableview which is set to custom model implemented using
QAbstractTableModel
. Also the tableview is set to combobox delegate . How to Add items to combobox in a treeview set to delegate depending on another combobox .
Suppose i have two colums in a tableview and column 1 has items "A" and "B" . In the column 1 if combobox item is selected to A then item "1" and "2" should be added to combobox of column 2 and if "B" then "1" . -
you can use QAbstractItemDelegate::setEditorData of your delegate to populate items in combo box
@Igor-Y
Thanks for the reply.
I already have thesetEditorData
how can i use it to implement this?void MyDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const { QString value= index.model()->data(index,Qt::DisplayRole).toString(); QComboBox *comboBox = static_cast<QComboBox*>(editor); int itemIndex = comboBox->findText(value); comboBox->setCurrentIndex(itemIndex); }
-
@Igor-Y
Thanks for the reply.
I already have thesetEditorData
how can i use it to implement this?void MyDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const { QString value= index.model()->data(index,Qt::DisplayRole).toString(); QComboBox *comboBox = static_cast<QComboBox*>(editor); int itemIndex = comboBox->findText(value); comboBox->setCurrentIndex(itemIndex); }