Is there a way to install validator (regex i.e) for a tableMOdel or some cells in this model?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There isn’t any built in support for validation in the model/view system but this wouldn’t be too difficult to do.
In
QAbstractItemModel::setDatayou will need to validate the input, and return false if invalid, store the result of validation somewhere.In [
QAbstractItemModel::datayou could now return a different colour for theQt::BackgroundRolerole to signal something was wrong.In addition, you could implement a custom
QAbstractItemDelegatethis would allow you to create a validating editor, which could provide more feedback to the user.The delegate would then be set on the view with one of the
QAbstractItemView::setItemDelegateorsetItemDelegateFor*functions.