]> Some of my projects - localmylist.git/commitdiff
Allow using the return key to open files in MyList TreeView.
authorAPTX <marek321@gmail.com>
Wed, 5 Nov 2014 23:11:58 +0000 (00:11 +0100)
committerAPTX <marek321@gmail.com>
Wed, 5 Nov 2014 23:11:58 +0000 (00:11 +0100)
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
localmylist-management/mylistview.h

index 09a5090ffe284b84bb5cab4e83f1d673ee5434e7..038472c4726288a7cf2ea806fd9703c022777660 100644 (file)
@@ -10,6 +10,7 @@
 #include <QMenu>
 #include <QDesktopServices>
 #include <QUrl>
+#include <QKeyEvent>
 
 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<MyListFilterModel *>(model());
index e500c0fb461d50d6914a6ee2de27c35d0759bfa2..b324364e5c6d5bb08964b3b129b162173abd9fff 100644 (file)
@@ -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);