Results 1 to 2 of 2

Thread: set Tab Order in a QTableWidget

  1. #1
    Join Date
    Jul 2007
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default set Tab Order in a QTableWidget

    Hello, I have the following problem:

    I have a QTableWidget with 3 rows and 4 columns. The first 3 columns of each row are fixed with written data, but the last column is always editable.
    It looks kind of like this, when f is a fixed cell and the _ is an editable cell:

    f f f _
    f f f _
    f f f _

    What I want to happen is that once the user is in the first editable cell and clicks tab, it should jump to the next editable cell and so on.

    I am using only QTableWidgetItems in the QTableWidget. This is why the function QWidget::setTabOrder( QWidget*, QWidget*) does not work, because a QTableWidgetItem is not derived from QWidget

    Any ideas how else I could do that?

    I am using Qt 4.2.2 on Windows

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: set Tab Order in a QTableWidget

    The easiest way might be to reimplement QAbstractItemView::focusNextPrevChild():
    Qt Code:
    1. bool MyTableWidget::focusNextPrevChild(bool next)
    2. {
    3. // check if current column is the editable column
    4. int currentColumn = currentItem() ? currentItem->column() : -1;
    5. if (tabKeyNavigation() && currentColumn == 3)
    6. {
    7. // Qt::Key_Down instead of Qt::Key_Tab and Qt::Key_Up instead of Qt::Key_Backtab
    8. QKeyEvent event(QEvent::KeyPress, next ? Qt::Key_Down : Qt::Key_Up, Qt::NoModifier);
    9. keyPressEvent(&event);
    10. if (event.isAccepted())
    11. return true;
    12. }
    13. return QTableWidget::focusNextPrevChild(next);
    14. }
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  3. The following user says thank you to jpn for this useful post:

    azalea (9th March 2018)

Similar Threads

  1. QComboBox in QTableWidget : display troubles.
    By Nyphel in forum Qt Programming
    Replies: 2
    Last Post: 13th October 2007, 23:29
  2. QTableWidget (resizing rows, turning off selection, etc.)
    By kiss-o-matic in forum Qt Programming
    Replies: 6
    Last Post: 11th January 2007, 01:57
  3. QTableWidget editing question
    By Trasmeister in forum Qt Programming
    Replies: 1
    Last Post: 20th September 2006, 18:46
  4. Replies: 6
    Last Post: 5th March 2006, 21:05
  5. Replies: 1
    Last Post: 26th February 2006, 05:52

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.