ehamberg
14th March 2008, 17:16
Hi,
I have a QTableView with a QAbstractTableModel and a custom delegate for editing the different fields. For one of the fields I have a QDoubleSpinBox and I want to change the default validator to allow both a comma and a dot to be used as a decimal symbol. However the lineEdit() methond in QDoubleSpinBox is protected, so I get an error. What is the easiest way I can change the spinbox' validator?
The code:
void ExpensesDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
{
if (index.column() == AMOUNT_COLUMN) {
QDoubleSpinBox *amountEditor = qobject_cast<QDoubleSpinBox *>(editor);
amountEditor->lineEdit()->setValidator(new QRegExpValidator(QRegExp("-?[0-9]*[.,]?[0-9]*"), amountEditor)); // <---
amountEditor->setValue(index.model()->data(index, Qt::EditRole).toDouble());
...
I have a QTableView with a QAbstractTableModel and a custom delegate for editing the different fields. For one of the fields I have a QDoubleSpinBox and I want to change the default validator to allow both a comma and a dot to be used as a decimal symbol. However the lineEdit() methond in QDoubleSpinBox is protected, so I get an error. What is the easiest way I can change the spinbox' validator?
The code:
void ExpensesDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
{
if (index.column() == AMOUNT_COLUMN) {
QDoubleSpinBox *amountEditor = qobject_cast<QDoubleSpinBox *>(editor);
amountEditor->lineEdit()->setValidator(new QRegExpValidator(QRegExp("-?[0-9]*[.,]?[0-9]*"), amountEditor)); // <---
amountEditor->setValue(index.model()->data(index, Qt::EditRole).toDouble());
...