Results 1 to 11 of 11

Thread: Adding validation to a QListView's edit mode

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2010
    Posts
    53
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Adding validation to a QListView's edit mode

    Quote Originally Posted by MattT View Post
    That's what I'm doing right now -- I have my own custom delegate which uses a QLineEdit widget as its editor, then hooks into that widget's evenFilter to tell when the user has pressed enter/esc or the widget has lost focus. It works great for keeping the widget open and not saving the data when it is invalid, but the problem is that last one: losing focus. When my widget gets a FocusOut event, I try to prevent it from losing focus, but it doesn't work.

    It also has a bug where it gets a bunch of FocusOut events when the window is closing, which causes my validation code to fire 3 times, and 3 "invalid input" error boxes to popup one after the other, right as the winow should be closing.
    i sad. your own editor. i mean subclass from QLineEdit and reimplement event filter, then send editingFinished(); signal only when your data is valid.
    and for future, read more Qt's documentation. and examples, like this.

  2. #2
    Join Date
    May 2010
    Posts
    10
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Adding validation to a QListView's edit mode

    Even if I create a widget, I still have the problem with losing focus. Creating a new widget doesn't solve the problem, it only makes my problem with delegates a problem with widgets.

    The problem isn't with not sending the edtingFinished() signal -- I have a version of my code which doesn't even use that signal, and uses an event filter on the widget to detect when the user is done editing (presses 'enter' or 'esc', or the widget loses focus) -- it's with getting my widget to retain focus, and at having the FocusOut events fire when the window is closing, causing my "invalid data" error box to pop up a bunch.

    Also, I think your link should be to here You should always check that you're using the latest version of the Qt docs. As you can see, that example has been updated to use the QStyledItemDelegate now.
    Last edited by MattT; 31st July 2010 at 00:33.

  3. #3
    Join Date
    Jul 2010
    Posts
    53
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Adding validation to a QListView's edit mode

    I have a version of my code which doesn't
    QLineEdit automatically sends this signal, read.

  4. #4
    Join Date
    May 2010
    Posts
    10
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Adding validation to a QListView's edit mode

    Yes, but it isn't hooked up to anything by default. The signals that cause the editor to close are commitData and closeEditor, emitted by the delegate. Check the code for QListView/QAbstractItemView, you'll see. I have one version of my code where I hook that signal into one of my delegate's slots in order to validate the data and then, if valid, emit commitData and closeEditor to the ListView and, if not valid, open up an error dialog. The other version of my code doesn't listen for editingFinished, and just uses the QLineEdit's event filter to try to determine when the user has pressed enter, esc or the editor has lost focus. If it does it emits commitData and closeEditor.

  5. #5
    Join Date
    Jul 2010
    Posts
    53
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Adding validation to a QListView's edit mode

    if not valid, open up an error dialog
    and do not close editor inside cell?

    you say you have 2 versions. both are not working?

  6. #6
    Join Date
    May 2010
    Posts
    10
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Adding validation to a QListView's edit mode

    Yup, now we're on the same page.

    The problem isn't with the editor closing -- I can prevent that fine. The problem is with the editor losing focus. How do I keep focus on the editor, even when the user clicks on another widget?

Similar Threads

  1. Multiple clicks required to get into edit mode on QTreeView
    By JonInAnnArbor in forum Qt Programming
    Replies: 10
    Last Post: 26th November 2012, 18:59
  2. Delegates and edit mode while scrolling
    By Kiko in forum Qt Programming
    Replies: 0
    Last Post: 29th November 2009, 13:04
  3. Replies: 8
    Last Post: 23rd October 2009, 15:33
  4. QListView 'details' mode
    By squidge in forum Qt Programming
    Replies: 1
    Last Post: 7th October 2009, 07:55
  5. Adding a line edit in a toolbar
    By borges in forum Qt Tools
    Replies: 1
    Last Post: 16th August 2007, 15:33

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
  •  
Qt is a trademark of The Qt Company.