Hi, it's my first post here, but it's not the first time i visited this site in order to find some answers to my problems. This time, however, i haven't seen any post related to what i'm trying to do, so here it goes.

I'm working in a ERP Qt application, in which i use a MYSQL database, and i need to show the data in a table, even i know i can use a QTableModel for accessing the database, i prefer to do the access to the DB on my own, because it's an application in which i would like the maximum control of it, so i used a QTableWidget, and populate it with the data i receive from the DB.

However, the user must be able to insert or modify this data, so i have to set a limit to the strings displayed in the QTableWidget, so they don't insert a longer string, which the DB would not accept.

I've tried to subclass QTableWidget and reimplement the keyPressEvent so it stops the text from exceeding the maximum length, also i've tried to use QLineEdit's as a cellWidget, and limit the length of the lineedits, but it don't like it's behaviour, because it gets the application focus in a strange manner.

I would like to know, which class has the keyPressEvent that "sends" the text into the QTableWidgetItem, because it appears in the Qt Manual that the QTableWidgetItem is not a subclass of QObject nor QWidget and also, it doesn't use the keyPressEvent.

Any help would be very appreciated.

P.S: Sorry for my english, I'm spanish.