Important: Please read the Qt Code of Conduct -

Add items to combobox depending on another combobox in a tableview set to delegate

  • 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 the setEditorData 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);

  • I was able to get the value of the selected items in the column1 and using it in setEditorData I am adding items to combobox usingaddItems if i get matched selected items from column1

Log in to reply