PDA

View Full Version : How to set limits on the text entered in any cell of a QTableView?



Mezzo
9th April 2011, 16:56
Hello,

I'm trying to do a crossword game using QT. I'm using QTableView for this and It should be that the user can enter one and only one letter in any of the editable cells in the QTableView. The problem is that I cannot seem to figure out how to put limits or restrictions on what the user can enter in each editable cell. How to do it? I have looked at QT documentation, searched online, looked in key/mouse events in QT but still I did not get how to do it. Any help well be appreciated. Thank you.

viulskiez
9th April 2011, 22:27
Use delegate and create your own editor. For example, if the editor is an instance of QLineEdit, then you can simply set the maximumLength property to 1.

Check this Qt example:
Spin Box Delegate Example (http://doc.qt.nokia.com/latest/itemviews-spinboxdelegate.html)

Hopefully can help you..