Results 1 to 4 of 4

Thread: Auto commit in QLineEdit in QTableWidget

  1. #1
    Join Date
    Jan 2006
    Location
    England
    Posts
    20
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default 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

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default 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".

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default 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]).

  4. #4
    Join Date
    Jan 2006
    Location
    England
    Posts
    20
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default 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.

Similar Threads

  1. Pointer Question related to QLineEdit
    By ChrisReath in forum Qt Programming
    Replies: 1
    Last Post: 23rd May 2008, 16:13

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.