Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-136749

QTableWidget with QDoubleSpinBoxDelegate does not behave properly if keyboardTracking is set to false

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 5.15.16
    • Widgets: Itemviews
    • None
    • Windows

    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);
          }
      };
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            ars.masiuk Ars Masiuk
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes