16 #include <QHeaderView>
17 #include <QMouseEvent>
25 setAlternatingRowColors(
true);
26 setSelectionBehavior(QAbstractItemView::SelectRows);
27 setSelectionMode(QAbstractItemView::ExtendedSelection);
29 header()->setSectionResizeMode(QHeaderView::Stretch);
34 QTreeView::setModel(model);
40 if (!event || event->key() != Qt::Key_Return || state() == QAbstractItemView::EditingState)
41 return QTreeView::keyPressEvent(event);
43 const QModelIndex index = currentIndex();
49 Qt::KeyboardModifiers modifiers)
51 const QModelIndex current_index = currentIndex();
52 bool filtered_action = cursorAction == QAbstractItemView::MoveNext
53 || cursorAction == QAbstractItemView::MovePrevious;
55 if (!current_index.isValid() || !
isTextField(current_index) || !filtered_action)
56 return QTreeView::moveCursor(cursorAction, modifiers);
58 QModelIndex next = current_index;
60 setCurrentIndex(next);
61 next = QTreeView::moveCursor(cursorAction, modifiers);
68 return index.isValid() && index.column() > 0;
73 return index.isValid();
bool isKeyboardEditable(const QModelIndex &index) const
QModelIndex moveCursor(QAbstractItemView::CursorAction cursorAction, Qt::KeyboardModifiers modifiers) override
bool isTextField(const QModelIndex &index) const
void setModel(QAbstractItemModel *model) override
void keyPressEvent(QKeyEvent *event) override
MaterialTreeView(QWidget *parent=nullptr)
~MaterialTreeView() override
Based on Qt example "codeeditor" Copyright (C) 2016 The Qt Company Ltd.