Auto commit in QLineEdit in QTableWidget
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
Re: Auto commit in QLineEdit in QTableWidget
Quote:
Originally Posted by Corran
Does anyone have an idea of the best way of going about this?
Maybe you don't need the QLineEdit at all?
Quote:
Originally Posted by Corran
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".
Re: Auto commit in QLineEdit in QTableWidget
If you want to restrict QLineEdit's input, use an inputMask (set to "9" in your case -- this allows a single digit [0-9]).
Re: Auto commit in QLineEdit in QTableWidget
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.