The QFileDialog provides a dialog widget for inputting file names. More...
#include <qfiledialog.h>
Inherits QDialog.
This class implements a dialog which can be used if the user should select a file or a directory.
Example (e.g. to get a filename for saving a file):
QString fileName = QFileDialog::getSaveFileName( "newfile.txt", "Textfiles (*.txt)", this ); if ( !fileName.isNull() ) { // got a file name ... }
To let the user specify a filename for e.g. opening a file, you could use following code:
QString s( QFileDialog::getOpenFileName( QString::null, "Images (*.png *.xpm *.jpg)", this ) ); if ( s.isEmpty() ) return; open( s ); // open() being your function to read the file
Other convenient static methods are QFileDialog::getExistingDirectory() to let the user choode a directory or QFileDialog::getOpenFileNames() to let the user select multiple files.
Additionally to these convenient static methods you can use one of QFileDialog's constructors, set a mode (see setMode()) and do more things, like adding a preview widget which will preview the current file or information of the current file while the user does the selection (see setPreviewMode(), setInfoPreviewWidget and setContentsPreviewWidget()) or add additional widgets to the filedialog then (see addWidgets(), addToolButton(), addLeftWidget() and addRightWidget()).
To get the selection the user did then, see selectedFile(), selectedFiles(), selectedFilter() and url(). To set these things see setUrl() and setSelection().
For an example about how to use this customization of the QFileDialog, take a look at the qdir example (qt/examples/qdir/qdir.cpp)
See also: QPrintDialog.
Examples: qdir/qdir.cpp movies/main.cpp
AnyFile
- Return the name of any file, whether existing or not.
ExistingFile
- Return the name of a single, existing, file.
Directory
- Return the name of a directory.
ExistingFiles
- Return the names of zero or more existing files.
Examples: qdir/qdir.cpp
DetailView
- View which shows except the filename also
size, date, etc. of a file in columns
ListView
- Simple view which shows only all filenames plus icons
PreviewContents
- Besides the view with the files a preview
widget is shown shich shows the contents of the currently selected file
PreviewInfo
- Besides the view with the files a preview
widget is shown shich shows infos of the currently selected file
Using setViewMode() you can set the view mode of the filedialog, and with viewMode() you can get the current view mode. The value which is set or returned here can also be or'd together combination of these values.
Constructs a file dialog with a parent, name and modal flag.
The dialog becomes modal if modal is TRUE, otherwise modeless.
Constructs a file dialog with a parent, name and modal flag.
The dialog becomes modal if modal is TRUE, otherwise modeless.
Destructs the file dialog.
[protected]
Adds filter to the filter list and makes it the current one.
[protected]
Adds the widget w to the left of the filedialog.
See also: addRightWidget(), addWidgets() and addToolButton().
[protected]
Adds the widget w to the right of the filedialog.
See also: addLeftWidget(), addWidgets() and addToolButton().
[protected]
Adds a the button b to the row of tool buttons on the top of the filedialog. The button is appended at the end (right) of this row. If separator is TRUE, a small space is inserted between the last button of the row and the new button b.
See also: addWidgets(), addLeftWidget() and addRightWidget().
[protected]
Adds 1-3 widgets to the bottom of the file dialog. l is the (optional) label, which is put beneath the "file name" and "file type" labels, w is a (optional) widget, which is put beneath the file type combo box, and b is the (you guessed it - optional) button, which is put beneath the cancel button.
If you don't want to add something in one of the columns, pass 0.
Each time calling this method adds a new row of widgets to the bottom of the filedialog.
See also: addToolButton(), addLeftWidget() and addRightWidget().
[protected slot]
For internal use only.
[protected slot]
For internal use only.
Returns the active directory in the file dialog.
See also: setDir().
[signal]
This signal is emitted when the user has selected a new directory.
Returns the active directory path string in the file dialog.
[virtual]
Reimplemented for internal reasons; the API is not affected.
Reimplemented from QObject.
[signal]
This signal is emitted when the user highlights a file.
[protected slot]
For internal use only.
[signal]
This signal is emitted when the user selects a file.
[static]
Ask the user for the name of an existing directory, starting at dir. Returns the name of the directory the user selected.
If dir is null, getExistingDirectory() starts wherever the previous file dialog left off.
NOTE: In the windows version of Qt this static method uses the native windows file dialog, and not the QFileDialog.
[static]
Opens a modal file dialog and returns the name of the file to be opened.
If startWith is the name of a directory, the dialog starts off in that directory. If startWith is the name of an existing file, the dialogs starts in that directory, and with startWith selected.
Only files matching filter are selectable. If filter is QString::null, all files are selectable. In the filter string multiple filters can be specified seperated by either two semicolons next to each other or seperated by newlines. To add two filters, one to show all C++ files and one to show all header files, the filter string could look like "C++ Files (*.cpp *.cc *.C *.cxx *.c++);;Header Files (*.h *.hxx *.h++)"
If widget and/or name is provided, the dialog will be centered over widget and named name.
getOpenFileName() returns a null string if the user cancelled the dialog.
This static function is less capable than the full QFileDialog object, but is convenient and easy to use.
Example:
// start at the current working directory and with *.cpp as filter QString f = QFileDialog::getOpenFileName( QString::null, "*.cpp", this ); if ( !f.isEmpty() ) { // the user selected a valid existing file } else { // the user cancelled the dialog }
getSaveFileName() is another convenience function, equal to this one except that it allows the user to specify the name of a nonexistent file name.
NOTE: In the windows version of Qt this static method uses the native windows file dialog, and not the QFileDialog.
See also: getSaveFileName().
[static]
Lets the user select N files from a single directory, and returns a list of the selected files. The list may be empty, and the file names are fully qualified (i.e. "/usr/games/quake" or "c:\\quake\\quake").
filter is the default glob pattern (which the user can change). The default is all files. In the filter string multiple filters can be specified seperated by either two semicolons next to each other or seperated by newlines. To add two filters, one to show all C++ files and one to show all header files, the filter string could look like "C++ Files (*.cpp *.cc *.C *.cxx *.c++);;Header Files (*.h *.hxx *.h++)"
dir is the starting directory. If dir is not supplied, QFileDialog picks something presumably useful (such as the directory where the user selected something last, or the current working directory).
parent is a widget over which the dialog should be positioned and name is the object name of the temporary QFileDialog object.
Example:
QStringList s( QFileDialog::getOpenFileNames() ); // do something with the files in s.
NOTE: In the windows version of Qt this static method uses the native windows file dialog, and not the QFileDialog.
[static]
Opens a modal file dialog and returns the name of the file to be saved.
If startWith is the name of a directory, the dialog starts off in that directory. If startWith is the name of an existing file, the dialogs starts in that directory, and with startWith selected.
Only files matching filter are selectable. If filter is QString::null, all files are selectable. In the filter string multiple filters can be specified seperated by either two semicolons next to each other or seperated by newlines. To add two filters, one to show all C++ files and one to show all header files, the filter string could look like "C++ Files (*.cpp *.cc *.C *.cxx *.c++);;Header Files (*.h *.hxx *.h++)"
If widget and/or name is provided, the dialog will be centered over widget and named name.
Returns a null string if the user cancelled the dialog.
This static function is less capable than the full QFileDialog object, but is convenient and easy to use.
Example:
// start at the current working directory and with *.cpp as filter QString f = QFileDialog::getSaveFileName( QString::null, "*.cpp", this ); if ( !f.isEmpty() ) { // the user gave a file name } else { // the user cancelled the dialog }
getOpenFileName() is another convenience function, equal to this one except that it does not allow the user to specify the name of a nonexistent file name.
NOTE: In the windows version of Qt this static method uses the native windows file dialog, and not the QFileDialog.
See also: getOpenFileName().
[static]
Returns the icon provider currently in use. By default there is no icon provider and this function returns 0.
See also: setIconProvider() and QFileIconProvider.
[virtual protected]
Reimplemented for internal reasons; the API is not affected.
Reimplemented from QWidget.
[protected slot]
For internal use only.
Returns the file mode of this dialog.
See also: setMode().
[protected slot]
For internal use only.
Re-reads the active directory in the file dialog.
It is seldom necessary to call this function. It is provided in case the directory contents change and you want to refresh the directory list box.
[virtual protected]
Handles resize events for the file dialog.
Reimplemented from QWidget.
Resorts the displayed directory.
Returns the selected file name.
If a file name was selected, the returned string contains the absolute path name. The returned string is a null string if no file name was selected.
See also: QString::isNull(), QFileDialog::selectedFiles() and QFileDialog::selectedFilter().
Examples: qdir/qdir.cpp
Returns a list of selected files. This is only useful, if the mode of the filedialog is ExistingFiles. Else the list will only contain one entry, which is the the selecedFile. If no files were selected, this list is empty.
See also: QFileDialog::selecedFile() and QStringList::isEmpty().
Returns the filter which the user has chosen in the file dialog.
See also: QString::isNull() and QFileDialog::selectedFiles().
Sets the widget which should be used for displaying the preview of a file.
This widget should implement a public slot
void showPreview( const QUrl & );
A signal of the filedialog will then be automatically connected to this slot. If the user selects a file then, this signal is emitted, so that the preview widget can show a preview of this file (url).
Examples: qdir/qdir.cpp
Sets a directory path for the file dialog.
See also: dir().
[slot]
Sets a directory path string for the file dialog.
See also: dir().
[slot]
Sets the filter spec in use to newFilter.
If newFilter matches the regular expression ([a-zA-Z0-9\.\*\?\ \+\;]*)$ (ie. it ends with a normal wildcard expression enclosed in parentheses), only the parenthesized is used. This means that these calls are all equivalent:
fd->setFilter( "All C++ files (*.cpp *.cc *.C *.cxx *.c++)" ); fd->setFilter( "*.cpp *.cc *.C *.cxx *.c++" ) fd->setFilter( "All C++ files (*.cpp;*.cc;*.C;*.cxx;*.c++)" ); fd->setFilter( "*.cpp;*.cc;*.C;*.cxx;*.c++" )
[slot]
Sets this file dialog to offer types in the File Type combo box. types must be a null-terminated list of strings; each string must be in the format described in the documentation for setFilter().
See also: setFilter().
[slot]
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
[slot]
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
[static]
Sets all file dialogs to use provider to select icons to draw for each file. By default there is no icon provider, and QFileDialog simply draws a "folder" icon next to each directory and nothing next to the files.
See also: QFileIconProvider and iconProvider().
Examples: showimg/main.cpp
Sets the widget which should be used for displaying information of a file.
This widget should implement a public slot
void showPreview( const QUrl & );
A signal of the filedialog will then be automatically connected to this slot. If the user selects a file then, this signal is emitted, so that the preview widget can show information of this file (url).
Sets this file dialog to newMode, which can be one of Directory
(directories are accepted), ExistingFile
(existing
files are accepted), AnyFile
(any valid file name is accepted)
or ExistingFiles
(like ExistingFile,
but multiple files may be
selected)
See also: mode().
Examples: qdir/qdir.cpp
Sets the file preview modes. If info is TRUE, a widget for showing file information can be shown, else not. If contents is TRUE, a widget for showing a file preview can be shown, else not.
Examples: qdir/qdir.cpp
Sets the default selection to filename. If filename is absolute, setDir() is also called.
Examples: qdir/qdir.cpp
If s is TRUE, hidden files are shown in the filedialog, else no hidden files are shown.
[slot]
Sets the url which should be used as working directory.
Set the viewmode of the filedialog. You can choose between DetailView, ListView, PreviewContents and PreviewInfo. One of the View-Flags and one of the Preview-Flags can be or'd together, e.g. to set the filedialog to show a detail view and the show contents preview widget, use setViewMode( QFileDialog::DetailView | QFileDialog::PreviewContents );.
Examples: qdir/qdir.cpp
Returns TRUE if hidden files are shown in the filedialog, else FALSE.
[signal]
This signal is emitted when a preview of the URL u should be shown in the preview widget. Normally you don't need to connect to this signal, as this is done automatically.
[protected slot]
Stops the current copy operation.
Returns the URL of the current working directory.
Returns the viewmode of the filedialog. This is a value of either DetailView or ListView maybe or'd together with either PreviewContents or PreviewInfo.
Search the documentation, FAQ, qt-interest archive and more (uses
www.troll.no):
This file is part of the Qt toolkit, copyright © 1995-2000 Troll Tech, all rights reserved.
Copyright İ 2000 Troll Tech | Trademarks | Qt version 2.1.0 (pre-release)
|