Details
-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
5.15.16
-
None
Description
If a custom QDoubleSpinBox-delegate is set to a table widget and its keyboardTracking set to false, then the following behavior is to see:
1. User changes a value by keyboad and presses Enter -> value commited to model (correct)
2. User changes a value and presses Esc-> value not commited to model (correct)
but:
3. User changes a value by keyboard and presses Tab or clicks on another cell -> value is NOT commited to model (wrong, should have been commited!)
4. User presses "up" or "down" arrows on the keyboard or by mouse -> value is changed AND written to model (wrong! should be only changed in the editor but still *NOT *commited)
class CSpinEditorDelegate : public QStyledItemDelegate { Q_OBJECT public: CSpinEditorDelegate(QWidget *parent): QStyledItemDelegate(parent) { } virtual QWidget* createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override { QDoubleSpinBox* editor = new QDoubleSpinBox(parent); editor->setKeyboardTracking(false); return editor; } virtual void destroyEditor(QWidget *widget, const QModelIndex &index) const override { } virtual void setEditorData(QWidget *widget, const QModelIndex &index) const override { QDoubleSpinBox* editor = (QDoubleSpinBox*)widget; QVariant v = index.data(Qt::DisplayRole); double value = v.toDouble(); editor->setValue(value); } virtual void setModelData(QWidget *widget, QAbstractItemModel *model, const QModelIndex &index) const override { QDoubleSpinBox* editor = (QDoubleSpinBox*)widget; double value = editor->value(); model->setData(index, value, Qt::DisplayRole); } };