It was already possible to open files with the return key from
the filter box, but not when navigating the actual TreeView.
#include <QMenu>
#include <QDesktopServices>
#include <QUrl>
+#include <QKeyEvent>
MyListView::MyListView(QWidget *parent) :
QTreeView(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());
public:
explicit MyListView(QWidget *parent = 0);
+protected:
+ void keyPressEvent(QKeyEvent *event);
+
signals:
void openFileRequested(const QModelIndex &index);
void renameFilesRequested(const QModelIndex &index);