Model is a QSqlTableModel, maybe the changed signal is being emitted, but I don't know if my method is right.
{
QLineEdit *edit
= qobject_cast<QLineEdit
*>
(editor
);
QString oldVal
= index.
model()->data
(index, Qt
::EditRole).
toString();
if (oldVal != newVal)
{
model
->setData
(index, newVal.
remove(QRegExp("[()-]")));
/*
// This is wrong...edit has been destroyed by now.
if ((newVal.left(2) == "04") || (newVal.left(1) == "1"))
edit->setText(newVal.left(2)+"-"+newVal.mid(2,4)+"-"+newVal.mid(6,4));
else
edit->setText("("+newVal.left(2)+")"+newVal.mid(2,4)+"-"+newVal.mid(6,4));
*/
}
}
void LineEditDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index) const
{
QLineEdit *edit = qobject_cast<QLineEdit *>(editor);
QString oldVal = index.model()->data(index, Qt::EditRole).toString();
QString newVal = edit->text();
if (oldVal != newVal)
{
model->setData(index, newVal.remove(QRegExp("[()-]")));
/*
// This is wrong...edit has been destroyed by now.
if ((newVal.left(2) == "04") || (newVal.left(1) == "1"))
edit->setText(newVal.left(2)+"-"+newVal.mid(2,4)+"-"+newVal.mid(6,4));
else
edit->setText("("+newVal.left(2)+")"+newVal.mid(2,4)+"-"+newVal.mid(6,4));
*/
}
}
To copy to clipboard, switch view to plain text mode
I'm stripping away the inputMask characters and checking the first 1 or 2 digits to see which format to apply. I save the edited digits in the model but I want the formatted text displayed (e.g. 04-1234-5678)
Bookmarks