18#ifndef INTNUMERICDELEGATE_H
19#define INTNUMERICDELEGATE_H
21#include <QItemDelegate>
45 IntNumericDelegate(QWidget *parent =
nullptr,
int maxValue = 1000000000,
int minValue = -1000000000,
int stepSize = 1,
int value = 0)
46 : QItemDelegate(parent), maxValue(maxValue), minValue(minValue), stepSize(stepSize), value(value) {}
55 QWidget *
createEditor(QWidget *parent,
const QStyleOptionViewItem &option,
const QModelIndex &index)
const override {
56 QSpinBox *editor =
new QSpinBox(parent);
57 editor->setMaximum(maxValue);
58 editor->setMinimum(minValue);
59 editor->setSingleStep(stepSize);
60 editor->setValue(value);
70 void setModelData(QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index)
const override {
71 QSpinBox *spinBox = qobject_cast<QSpinBox *>(editor);
72 int value = spinBox->value();
73 model->setData(index, value, Qt::EditRole);
The IntNumericDelegate class provides a spin box editor for integer numeric data in a view.
Definition intnumericdelegate.h:28
QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override
Creates an editor widget for the given parent, style option, and model index.
Definition intnumericdelegate.h:55
IntNumericDelegate(QWidget *parent=nullptr, int maxValue=1000000000, int minValue=-1000000000, int stepSize=1, int value=0)
Constructor for the IntNumericDelegate class.
Definition intnumericdelegate.h:45
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override
Sets the model data based on the data of the editor widget.
Definition intnumericdelegate.h:70