I have a numeric editor that extends the QSpinBox
NumericEditor::NumericEditor(QWidget *widget): QSpinBox(widget)
I use this editor to edit the type QVariant::Int
in the QTableWidget
QItemEditorCreatorBase *numericEditor = new QStandardItemEditorCreator<NumericEditor>();
factory->registerEditor(QVariant::Int, numericEditor);
Data is entered in the table as normal. Ignore the usage of the word "color". Its based off the color editor example.
QTableWidgetItem *nameItem2 = new QTableWidgetItem(QString("label2"));
QTableWidgetItem *colorItem2 = new QTableWidgetItem();
colorItem2->setData(Qt::DisplayRole, QVariant(int(4)));
table->setItem(1, 0, nameItem2);
table->setItem(1, 1, colorItem2);
The spin box appears and works fine in the QTableWidget.
My desire is to get access to the instance of QSpinBox that the table uses when it edits QVariant::Int
cells so I can set the min and max values.
How can I do this?
You can install a delegate on the column with
QTableWidget::setItemDelegateForColumn
, and when an editor is opened, itscreateEditor
method will be called.