16 #include <QHeaderView>
17 #include <QMouseEvent>
25 QTableView::setModel(model);
26 setAlternatingRowColors(
true);
27 horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
28 horizontalHeader()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
33 if (!event || event->key() != Qt::Key_Return || state() == QAbstractItemView::EditingState)
34 return QTableView::keyPressEvent(event);
36 const QModelIndex index = currentIndex();
42 Qt::KeyboardModifiers modifiers)
44 const QModelIndex current_index = currentIndex();
45 bool filtered_action = cursorAction == QAbstractItemView::MoveNext
46 || cursorAction == QAbstractItemView::MovePrevious;
48 if (!current_index.isValid() || !
isTextField(current_index) || !filtered_action)
49 return QTableView::moveCursor(cursorAction, modifiers);
51 QModelIndex next = current_index;
53 setCurrentIndex(next);
54 next = QTableView::moveCursor(cursorAction, modifiers);
61 return index.isValid() && index.column() > 1;
66 return index.isValid();
void keyPressEvent(QKeyEvent *event) override
void setModel(QAbstractItemModel *model) override
bool isKeyboardEditable(const QModelIndex &index) const
bool isTextField(const QModelIndex &index) const
QModelIndex moveCursor(QAbstractItemView::CursorAction cursorAction, Qt::KeyboardModifiers modifiers) override
~MaterialTableView() override
Based on Qt example "codeeditor" Copyright (C) 2016 The Qt Company Ltd.