From 2608a1bc79324cac504829bdae5630d69c3d27c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Du=C5=A1an=20Poizl?= Date: Tue, 14 Nov 2023 16:30:38 +0100 Subject: [PATCH] Add tooltip with filenames --- databaseview.cpp | 4 ++++ filesystemwidget.cpp | 8 +++++++- filesystemwidget.h | 9 ++++++++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/databaseview.cpp b/databaseview.cpp index c62389b..4429f86 100644 --- a/databaseview.cpp +++ b/databaseview.cpp @@ -123,6 +123,10 @@ QVariant FITSFileModel::data(const QModelIndex &index, int role) const font.setBold(m_markedFiles.contains(file)); return font; } + if(role == Qt::ToolTipRole && index.column() == 0) + { + return QSqlQueryModel::data(index, Qt::DisplayRole); + } return QSqlQueryModel::data(index, role); } diff --git a/filesystemwidget.cpp b/filesystemwidget.cpp index 9a1ae3f..7d1a06b 100644 --- a/filesystemwidget.cpp +++ b/filesystemwidget.cpp @@ -45,11 +45,17 @@ void FilesystemWidget::fileClicked(const QModelIndex &index, const QModelIndex & emit fileSelected(index.row()); } +QVariant FileSystemModel::data(const QModelIndex &index, int role) const +{ + if(role == Qt::ToolTipRole && index.column() == 0)role = Qt::DisplayRole; + return QFileSystemModel::data(index, role); +} + Filetree::Filetree(QWidget *parent) : QTreeView(parent) { QSettings settings; m_rootDir = settings.value("filetree/rootDir", QDir::homePath()).toString(); - m_fileSystemModel = new QFileSystemModel(this); + m_fileSystemModel = new FileSystemModel(this); m_fileSystemModel->setRootPath(m_rootDir); m_fileSystemModel->setNameFilters({"*.fits", "*.fit", "*.xisf", "*.jpg", "*.jpeg", "*.png", "*.cr2", "*.nef", "*.dng"}); m_fileSystemModel->setNameFilterDisables(false); diff --git a/filesystemwidget.h b/filesystemwidget.h index 936b4cf..52b8c9c 100644 --- a/filesystemwidget.h +++ b/filesystemwidget.h @@ -23,10 +23,17 @@ signals: void reverseSort(); }; +class FileSystemModel : public QFileSystemModel +{ +public: + explicit FileSystemModel(QObject *parent) : QFileSystemModel(parent){} + QVariant data(const QModelIndex &index, int role) const override; +}; + class Filetree : public QTreeView { Q_OBJECT - QFileSystemModel *m_fileSystemModel; + FileSystemModel *m_fileSystemModel; QString m_rootDir; public: explicit Filetree(QWidget *parent = nullptr);