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:

Qt Code:
  1. void ExpensesDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
  2. {
  3. if (index.column() == AMOUNT_COLUMN) {
  4. QDoubleSpinBox *amountEditor = qobject_cast<QDoubleSpinBox *>(editor);
  5.  
  6. amountEditor->lineEdit()->setValidator(new QRegExpValidator(QRegExp("-?[0-9]*[.,]?[0-9]*"), amountEditor)); // <---
  7.  
  8. amountEditor->setValue(index.model()->data(index, Qt::EditRole).toDouble());
  9.  
  10. ...
To copy to clipboard, switch view to plain text mode