1#ifndef DESELECTABLETREEVIEW_H
2#define DESELECTABLETREEVIEW_H
4#include <QCoreApplication>
35 bool doubleClickHappened =
false;
36 bool clickSelected =
false;
42 virtual void mousePressEvent(QMouseEvent *event) {
43 clickSelected = selectionModel()->isSelected(indexAt(event->pos()));
44 QTreeView::mousePressEvent(event);
51 void mouseReleaseEvent(QMouseEvent *event) {
52 doubleClickHappened =
false;
54 QTime dieTime = QTime::currentTime().addMSecs(200);
55 while (QTime::currentTime() < dieTime)
56 QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
58 if (!doubleClickHappened && clickSelected) {
59 QModelIndex item = indexAt(event->pos());
60 bool selected = selectionModel()->isSelected(indexAt(event->pos()));
61 if ((item.row() == -1 && item.column() == -1) || selected) {
63 const QModelIndex index;
64 selectionModel()->setCurrentIndex(index, QItemSelectionModel::Select);
67 QTreeView::mouseReleaseEvent(event);
70 QTreeView::mouseReleaseEvent(event);
72 clickSelected =
false;
79 void mouseDoubleClickEvent(QMouseEvent *event) {
80 doubleClickHappened =
true;
81 QTreeView::mouseDoubleClickEvent(event);
The DeselectableTreeView class loosly based on http://stackoverflow.com/questions/2761284/ thanks to ...
virtual ~DeselectableTreeView()
~DeselectableTreeView standard destructor
DeselectableTreeView(QWidget *parent)
DeselectableTreeView standard constructor.
void emptyClicked()
emptyClicked event