I'm using a QFileIconProvider class to show image thumbnails in a QFileDialog by overriding the 'icon' method to load from a file to a QIcon.
After implementing this, the file dialog is very slow in navigating through sub-folders and hangs for a few seconds before changing directory.
C++ class is below.
Why is the rendering being slow and how can I speed it up?
{
const QString &path
= info.
absoluteFilePath();
// check if 'info' is a drive type
if (path.isEmpty())
if (info.isFile()) {
if (QFile(info.
absoluteFilePath()).
exists()) { // show file as icon
QImage originalImage
(info.
absoluteFilePath());
if (!originalImage.isNull())
return QIcon(info.
absoluteFilePath());
}
}
// check if 'info' is a directory type
if (info.isDir())
}
QIcon CFileIconProvider::icon(const QFileInfo &info) const
{
const QString &path = info.absoluteFilePath();
// check if 'info' is a drive type
if (path.isEmpty())
return QFileIconProvider::icon(QFileIconProvider::Drive);
if (info.isFile()) {
if (QFile(info.absoluteFilePath()).exists()) {
// show file as icon
QImage originalImage(info.absoluteFilePath());
if (!originalImage.isNull())
return QIcon(info.absoluteFilePath());
}
}
// check if 'info' is a directory type
if (info.isDir())
return QFileIconProvider::icon(QFileIconProvider::Folder);
return QIcon();
}
To copy to clipboard, switch view to plain text mode
#ifndef FILEICON_PROVIDER_H
#define FILEICON_PROVIDER_H
#include <QFileIconProvider>
#include <QObject>
#include <QIcon>
{
public:
CFileIconProvider();
};
#endif // FILEICON_PROVIDER_H
#ifndef FILEICON_PROVIDER_H
#define FILEICON_PROVIDER_H
#include <QFileIconProvider>
#include <QObject>
#include <QIcon>
class CFileIconProvider : public QFileIconProvider
{
public:
CFileIconProvider();
QIcon icon(const QFileInfo &info) const override;
};
#endif // FILEICON_PROVIDER_H
To copy to clipboard, switch view to plain text mode
Bookmarks