From 569932e32439d8f6baa5e2ca562283f6ecb84cbd Mon Sep 17 00:00:00 2001 From: APTX Date: Thu, 6 Nov 2014 00:11:58 +0100 Subject: [PATCH] Allow using the return key to open files in MyList TreeView. It was already possible to open files with the return key from the filter box, but not when navigating the actual TreeView. --- localmylist-management/mylistview.cpp | 14 ++++++++++++++ localmylist-management/mylistview.h | 3 +++ 2 files changed, 17 insertions(+) diff --git a/localmylist-management/mylistview.cpp b/localmylist-management/mylistview.cpp index 09a5090..038472c 100644 --- a/localmylist-management/mylistview.cpp +++ b/localmylist-management/mylistview.cpp @@ -10,6 +10,7 @@ #include #include #include +#include MyListView::MyListView(QWidget *parent) : QTreeView(parent) @@ -50,6 +51,19 @@ MyListView::MyListView(QWidget *parent) : } } +void MyListView::keyPressEvent(QKeyEvent *event) +{ + if (event->key() == Qt::Key_Return && currentIndex().isValid()) + { + emit openFileRequested(currentIndex()); + event->accept(); + } + else + { + QTreeView::keyPressEvent(event); + } +} + MyListFilterModel *MyListView::myListFilterModel() const { return qobject_cast(model()); diff --git a/localmylist-management/mylistview.h b/localmylist-management/mylistview.h index e500c0f..b324364 100644 --- a/localmylist-management/mylistview.h +++ b/localmylist-management/mylistview.h @@ -12,6 +12,9 @@ class MyListView : public QTreeView public: explicit MyListView(QWidget *parent = 0); +protected: + void keyPressEvent(QKeyEvent *event); + signals: void openFileRequested(const QModelIndex &index); void renameFilesRequested(const QModelIndex &index); -- 2.52.0