Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qfiledialog.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QFILEDIALOG_H
5#define QFILEDIALOG_H
6
7#include <QtWidgets/qtwidgetsglobal.h>
8#include <QtCore/qdir.h>
9#include <QtCore/qstring.h>
10#include <QtCore/qurl.h>
11#include <QtWidgets/qdialog.h>
12
13#include <functional>
14
16
18
19class QModelIndex;
20class QItemSelection;
21struct QFileDialogArgs;
26
27class Q_WIDGETS_EXPORT QFileDialog : public QDialog
28{
30 Q_PROPERTY(ViewMode viewMode READ viewMode WRITE setViewMode)
31 Q_PROPERTY(FileMode fileMode READ fileMode WRITE setFileMode)
32 Q_PROPERTY(AcceptMode acceptMode READ acceptMode WRITE setAcceptMode)
33 Q_PROPERTY(QString defaultSuffix READ defaultSuffix WRITE setDefaultSuffix)
34 Q_PROPERTY(Options options READ options WRITE setOptions)
35 Q_PROPERTY(QStringList supportedSchemes READ supportedSchemes WRITE setSupportedSchemes)
36
37public:
38 enum ViewMode { Detail, List };
39 Q_ENUM(ViewMode)
40 enum FileMode { AnyFile, ExistingFile, Directory, ExistingFiles };
41 Q_ENUM(FileMode)
42 enum AcceptMode { AcceptOpen, AcceptSave };
43 Q_ENUM(AcceptMode)
44 enum DialogLabel { LookIn, FileName, FileType, Accept, Reject };
45
46 // keep this in sync with QFileDialogOption::FileDialogOptions
47 enum Option
48 {
49 ShowDirsOnly = 0x00000001,
50 DontResolveSymlinks = 0x00000002,
51 DontConfirmOverwrite = 0x00000004,
52 DontUseNativeDialog = 0x00000008,
53 ReadOnly = 0x00000010,
54 HideNameFilterDetails = 0x00000020,
55 DontUseCustomDirectoryIcons = 0x00000040
56 };
60
61 QFileDialog(QWidget *parent, Qt::WindowFlags f);
62 explicit QFileDialog(QWidget *parent = nullptr,
63 const QString &caption = QString(),
64 const QString &directory = QString(),
65 const QString &filter = QString());
67
68 void setDirectory(const QString &directory);
69 inline void setDirectory(const QDir &directory);
70 QDir directory() const;
71
72 void setDirectoryUrl(const QUrl &directory);
73 QUrl directoryUrl() const;
74
75 void selectFile(const QString &filename);
76 QStringList selectedFiles() const;
77
78 void selectUrl(const QUrl &url);
79 QList<QUrl> selectedUrls() const;
80
81 void setNameFilter(const QString &filter);
83 QStringList nameFilters() const;
84 void selectNameFilter(const QString &filter);
85 QString selectedMimeTypeFilter() const;
86 QString selectedNameFilter() const;
87
88#if QT_CONFIG(mimetype)
91 void selectMimeTypeFilter(const QString &filter);
92#endif
93
94 QDir::Filters filter() const;
95 void setFilter(QDir::Filters filters);
96
97 void setViewMode(ViewMode mode);
98 ViewMode viewMode() const;
99
100 void setFileMode(FileMode mode);
101 FileMode fileMode() const;
102
103 void setAcceptMode(AcceptMode mode);
104 AcceptMode acceptMode() const;
105
106 void setSidebarUrls(const QList<QUrl> &urls);
107 QList<QUrl> sidebarUrls() const;
108
109 QByteArray saveState() const;
110 bool restoreState(const QByteArray &state);
111
112 void setDefaultSuffix(const QString &suffix);
113 QString defaultSuffix() const;
114
115 void setHistory(const QStringList &paths);
116 QStringList history() const;
117
118 void setItemDelegate(QAbstractItemDelegate *delegate);
119 QAbstractItemDelegate *itemDelegate() const;
120
121 void setIconProvider(QAbstractFileIconProvider *provider);
122 QAbstractFileIconProvider *iconProvider() const;
123
124 void setLabelText(DialogLabel label, const QString &text);
125 QString labelText(DialogLabel label) const;
126
127 void setSupportedSchemes(const QStringList &schemes);
128 QStringList supportedSchemes() const;
129
130#if QT_CONFIG(proxymodel)
131 void setProxyModel(QAbstractProxyModel *model);
132 QAbstractProxyModel *proxyModel() const;
133#endif
134
135 void setOption(Option option, bool on = true);
136 bool testOption(Option option) const;
137 void setOptions(Options options);
138 Options options() const;
139
140 using QDialog::open;
141 void open(QObject *receiver, const char *member);
142 void setVisible(bool visible) override;
143
149
150 void urlSelected(const QUrl &url);
151 void urlsSelected(const QList<QUrl> &urls);
154
156
157public:
158
159 static QString getOpenFileName(QWidget *parent = nullptr,
160 const QString &caption = QString(),
161 const QString &dir = QString(),
162 const QString &filter = QString(),
163 QString *selectedFilter = nullptr,
164 Options options = Options());
165
166 static QUrl getOpenFileUrl(QWidget *parent = nullptr,
167 const QString &caption = QString(),
168 const QUrl &dir = QUrl(),
169 const QString &filter = QString(),
170 QString *selectedFilter = nullptr,
171 Options options = Options(),
172 const QStringList &supportedSchemes = QStringList());
173
174 static QString getSaveFileName(QWidget *parent = nullptr,
175 const QString &caption = QString(),
176 const QString &dir = QString(),
177 const QString &filter = QString(),
178 QString *selectedFilter = nullptr,
179 Options options = Options());
180
181 static QUrl getSaveFileUrl(QWidget *parent = nullptr,
182 const QString &caption = QString(),
183 const QUrl &dir = QUrl(),
184 const QString &filter = QString(),
185 QString *selectedFilter = nullptr,
186 Options options = Options(),
187 const QStringList &supportedSchemes = QStringList());
188
189 static QString getExistingDirectory(QWidget *parent = nullptr,
190 const QString &caption = QString(),
191 const QString &dir = QString(),
192 Options options = ShowDirsOnly);
193
194 static QUrl getExistingDirectoryUrl(QWidget *parent = nullptr,
195 const QString &caption = QString(),
196 const QUrl &dir = QUrl(),
197 Options options = ShowDirsOnly,
198 const QStringList &supportedSchemes = QStringList());
199
200 static QStringList getOpenFileNames(QWidget *parent = nullptr,
201 const QString &caption = QString(),
202 const QString &dir = QString(),
203 const QString &filter = QString(),
204 QString *selectedFilter = nullptr,
205 Options options = Options());
206
207 static QList<QUrl> getOpenFileUrls(QWidget *parent = nullptr,
208 const QString &caption = QString(),
209 const QUrl &dir = QUrl(),
210 const QString &filter = QString(),
211 QString *selectedFilter = nullptr,
212 Options options = Options(),
213 const QStringList &supportedSchemes = QStringList());
214
215 static void getOpenFileContent(const QString &nameFilter,
216 const std::function<void(const QString &, const QByteArray &)> &fileContentsReady,
217 QWidget *parent= nullptr);
218
219 static void saveFileContent(const QByteArray &fileContent,
220 const QString &fileNameHint,
221 QWidget *parent = nullptr);
222
223#if QT_WIDGETS_REMOVED_SINCE(6, 7)
224 static void getOpenFileContent(const QString &nameFilter,
225 const std::function<void(const QString &, const QByteArray &)> &fileContentsReady);
226 static void saveFileContent(const QByteArray &fileContent,
227 const QString &fileNameHint = QString());
228#endif
229
230
231protected:
233 void done(int result) override;
234 void accept() override;
235 void changeEvent(QEvent *e) override;
236
237private:
238 Q_DECLARE_PRIVATE(QFileDialog)
239 Q_DISABLE_COPY(QFileDialog)
240
242};
243
244inline void QFileDialog::setDirectory(const QDir &adirectory)
245{ setDirectory(adirectory.absolutePath()); }
246
247Q_DECLARE_OPERATORS_FOR_FLAGS(QFileDialog::Options)
248
250
251#endif // QFILEDIALOG_H
The QAbstractItemDelegate class is used to display and edit data items from a model.
The QAbstractProxyModel class provides a base class for proxy item models that can do sorting,...
\inmodule QtCore
Definition qbytearray.h:57
The QDialog class is the base class of dialog windows.
Definition qdialog.h:19
virtual void open()
Definition qdialog.cpp:503
\inmodule QtCore
Definition qdir.h:20
\inmodule QtCore
Definition qcoreevent.h:45
The QFileDialog class provides a dialog that allows users to select files or directories.
Definition qfiledialog.h:28
FileMode
This enum is used to indicate what the user may select in the file dialog; that is,...
Definition qfiledialog.h:40
void currentChanged(const QString &path)
When the current file changes for local operations, this signal is emitted with the new file name as ...
void urlsSelected(const QList< QUrl > &urls)
When the selection changes and the dialog is accepted, this signal is emitted with the (possibly empt...
void filesSelected(const QStringList &files)
When the selection changes for local operations and the dialog is accepted, this signal is emitted wi...
void fileSelected(const QString &file)
When the selection changes for local operations and the dialog is accepted, this signal is emitted wi...
void currentUrlChanged(const QUrl &url)
When the current file changes, this signal is emitted with the new file URL as the url parameter.
void filterSelected(const QString &filter)
DialogLabel
\value LookIn \value FileName \value FileType \value Accept \value Reject
Definition qfiledialog.h:44
void urlSelected(const QUrl &url)
When the selection changes and the dialog is accepted, this signal is emitted with the (possibly empt...
AcceptMode
\value AcceptOpen \value AcceptSave
Definition qfiledialog.h:42
void directoryUrlEntered(const QUrl &directory)
This signal is emitted when the user enters a directory.
ViewMode
This enum describes the view mode of the file dialog; that is, what information about each file is di...
Definition qfiledialog.h:38
void directoryEntered(const QString &directory)
\inmodule QtCore
\inmodule QtCore
\inmodule QtCore
Definition qobject.h:103
The QPlatformDialogHelper class allows for platform-specific customization of dialogs.
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
\inmodule QtCore
Definition qurl.h:94
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
QString text
else opt state
[0]
Combined button and popup list for selecting options.
QList< QString > QStringList
Constructs a string list that contains the given string, str.
#define Q_DECLARE_FLAGS(Flags, Enum)
Definition qflags.h:174
#define Q_DECLARE_OPERATORS_FOR_FLAGS(Flags)
Definition qflags.h:194
GLenum mode
GLfloat GLfloat f
GLsizei const GLuint * paths
GLuint GLsizei const GLchar * label
[43]
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
GLsizei const GLchar *const * path
GLuint64EXT * result
[6]
GLuint GLenum option
#define QT_REQUIRE_CONFIG(feature)
#define Q_ENUM(x)
#define Q_PROPERTY(...)
#define Q_OBJECT
#define Q_FLAG(x)
#define Q_SIGNALS
QSqlQueryModel * model
[16]
QFile file
[0]
file open(QIODevice::ReadOnly)
QUrl url("example.com")
[constructor-url-reference]
QStringList mimeTypeFilters({"image/jpeg", "image/png", "application/octet-stream" })
[12]
QString dir
[11]
dialog setViewMode(QFileDialog::Detail)
[3]
dialog setNameFilter(tr("Images (*.png *.xpm *.jpg)"))
[2]
dialog setMimeTypeFilters(mimeTypeFilters)
dialog setNameFilters(filters)
QStringList files
[8]
dialog setFileMode(QFileDialog::AnyFile)
const QStringList filters({"Image files (*.png *.xpm *.jpg)", "Text files (*.txt)", "Any files (*)" })
[6]
QJSValueList args