Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Tab order of QTableWidget after editing a cell



  • I've got a QTableWidget with 4 columns and many rows in which only several are visible (and the rest can be viewed scrolling down). Each cell is set with setCellWidget() with a QDoubleSpinBox.

    The tab order works as expected initially (In order of cell creation, default order). When I enter or edit a cell anywhere in the list of cells though, the tab order picks up from the last tabbed cell rather than from the cell in which I entered/edited. I would like the tab order to be reset to wherever currently entered.

    • I can accomplish this when setting QTableWidget's setTabKeyNavigation() to false. The issue here is once I tab into a cell out visible range the scrollbar doesn't automatically scroll down.

    • I tried using QLineEdit instead of QDoubleSpinBox but it doesn't matter, same result.

    • I've tried setting the setTabOrder() for each QDoubleSpinBox but does not work.

    • Signals cellPressed(), cellClicked(), itemPressed(), itemClicked() don't work but currentCellChanged() does.

    Any suggestions on approach to resolve here?


  • Lifetime Qt Champion

    Hi,

    Why are you using setCellWidget and not a QDoubleSpinBox based QStyledItemDelegate ?



  • Because I wanted to make all cells editable at once rather than having createEditor() in the delegate called only when double clicking a cell and the remaining cells be read-only.

    Is it possible to do this with QStyledItemDelegate? I have the basic example (from http://doc.qt.io/archives/qt-4.8/qt-itemviews-spinboxdelegate-example.html) working but I need all spinboxes to be editable at once.



  • Alternatively, I could replace the double click with just a single click cell selection to show spinbox ... this would suffice as tabbing would then create the next spinbox.

    https://stackoverflow.com/questions/18831242/qt-start-editing-of-cell-after-one-click suggests doing this on mousepressevent. Would this be your suggestion as well?


Log in to reply