Results 1 to 2 of 2

Thread: Delegate should not commit on error in editor

  1. #1
    Join Date
    Feb 2013
    Qt products

    Default Delegate should not commit on error in editor


    I'm trying to implement a delegate with a custom editor. This editor can validate its content and return True / False on invalid text input.
    I need to block the commit somehow if an error occurs, but I'm unable to do this.

    I tried implementing eventFilter and throw away the Key_RETURN and Key_ENTER event if the editor contains errors, but the delegate will still accept the input and save the content to the model.
    I also tried implementing commitData but this seems to be called after the editor is closed.

    Is there a way to make sure I can only close the editor / delegate if there are no input errors?

    Right now the validation is a custom funktion isValid(), that simply checks the inputs of both QLineEdit widgets and returns true / false.
    I could write this as a QValidator I guess if neccessary, but I hoped there would be another way to handle this topic.

  2. #2
    Join Date
    Jan 2008
    Alameda, CA, USA
    Thanked 773 Times in 763 Posts
    Qt products
    Windows Android

    Default Re: Delegate should not commit on error in editor

    I think that QValidator exists for this reason. If the input isn't acceptable, it won't let you leave the editor unless you cancel.

    Delegates can be tricky. I ran into a problem like this, using an editable combo box in a table, and finally had to abandon the editing capability because I couldn't find a straightforward way to make it work and didn't want to waste more time on it. It has been a while, but I think my problem was similar to yours - I couldn't prevent the return or tab keys from moving focus and closing the editor when the content was invalid.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. QSqlQueryModel: Delegate with combobox as editor
    By chri in forum Qt Programming
    Replies: 1
    Last Post: 15th October 2020, 10:00
  2. Complex editor in delegate
    By achard.ju in forum Qt Programming
    Replies: 5
    Last Post: 14th March 2015, 08:41
  3. Delegate and editor hide event
    By zuck in forum Qt Programming
    Replies: 1
    Last Post: 1st November 2009, 18:59
  4. svn commit error on XP using Qt creator
    By yycking in forum General Discussion
    Replies: 3
    Last Post: 10th April 2009, 09:47
  5. [delegate] wrong commit for boolean
    By lauranger in forum Qt Programming
    Replies: 3
    Last Post: 26th October 2006, 09:14


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.