Results 1 to 3 of 3

Thread: Problem with custom QStyledItemDelegate and tab handling

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,320
    Thanks
    316
    Thanked 870 Times in 857 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Problem with custom QStyledItemDelegate and tab handling

    I have implemented a custom QStyledItemDelegate for editing a cell in a QTableView. The delegate's editor is a QWidget with some radio buttons and two line edits. See the attached screenshots that show the editor widget as a delegate and parented with a QDialog.

    The problem I am having is when the editor is used as a delegate. If I edit the text in either line edit and then press Tab, the editor is immediately closed. The new text is discarded and control goes back to the table view.

    When used in a QDialog, the behavior is normal; Tab moves the focus to the next widget in the tab chain.

    I have installed an event filter on both line edits and watch for FocusOut events. In delegate mode, editing one line edit and then -clicking- on the next generates a focus out event on the first line edit. Editing the first line edit and pressing Tab does not generate a focus out event.

    I have tried setting window modality to Qt::ApplicationModal when using the editor as a delegate. This has no effect on behavior, even though the delegate reports that the editor "isModal" in all of the delegate methods (setEditorData(), setModelData(), updateEditorGeometry() etc.).

    How do I make this editor behave like a modal dialog when used as a delegate? In other words, the user must be forced to click either Ok or Cancel to close the delegate? Do I need to install an event filter on the table view and intercept tabs when the delegate is active?

    AsDelegate.jpg AsDialog.jpg

    EDIT: Installing an event filter on the table view has no effect. After reading more of the QStyledItemDelegate docs, I see that it puts an event filter on the editor which intercepts the Tab key. Overriding this implementation in my derived delegate class has no effect, so it is likely the base class is getting the event first. If I explicitly install my own event filter on the editor class immediately after creating it, there is still no effect, so again, the base class must be getting it first.
    Last edited by d_stranz; 14th April 2020 at 19:39.
    <=== 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.

  2. The following user says thank you to d_stranz for this useful post:

    laurynas2003 (16th April 2020)

Similar Threads

  1. QStyledItemDelegate custom Editor--How to cancel edits
    By davethomaspilot in forum Qt Programming
    Replies: 0
    Last Post: 11th February 2014, 12:43
  2. Replies: 1
    Last Post: 14th June 2011, 03:46
  3. Custom QStyledItemDelegate
    By Berryblue031 in forum Qt Programming
    Replies: 0
    Last Post: 2nd March 2011, 10:32
  4. QStyledItemDelegate with custom QWidget editor
    By stefanadelbert in forum Qt Programming
    Replies: 3
    Last Post: 14th July 2010, 23:19
  5. update custom QStyledItemDelegate after drag
    By dano in forum Qt Programming
    Replies: 1
    Last Post: 17th November 2008, 18:29

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.