There is a delegate class ComboBoxDelegate : public QStyledItemDelegate , used for QTableView , how to catch the change of the current item in QComboBox? I tried to commitData(QWidget*) for itemDelegateForColumn() and itemChanged(QStandardItem*) for model. setModelData() already triggered when exiting the edit mode, and I need to track on the fly the change of the current list item to generate a new list of items for another delegate combo in another column (and only for the current row).
|
1 answer
You can track the current item in the drop-down list by sending the currentIndexChanged signal of the QComboBox class to the ComboBoxDelegate class level. The signal transfer must be made in the delegate class createEditor method. Example of implementation:
class ComboBoxDelegate : public QStyledItemDelegate { Q_OBJECT ... public: QWidget* ComboBoxDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &/* option */, const QModelIndex &/* index */) const { QComboBox* editor = new QComboBox(parent); editor->addItem(...); editor->addItem(...); ... // "Перебрасываем" сигнал на уровень класса. connect(editor, SINGAL(currentIndexChanged(int)), SINGAL(currentIndexChanged(int)); return editor; } signals: void currentIndexChanged(int index); ... } Thus, in the code that creates instances of the ComboBoxDelegate class, you can intercept the change signal of the current element.
Something similar I have already described here .
|