QAbstractItemDelegate and editing
-
There is one more simple solution that I find. In my delegate I need to add connect @ public: void setEditorData(QWidget * editor, const QModelIndex & index) const {
QComboBox * cb = static_cast<QComboBox *>(editor);
QString s = index.data(Qt::DisplayRole).toString();
int i = cb->findText(s);
cb->setCurrentIndex(i);connect(cb, SIGNAL(currentIndexChanged(int)), this, SLOT(onCurrentIndexChanged(int))); }@
And add a slot onCurrentIndexChanged : @public slots: void onCurrentIndexChanged(int index) {
QComboBox * cb = static_cast<QComboBox *>(sender());
emit commitData(cb);
emit closeEditor(cb);
}@
So it solved locally and works pretty well. -
Just want to thanks for this trick, I modified it a little bit so it works with every QWidget editor
1- In createEditor, connect a custom signal in your QWidget Editor to a custom slot in the Delegate
@QWidget *IntervalDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const{
else if (index.column() == 3 ) {
CadenceEditor *editor = new CadenceEditor(parent);
connect (editor, SIGNAL(endEdit()), this, SLOT(closeWidgetEditor()) );
return editor;
}@2- close the editor in the custom delegate slot :
@void IntervalDelegate::closeWidgetEditor() {qDebug() << "CLOSE EDITOR NOW!"; QWidget *editor = qobject_cast<QWidget*>(sender()); emit commitData(editor); emit closeEditor(editor);
}@
-
I can now close the editor with a custom "OK" button, show in this image:
https://www.dropbox.com/s/95agb2c38f9p354/customEditors.pngProblem is when I click the OK button, the click get propaged under it and it open another editor, how can I stop the click? I already have setAttribute(Qt::WA_NoMousePropagation); on my custom QWidget editor..
Thanks