QTableWidget, any easy way to make only some items tab stoppable
Solved
General and Desktop
-
Hi
What is stoppable and unstoppable ?
Never seen these words in relation to QTableWidgetItem :) -
Hi
What is stoppable and unstoppable ?
Never seen these words in relation to QTableWidgetItem :) -
@mrjj For example
- a 2x2 table
- focus on cell (0,1)
- press Tab key, focus to cell(1.1) instead of cell(1,0)
Is there any built in support for this?
@jronald
HI
I think
http://doc.qt.io/qt-5/qabstractitemview.html#moveCursor
can be used but I have not tested it. -
@jronald
HI
I think
http://doc.qt.io/qt-5/qabstractitemview.html#moveCursor
can be used but I have not tested it. -
Try reimplementing
moveCursor
#include <QTableWidget> #include <QAbstractItemModel> class MyTableWidget : public QTableWidget{ Q_OBJECT Q_DISABLE_COPY(MyTableWidget) public: explicit MyTableWidget(QWidget* parent = Q_NULLPTR) :QTableWidget(parent) {} protected: QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers) Q_DECL_OVERRIDE{ QModelIndex beginIdx = currentIndex(); QModelIndex currIdx, prevIdx; if(model()){ for(;;){ currIdx = QTableWidget::moveCursor(cursorAction,modifiers); if(!beginIdx.isValid()) beginIdx=currIdx; if(!currIdx.isValid()) break; if(model()->flags(currIdx) & Qt::ItemIsSelectable) break; if(currIdx==beginIdx) break; if(prevIdx==currIdx) break; prevIdx=currIdx; setCurrentIndex(currIdx); } } return currIdx; } };