PDA

View Full Version : QTableView QItemDelegate validation



pippo42
26th February 2010, 10:27
Hello!

I am trying to prevent the user to enter to enter incorrect values in a QTableView. What I would like to do is check the contents of the cell at the end of the edition and prevent the user to leave to editor if the value is wrong.

I have been playing with a QItemDelegate and with the signal closeEditor. What would be the proper way to do it?

The ideal that I would like to achieve is, in case of an error, to prevent the user to leave the editor of a cell and even to prevent him from saving the data.

Thank you!

bmhautz
26th February 2010, 16:18
If your editor is using a QLineEdit, QComboBox, or QSpinBox, then each of these widgets has a setValidator function for a QValidator subclass.

Look here for more info: http://qt.nokia.com/doc/4.6/qvalidator.html

yodasoda
26th February 2010, 18:51
I concur, you dont need to go through all that trouble, just use the validator and it works even as the user is entering the data so you dont have to wait till the end.

pippo42
8th March 2010, 09:23
Thanks I will try with the validator.

Sorry for not replying earlier. I was abroad.