Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to set vertical tab order in a QTableWidget
Forum Updated to NodeBB v4.3 + New Features

How to set vertical tab order in a QTableWidget

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 3.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    ryan0270
    wrote on last edited by
    #1

    Seems like it should be simple enough, but Qt is not behaving at all how I expect. I have some standard QTableWidget tables and I'm trying to get them to tab vertical first (rather than the default horizontal first). Here is the function I currently have
    [code]
    void setVerticalTabOrder(QTableWidget *tbl)
    {
    for(int j=0; j<tbl->columnCount(); j++)
    {
    for(int i=0; i<tbl->rowCount()-1; i++)
    QWidget::setTabOrder(tbl->cellWidget(i,j), tbl->cellWidget(i+1,j));
    if(j != tbl->columnCount()-1)
    QWidget::setTabOrder(tbl->cellWidget(tbl->rowCount()-1,j), tbl->cellWidget(0,j+1));
    else
    QWidget::setTabOrder(tbl->cellWidget(tbl->rowCount()-1,j), tbl->cellWidget(0,0));
    }
    }
    [/code]

    Which doesn't seem to change the behavior at all. Searching around I've seen some posts about subclassing QTableWidget and doing custom handling, but I don't see why I need to go through all that effort just to change to vertical first tabbing. More importantly, I want to know why the above doesn't do what I expect.

    Thoughts?

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      I think that QTableWidget manually handles tab key presses so setting tab order on widgets inside the cells doesn't have any effect.
      If you don't want to subclass, you can install an event handler and catch the QEvent::ShortcutOverride events. Then you check for the Qt::Key_Tab or Qt::Key_Backtab and use setCurrentIndex() to traverse in any custom order.

      1 Reply Last reply
      0
      • R Offline
        R Offline
        ryan0270
        wrote on last edited by
        #3

        Since the setTabOrder function is a static under the QWidget class, I was under the impression that this functionality should be relatively independent of the QTableWidget class specifically.

        1 Reply Last reply
        0
        • Chris KawaC Offline
          Chris KawaC Offline
          Chris Kawa
          Lifetime Qt Champion
          wrote on last edited by
          #4

          I didn't look at the actual implementation but "should" might just be the keyword here :)

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved