-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExtendedTreeView.cpp
More file actions
41 lines (38 loc) · 1.48 KB
/
ExtendedTreeView.cpp
File metadata and controls
41 lines (38 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include "ExtendedTreeView.h"
void ExtendedTreeView::mousePressEvent(QMouseEvent* event) {
QModelIndex index = indexAt(event->pos());
if (!index.isValid()) {
QTreeView::mousePressEvent(event);
return;
}
// определяем область стрелки (20px слева)
QRect rect = visualRect(index);
QRect arrowRect(rect.left(), rect.top(), 20, rect.height());
if (arrowRect.contains(event->pos()) && model()->hasChildren(index)) {
if (isExpanded(index))
collapse(index);
else
expand(index);
// не передаём дальше, чтобы не было двойного действия
return;
}
QTreeView::mousePressEvent(event);
}
void ExtendedTreeView::mouseDoubleClickEvent(QMouseEvent* event) {
QModelIndex index = indexAt(event->pos());
if (!index.isValid()) {
QTreeView::mouseDoubleClickEvent(event);
return;
}
QRect rect = visualRect(index);
QRect arrowRect(rect.left(), rect.top(), 20, rect.height());
if (arrowRect.contains(event->pos()) && model()->hasChildren(index)) {
// игнорируем двойной клик по стрелке
return;
}
QTreeView::mouseDoubleClickEvent(event);
}
void ExtendedTreeView::scrollTo(const QModelIndex &index, ScrollHint hint) {
if (!autoScroll) return; // не прокручиваем, если отключен автоскролл
QTreeView::scrollTo(index, hint);
}