[SOLVED] Delegate at QTableView
-
Hi All, I have QTableView, at some of column I set delegate, and at that delegate create QLineEdit, and set them RegExpValidator, but some times that RegExpValidator dosen't work, and i don't understand why... :(
code of delegate:
@public: QWidget * createEditor(QWidget * parent, const QStyleOptionViewItem & /option/, const QModelIndex & /index/) const {
QLineEdit * editWidget = new QLineEdit(parent);
connect(editWidget, SIGNAL(textEdited(const QString &)), this, SLOT(onTextEdited(const QString &)));
QString regExpStr = "[";
//... add valid chars to regExpStr;
regExpStr+="]*";
QRegExp regExp(regExpStr);
regExp.setCaseSensitivity(Qt::CaseInsensitive);
editWidget->setValidator(new QRegExpValidator(regExp, parent));
return editWidget;
}
//--------------------------------------------------------------------------------------------------
public: void setEditorData(QWidget * editor, const QModelIndex & index) const {
QString value = index.data(Qt::EditRole).toString();
((QLineEdit )editor)->setText(value);
}
//--------------------------------------------------------------------------------------------------
public: void setModelData(QWidget * editor, QAbstractItemModel * model, const QModelIndex & index) const {
QLineEdit * edit = (QLineEdit )editor;
QString value = edit->text();
model->setData(index, value, Qt::EditRole);
}
//--------------------------------------------------------------------------------------------------
private slots: void onTextEdited(const QString &txt){
((QLineEdit)sender())->setText(txt.toUpper());
}@
variable regExpStr equals "[-XAGSRCF]" or "[-X#0-9]" -
by “doesn’t work”, i mean so some times i (user) can write not valid data to LineEdit, but when i set a breakpoint to look what regExp set to validator, validator start work correctly.
-
no more ideas?
-
tnx, all for help!
I'm solve this problem by myself.
Validator doesn't work when the text in QLineEdit is programmatically sets to not valid.
I solve this problem to set additional validation to the setEditorData function.