File indexing completed on 2026-09-29 09:25:21
0001
0002
0003
0004
0005 #ifndef QFILEDIALOG_H
0006 #define QFILEDIALOG_H
0007
0008 #include <QtWidgets/qtwidgetsglobal.h>
0009 #include <QtCore/qdir.h>
0010 #include <QtCore/qstring.h>
0011 #include <QtCore/qurl.h>
0012 #include <QtWidgets/qdialog.h>
0013
0014 #include <functional>
0015
0016 QT_REQUIRE_CONFIG(filedialog);
0017
0018 QT_BEGIN_NAMESPACE
0019
0020 class QModelIndex;
0021 class QItemSelection;
0022 struct QFileDialogArgs;
0023 class QFileDialogPrivate;
0024 class QAbstractFileIconProvider;
0025 class QAbstractItemDelegate;
0026 class QAbstractProxyModel;
0027
0028 class Q_WIDGETS_EXPORT QFileDialog : public QDialog
0029 {
0030 Q_OBJECT
0031 Q_PROPERTY(ViewMode viewMode READ viewMode WRITE setViewMode)
0032 Q_PROPERTY(FileMode fileMode READ fileMode WRITE setFileMode)
0033 Q_PROPERTY(AcceptMode acceptMode READ acceptMode WRITE setAcceptMode)
0034 Q_PROPERTY(QString defaultSuffix READ defaultSuffix WRITE setDefaultSuffix)
0035 Q_PROPERTY(Options options READ options WRITE setOptions)
0036 Q_PROPERTY(QStringList supportedSchemes READ supportedSchemes WRITE setSupportedSchemes)
0037
0038 public:
0039 enum ViewMode { Detail, List };
0040 Q_ENUM(ViewMode)
0041 enum FileMode { AnyFile, ExistingFile, Directory, ExistingFiles };
0042 Q_ENUM(FileMode)
0043 enum AcceptMode { AcceptOpen, AcceptSave };
0044 Q_ENUM(AcceptMode)
0045 enum DialogLabel { LookIn, FileName, FileType, Accept, Reject };
0046
0047
0048 enum Option
0049 {
0050 ShowDirsOnly = 0x00000001,
0051 DontResolveSymlinks = 0x00000002,
0052 DontConfirmOverwrite = 0x00000004,
0053 DontUseNativeDialog = 0x00000008,
0054 ReadOnly = 0x00000010,
0055 HideNameFilterDetails = 0x00000020,
0056 DontUseCustomDirectoryIcons = 0x00000040
0057 };
0058 Q_ENUM(Option)
0059 Q_DECLARE_FLAGS(Options, Option)
0060 Q_FLAG(Options)
0061
0062 QFileDialog(QWidget *parent, Qt::WindowFlags f);
0063 explicit QFileDialog(QWidget *parent = nullptr,
0064 const QString &caption = QString(),
0065 const QString &directory = QString(),
0066 const QString &filter = QString());
0067 ~QFileDialog();
0068
0069 void setDirectory(const QString &directory);
0070 inline void setDirectory(const QDir &directory);
0071 QDir directory() const;
0072
0073 void setDirectoryUrl(const QUrl &directory);
0074 QUrl directoryUrl() const;
0075
0076 void selectFile(const QString &filename);
0077 QStringList selectedFiles() const;
0078
0079 void selectUrl(const QUrl &url);
0080 QList<QUrl> selectedUrls() const;
0081
0082 void setNameFilter(const QString &filter);
0083 void setNameFilters(const QStringList &filters);
0084 QStringList nameFilters() const;
0085 void selectNameFilter(const QString &filter);
0086 QString selectedMimeTypeFilter() const;
0087 QString selectedNameFilter() const;
0088
0089 #if QT_CONFIG(mimetype)
0090 void setMimeTypeFilters(const QStringList &filters);
0091 QStringList mimeTypeFilters() const;
0092 void selectMimeTypeFilter(const QString &filter);
0093 #endif
0094
0095 QDir::Filters filter() const;
0096 void setFilter(QDir::Filters filters);
0097
0098 void setViewMode(ViewMode mode);
0099 ViewMode viewMode() const;
0100
0101 void setFileMode(FileMode mode);
0102 FileMode fileMode() const;
0103
0104 void setAcceptMode(AcceptMode mode);
0105 AcceptMode acceptMode() const;
0106
0107 void setSidebarUrls(const QList<QUrl> &urls);
0108 QList<QUrl> sidebarUrls() const;
0109
0110 QByteArray saveState() const;
0111 bool restoreState(const QByteArray &state);
0112
0113 void setDefaultSuffix(const QString &suffix);
0114 QString defaultSuffix() const;
0115
0116 void setHistory(const QStringList &paths);
0117 QStringList history() const;
0118
0119 void setItemDelegate(QAbstractItemDelegate *delegate);
0120 QAbstractItemDelegate *itemDelegate() const;
0121
0122 void setIconProvider(QAbstractFileIconProvider *provider);
0123 QAbstractFileIconProvider *iconProvider() const;
0124
0125 void setLabelText(DialogLabel label, const QString &text);
0126 QString labelText(DialogLabel label) const;
0127
0128 void setSupportedSchemes(const QStringList &schemes);
0129 QStringList supportedSchemes() const;
0130
0131 #if QT_CONFIG(proxymodel)
0132 void setProxyModel(QAbstractProxyModel *model);
0133 QAbstractProxyModel *proxyModel() const;
0134 #endif
0135
0136 void setOption(Option option, bool on = true);
0137 bool testOption(Option option) const;
0138 void setOptions(Options options);
0139 Options options() const;
0140
0141 using QDialog::open;
0142 void open(QObject *receiver, const char *member);
0143 void setVisible(bool visible) override;
0144
0145 Q_SIGNALS:
0146 void fileSelected(const QString &file);
0147 void filesSelected(const QStringList &files);
0148 void currentChanged(const QString &path);
0149 void directoryEntered(const QString &directory);
0150
0151 void urlSelected(const QUrl &url);
0152 void urlsSelected(const QList<QUrl> &urls);
0153 void currentUrlChanged(const QUrl &url);
0154 void directoryUrlEntered(const QUrl &directory);
0155
0156 void filterSelected(const QString &filter);
0157
0158 public:
0159
0160 static QString getOpenFileName(QWidget *parent = nullptr,
0161 const QString &caption = QString(),
0162 const QString &dir = QString(),
0163 const QString &filter = QString(),
0164 QString *selectedFilter = nullptr,
0165 Options options = Options());
0166
0167 static QUrl getOpenFileUrl(QWidget *parent = nullptr,
0168 const QString &caption = QString(),
0169 const QUrl &dir = QUrl(),
0170 const QString &filter = QString(),
0171 QString *selectedFilter = nullptr,
0172 Options options = Options(),
0173 const QStringList &supportedSchemes = QStringList());
0174
0175 static QString getSaveFileName(QWidget *parent = nullptr,
0176 const QString &caption = QString(),
0177 const QString &dir = QString(),
0178 const QString &filter = QString(),
0179 QString *selectedFilter = nullptr,
0180 Options options = Options());
0181
0182 static QUrl getSaveFileUrl(QWidget *parent = nullptr,
0183 const QString &caption = QString(),
0184 const QUrl &dir = QUrl(),
0185 const QString &filter = QString(),
0186 QString *selectedFilter = nullptr,
0187 Options options = Options(),
0188 const QStringList &supportedSchemes = QStringList());
0189
0190 static QString getExistingDirectory(QWidget *parent = nullptr,
0191 const QString &caption = QString(),
0192 const QString &dir = QString(),
0193 Options options = ShowDirsOnly);
0194
0195 static QUrl getExistingDirectoryUrl(QWidget *parent = nullptr,
0196 const QString &caption = QString(),
0197 const QUrl &dir = QUrl(),
0198 Options options = ShowDirsOnly,
0199 const QStringList &supportedSchemes = QStringList());
0200
0201 static QStringList getOpenFileNames(QWidget *parent = nullptr,
0202 const QString &caption = QString(),
0203 const QString &dir = QString(),
0204 const QString &filter = QString(),
0205 QString *selectedFilter = nullptr,
0206 Options options = Options());
0207
0208 static QList<QUrl> getOpenFileUrls(QWidget *parent = nullptr,
0209 const QString &caption = QString(),
0210 const QUrl &dir = QUrl(),
0211 const QString &filter = QString(),
0212 QString *selectedFilter = nullptr,
0213 Options options = Options(),
0214 const QStringList &supportedSchemes = QStringList());
0215
0216 static void getOpenFileContent(const QString &nameFilter,
0217 const std::function<void(const QString &, const QByteArray &)> &fileContentsReady,
0218 QWidget *parent= nullptr);
0219
0220 static void saveFileContent(const QByteArray &fileContent,
0221 const QString &fileNameHint,
0222 QWidget *parent = nullptr);
0223
0224 #if QT_WIDGETS_REMOVED_SINCE(6, 7)
0225 static void getOpenFileContent(const QString &nameFilter,
0226 const std::function<void(const QString &, const QByteArray &)> &fileContentsReady);
0227 static void saveFileContent(const QByteArray &fileContent,
0228 const QString &fileNameHint = QString());
0229 #endif
0230
0231
0232 protected:
0233 QFileDialog(const QFileDialogArgs &args);
0234 void done(int result) override;
0235 void accept() override;
0236 void changeEvent(QEvent *e) override;
0237
0238 private:
0239 Q_DECLARE_PRIVATE(QFileDialog)
0240 Q_DISABLE_COPY(QFileDialog)
0241
0242 friend class QPlatformDialogHelper;
0243 };
0244
0245 inline void QFileDialog::setDirectory(const QDir &adirectory)
0246 { setDirectory(adirectory.absolutePath()); }
0247
0248 Q_DECLARE_OPERATORS_FOR_FLAGS(QFileDialog::Options)
0249
0250 QT_END_NAMESPACE
0251
0252 #endif