I have a QTableView and i wanted the user to be able to select a whole row rather than individual cell. So i changed the selection behavior as shown below.
table->setSelectionBehavior(QAbstractItemView::SelectRows)
But now when the tab key is clicked it still walks through individual cells rather than whole row. I want the user to be able to walk through each row rather individual cells.
You must inherit from QTableView class and override keyPressEvent(). For example:
#include <QTableView>
#include <QKeyEvent>
class CustomView : public QTableView
{
Q_OBJECT
// QWidget interface
protected:
void keyPressEvent(QKeyEvent *event) {
switch(event->key()) {
case Qt::Key_Tab: {
if(currentIndex().row() != model()->rowCount())
selectRow(currentIndex().row() + 1);
break;
}
default: QTableView::keyPressEvent(event);
}
}
public:
explicit CustomView(QWidget *parent = 0);
~CustomView(){}
signals:
public slots:
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With