Qt logo

QFileDialog Class Reference


The QFileDialog provides a dialog widget for inputting file names. More...

#include <qfiledialog.h>

Inherits QDialog.

List of all member functions.

Public Members

Public Slots

Signals

Static Public Members

Protected Members

Protected Slots

Properties

TypeNameREADWRITEOptions
QStringselectedFileselectedFile
QStringselectedFilterselectedFilter
QStringListselectedFilesselectedFiles
QStringdirPathdirPath
boolshowHiddenFilesshowHiddenFilessetShowHiddenFiles
ModemodemodesetMode
ViewModeviewModeviewModesetViewMode
PreviewModepreviewModepreviewModesetPreviewMode
boolinfoPreviewisInfoPreviewEnabledsetInfoPreviewEnabled
boolcontentsPreviewisContentsPreviewEnabledsetContentsPreviewEnabled

Detailed Description

The QFileDialog provides a dialog widget for inputting file names.

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 setInfoPreview(), setContentsPreview(), setInfoPreviewEnabled() and setContentsPreviewEnabled()) 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: movies/main.cpp


Member Type Documentation

QFileDialog::Mode

This enum type is used to set and read QFileDialog's operating mode. The defined values are:

QFileDialog::PreviewMode

  • NoPreview - No preview is shown at all
  • Contents - Besides the view with the files a preview widget is shown shich shows the contents of the currently selected file
  • Info - Besides the view with the files a preview widget is shown shich shows infos of the currently selected file

    Using setPreviewMode() this mode can be set to the file dialog.

    QFileDialog::ViewMode

    This enum type describes the view mode of the filedialog.