How to prevent changing selection in QtableView, if the data is invalid?
When adding new data to QtableView/QRelationalTableModel, I need to verify the data entered by the user. The verification is done by using QValidator, but how can I prevent changing from that cell if the data is invalid, and to instruct user to correct the data?
Thanks in advance,
Reimplement the focusOutEvent for the input widget and setFocus() if there is no acceptable input. You can then use a custom delegate to show your input widget.
- class LineEdit : public QLineEdit
- void focusOutEvent(QFocusEvent *event)
- if (((currentFocus_ == this) || (currentFocus_ == 0)) &&
- (hasAcceptableInput() == false))
- currentFocus_ = this;
- currentFocus_ = 0;
- static LineEdit *currentFocus_;
- LineEdit *LineEdit::currentFocus_ = 0;
Brain to terminal. Not tested.