PDA

View Full Version : Auto commit in QLineEdit in QTableWidget



Corran
7th January 2006, 19:32
This is what I have done so far:
A cell in a QTableWidget is selected and a key is pressed
This causes the GridDelegate (my custom subclass of QItemDelegate) to create the editor (QLineEdit) and set the line edit text to the key I pressed.
Using the cursorPositionChanged(int,int) signal to watch for cursor position changes, when the cursor moves I move it back to the start of the line. This way one can never enter more than one number.However, I can't find a way to implement the following:
When a key is pressed it is instantly committed to the line edit, then the delegate should save this data to the model and the line edit should then lose focus. This is what happens when the enter key is pressed, so I guess simulating an enter key press would do the trick.Does anyone have an idea of the best way of going about this?

I'm using Qt 4.1 under Linux

jacek
7th January 2006, 19:39
Does anyone have an idea of the best way of going about this?
Maybe you don't need the QLineEdit at all?


This causes the GridDelegate (my custom subclass of QItemDelegate) to create the editor (QLineEdit) and set the line edit text to the key I pressed.
Just change this step to "save this data to the model".

wysota
8th January 2006, 22:26
If you want to restrict QLineEdit's input, use an inputMask (set to "9" in your case -- this allows a single digit [0-9]).

Corran
9th January 2006, 18:50
In the end I revised my whole approach. Now I install an eventFilter on the table which only when it recieves keys 1-9 it sets the numbers and ignores all other key presses. It's got exactly the functionallity I need and it does away with the mess of a custom delegate I was using which never seems to work the way it should.