Results 1 to 2 of 2

Thread: QTableWidget editing question

  1. #1
    Join Date
    Sep 2006
    Posts
    6
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default QTableWidget editing question

    (Qt 4.1.4)

    I've created a standard QTableWidget in a GUI, and I'm using a reimplementation of QItemDelegate so I can provide my own custom mechanism to edit the data contained within that QTableWidget. I'm using QDoubleSpinBox and QComboBox as my custom editing widgets. This all works happily, but my problems stem from defining how the editing is triggered.

    What I want to happen is to be able to navigate between the cells (using direction arrows), and kick-off a cell edit by pressing any key, 'Return' or 'Space' keys.


    If I set up the following edit trigger flags on the QTableWidget as follows:

    Qt Code:
    1. QAbstractItemView::DoubleClicked |
    2. QAbstractItemView::SelectedClicked |
    3. QAbstractItemView::EditKeyPressed |
    4. QAbstractItemView::AnyKeyPressed
    To copy to clipboard, switch view to plain text mode 

    The behaviour I get is that whenever you enter text, (EG: '1', 'g', 'Z' etc..), the edit is triggered, but editing is NOT triggered on a 'return' or 'space' key stroke.

    Alternatively, if I set the edit trigger flags as follows:

    Qt Code:
    1. QAbstractItemView::AllEditTriggers
    To copy to clipboard, switch view to plain text mode 

    I now acheived the desired result of having the edit triggered by a 'space' or 'return', but I also have the undesired result of having any movement onto a new cell triggering an edit. This is a problem because the spin and combo boxes take control of the up and down key strokes; essentially meaning that you can't swiftly or easily navigate the QTableWidget without cancelling the edit (either by 'return' or 'enter').


    So, in essence my problem seems to be that I can either have 'Space' and 'Return' start an edit, OR I can have navigation between cells without automatically starting an edit, but not both (which is what I'm looking for!)


    While it's possible to hook in to the key press event (either by superclassing QTableWidget, or by installing an event filter), I was wondering if there was a simple way of acheiving the desired behaviour, whether I've done, or missed something rather silly!

    Thanks!

    -Martin

  2. #2
    Join Date
    Aug 2006
    Location
    Zürich, Switzerland
    Posts
    23
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableWidget editing question

    Hi Martin

    This is just an idea and not based on experience. When you look at the Qt doc of the QItemDelegate class you see that the default implementation of the eventFilter() handles Enter and Return keys to terminate editing:

    bool QItemDelegate::eventFilter ( QObject * object, QEvent * event ) [virtual protected]

    If the object is the current editor: if the event is an Esc key press the current edit is cancelled and ended, or if the event is an Enter or Return key press the current edit is accepted and ended. If editing is ended the event filter returns true to signify that it has handled the event; in all other cases it does nothing and returns false to signify that the event hasn't been handled.

    So instead of trying to make the QTableWidget behave as desired you could try to focus on the item delegate and implement your own eventFilter().

    Ernst

Similar Threads

  1. QTableWidget Update - slow
    By DPinLV in forum Qt Programming
    Replies: 16
    Last Post: 18th August 2006, 21:09
  2. Replies: 6
    Last Post: 5th March 2006, 21:05
  3. QTableWidget column and row sizes
    By Arthur in forum Qt Programming
    Replies: 4
    Last Post: 27th January 2006, 11:03
  4. Updating a QTableWidget through a Dialog
    By dragon in forum Newbie
    Replies: 3
    Last Post: 19th January 2006, 21:16
  5. How to obtain the width of a QTableWidget?
    By Giel Peters in forum Qt Programming
    Replies: 3
    Last Post: 9th January 2006, 22:34

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.