Movatterモバイル変換


[0]ホーム

URL:


We bake cookies in your browser for a better experience. Using this site means that you consent.Read More

Menu

Qt Documentation

QFileDialog Class

TheQFileDialog class provides a dialog that allow users to select files or directories.More...

Header:#include <QFileDialog>
Inherits:QDialog

Public Types

enumAcceptMode { AcceptOpen, AcceptSave }
enumDialogLabel { LookIn, FileName, FileType, Accept, Reject }
enumFileMode { AnyFile, ExistingFile, Directory, ExistingFiles, DirectoryOnly }
typedefMode
enumOption { ShowDirsOnly, DontResolveSymlinks, DontConfirmOverwrite, DontUseNativeDialog, ..., DontUseCustomDirectoryIcons }
flagsOptions
enumViewMode { Detail, List }

Properties

Public Functions

QFileDialog(QWidget * parent, Qt::WindowFlags flags)
QFileDialog(QWidget * parent = 0, const QString & caption = QString(), const QString & directory = QString(), const QString & filter = QString())
~QFileDialog()
AcceptModeacceptMode() const
QStringdefaultSuffix() const
QDirdirectory() const
FileModefileMode() const
QDir::Filtersfilter() const
QStringListhistory() const
QFileIconProvider *iconProvider() const
QAbstractItemDelegate *itemDelegate() const
QStringlabelText(DialogLabel label) const
QStringListnameFilters() const
voidopen(QObject * receiver, const char * member)
Optionsoptions() const
QAbstractProxyModel *proxyModel() const
boolrestoreState(const QByteArray & state)
QByteArraysaveState() const
voidselectFile(const QString & filename)
voidselectNameFilter(const QString & filter)
QStringListselectedFiles() const
QStringselectedNameFilter() const
voidsetAcceptMode(AcceptMode mode)
voidsetDefaultSuffix(const QString & suffix)
voidsetDirectory(const QString & directory)
voidsetDirectory(const QDir & directory)
voidsetFileMode(FileMode mode)
voidsetFilter(QDir::Filters filters)
voidsetHistory(const QStringList & paths)
voidsetIconProvider(QFileIconProvider * provider)
voidsetItemDelegate(QAbstractItemDelegate * delegate)
voidsetLabelText(DialogLabel label, const QString & text)
voidsetNameFilter(const QString & filter)
voidsetNameFilters(const QStringList & filters)
voidsetOption(Option option, bool on = true)
voidsetOptions(Options options)
voidsetProxyModel(QAbstractProxyModel * proxyModel)
voidsetSidebarUrls(const QList<QUrl> & urls)
voidsetViewMode(ViewMode mode)
QList<QUrl>sidebarUrls() const
booltestOption(Option option) const
ViewModeviewMode() const

Reimplemented Public Functions

virtual voidsetVisible(bool visible)
  • 8 public functions inherited fromQDialog
  • 220 public functions inherited fromQWidget
  • 29 public functions inherited fromQObject
  • 12 public functions inherited fromQPaintDevice

Signals

voidcurrentChanged(const QString & path)
voiddirectoryEntered(const QString & directory)
voidfileSelected(const QString & file)
voidfilesSelected(const QStringList & selected)
voidfilterSelected(const QString & filter)

Static Public Members

QStringgetExistingDirectory(QWidget * parent = 0, const QString & caption = QString(), const QString & dir = QString(), Options options = ShowDirsOnly)
QStringgetOpenFileName(QWidget * parent = 0, const QString & caption = QString(), const QString & dir = QString(), const QString & filter = QString(), QString * selectedFilter = 0, Options options = 0)
QStringListgetOpenFileNames(QWidget * parent = 0, const QString & caption = QString(), const QString & dir = QString(), const QString & filter = QString(), QString * selectedFilter = 0, Options options = 0)
QStringgetSaveFileName(QWidget * parent = 0, const QString & caption = QString(), const QString & dir = QString(), const QString & filter = QString(), QString * selectedFilter = 0, Options options = 0)
  • 4 static public members inherited fromQWidget
  • 7 static public members inherited fromQObject

Reimplemented Protected Functions

virtual voidaccept()
virtual voidchangeEvent(QEvent * e)
virtual voiddone(int result)
  • 7 protected functions inherited fromQDialog
  • 37 protected functions inherited fromQWidget
  • 8 protected functions inherited fromQObject
  • 1 protected function inherited fromQPaintDevice

Additional Inherited Members

  • 5 public slots inherited fromQDialog
  • 19 public slots inherited fromQWidget
  • 1 public slot inherited fromQObject
  • 7 protected functions inherited fromQDialog
  • 37 protected functions inherited fromQWidget
  • 8 protected functions inherited fromQObject
  • 1 protected function inherited fromQPaintDevice
  • 1 protected slot inherited fromQWidget

Detailed Description

TheQFileDialog class provides a dialog that allow users to select files or directories.

TheQFileDialog class enables a user to traverse the file system in order to select one or many files or a directory.

The easiest way to create aQFileDialog is to use the static functions. On Windows, Mac OS X, KDE and GNOME, these static functions will call the native file dialog when possible.

fileName=QFileDialog::getOpenFileName(this,    tr("Open Image"),"/home/jana", tr("Image Files (*.png *.jpg *.bmp)"));

In the above example, a modalQFileDialog is created using a static function. The dialog initially displays the contents of the "/home/jana" directory, and displays files matching the patterns given in the string "Image Files (*.png *.jpg *.bmp)". The parent of the file dialog is set tothis, and the window title is set to "Open Image".

If you want to use multiple filters, separate each one withtwo semicolons. For example:

"Images (*.png *.xpm *.jpg);;Text files (*.txt);;XML files (*.xml)"

You can create your ownQFileDialog without using the static functions. By callingsetFileMode(), you can specify what the user must select in the dialog:

QFileDialog dialog(this);dialog.setFileMode(QFileDialog::AnyFile);

In the above example, the mode of the file dialog is set toAnyFile, meaning that the user can select any file, or even specify a file that doesn't exist. This mode is useful for creating a "Save As" file dialog. UseExistingFile if the user must select an existing file, orDirectory if only a directory may be selected. See theQFileDialog::FileMode enum for the complete list of modes.

ThefileMode property contains the mode of operation for the dialog; this indicates what types of objects the user is expected to select. UsesetNameFilter() to set the dialog's file filter. For example:

dialog.setNameFilter(tr("Images (*.png *.xpm *.jpg)"));

In the above example, the filter is set to"Images (*.png *.xpm *.jpg)", this means that only files with the extensionpng,xpm, orjpg will be shown in theQFileDialog. You can apply several filters by usingsetNameFilters(). UseselectNameFilter() to select one of the filters you've given as the file dialog's default filter.

The file dialog has two view modes:List andDetail.List presents the contents of the current directory as a list of file and directory names.Detail also displays a list of file and directory names, but provides additional information alongside each name, such as the file size and modification date. Set the mode withsetViewMode():

dialog.setViewMode(QFileDialog::Detail);

The last important function you will need to use when creating your own file dialog isselectedFiles().

QStringList fileNames;if (dialog.exec())    fileNames= dialog.selectedFiles();

In the above example, a modal file dialog is created and shown. If the user clicked OK, the file they selected is put infileName.

The dialog's working directory can be set withsetDirectory(). Each file in the current directory can be selected using theselectFile() function.

TheStandard Dialogs example shows how to useQFileDialog as well as other built-in Qt dialogs.

See alsoQDir,QFileInfo,QFile,QPrintDialog,QColorDialog,QFontDialog,Standard Dialogs Example, andApplication Example.

Member Type Documentation

enum QFileDialog::AcceptMode

ConstantValue
QFileDialog::AcceptOpen0
QFileDialog::AcceptSave1

enum QFileDialog::DialogLabel

ConstantValue
QFileDialog::LookIn0
QFileDialog::FileName1
QFileDialog::FileType2
QFileDialog::Accept3
QFileDialog::Reject4

enum QFileDialog::FileMode

This enum is used to indicate what the user may select in the file dialog; i.e. what the dialog will return if the user clicks OK.

ConstantValueDescription
QFileDialog::AnyFile0The name of a file, whether it exists or not.
QFileDialog::ExistingFile1The name of a single existing file.
QFileDialog::Directory2The name of a directory. Both files and directories are displayed.
QFileDialog::ExistingFiles3The names of zero or more existing files.

This value is obsolete since Qt 4.5:

ConstantValueDescription
QFileDialog::DirectoryOnly4UseDirectory andsetOption(ShowDirsOnly, true) instead.

See alsosetFileMode().

typedef QFileDialog::Mode

UseQFileDialog::FileMode instead.

enum QFileDialog::Option
flags QFileDialog::Options

ConstantValueDescription
QFileDialog::ShowDirsOnly0x00000001Only show directories in the file dialog. By default both files and directories are shown. (Valid only in theDirectory file mode.)
QFileDialog::DontResolveSymlinks0x00000002Don't resolve symlinks in the file dialog. By default symlinks are resolved.
QFileDialog::DontConfirmOverwrite0x00000004Don't ask for confirmation if an existing file is selected. By default confirmation is requested.
QFileDialog::DontUseNativeDialog0x00000010Don't use the native file dialog. By default, the native file dialog is used unless you use a subclass ofQFileDialog that contains theQ_OBJECT macro.
QFileDialog::ReadOnly0x00000020Indicates that the model is readonly.
QFileDialog::HideNameFilterDetails0x00000040Indicates if the file name filter details are hidden or not.
QFileDialog::DontUseSheet0x00000008In previous versions of Qt, the static functions would create a sheet by default if the static function was given a parent. This is no longer supported and does nothing in Qt 4.5, The static functions will always be an application modal dialog. If you want to use sheets, useQFileDialog::open() instead.
QFileDialog::DontUseCustomDirectoryIcons0x00000080Always use the default directory icon. Some platforms allow the user to set a different icon. Custom icon lookup cause a big performance impact over network or removable drives. Setting this will affect the behavior of the icon provider. This enum value was added in Qt 4.8.6.

The Options type is a typedef forQFlags<Option>. It stores an OR combination of Option values.

enum QFileDialog::ViewMode

This enum describes the view mode of the file dialog; i.e. what information about each file will be displayed.

ConstantValueDescription
QFileDialog::Detail0Displays an icon, a name, and details for each item in the directory.
QFileDialog::List1Displays only an icon and a name for each item in the directory.

See alsosetViewMode().

Property Documentation

acceptMode :AcceptMode

This property holds the accept mode of the dialog.

The action mode defines whether the dialog is for opening or saving files.

By default, this property is set toAcceptOpen.

Access functions:

AcceptModeacceptMode() const
voidsetAcceptMode(AcceptMode mode)

See alsoAcceptMode.

defaultSuffix :QString

This property holds suffix added to the filename if no other suffix was specified.

This property specifies a string that will be added to the filename if it has no suffix already. The suffix is typically used to indicate the file type (e.g. "txt" indicates a text file).

Access functions:

QStringdefaultSuffix() const
voidsetDefaultSuffix(const QString & suffix)

fileMode :FileMode

This property holds the file mode of the dialog.

The file mode defines the number and type of items that the user is expected to select in the dialog.

By default, this property is set toAnyFile.

This function will set the labels for theFileName andAcceptDialogLabels. It is possible to set custom text after the call to setFileMode().

Access functions:

FileModefileMode() const
voidsetFileMode(FileMode mode)

See alsoFileMode.

options :Options

This property holds the various options that affect the look and feel of the dialog.

By default, all options are disabled.

Options should be set before showing the dialog. Setting them while the dialog is visible is not guaranteed to have an immediate effect on the dialog (depending on the option and on the platform).

This property was introduced in Qt 4.5.

Access functions:

Optionsoptions() const
voidsetOptions(Options options)

See alsosetOption() andtestOption().

viewMode :ViewMode

This property holds the way files and directories are displayed in the dialog.

By default, theDetail mode is used to display information about files and directories.

Access functions:

ViewModeviewMode() const
voidsetViewMode(ViewMode mode)

See alsoViewMode.

Member Function Documentation

QFileDialog::QFileDialog(QWidget * parent,Qt::WindowFlags flags)

Constructs a file dialog with the givenparent and widgetflags.

QFileDialog::QFileDialog(QWidget * parent = 0, constQString & caption = QString(), constQString & directory = QString(), constQString & filter = QString())

Constructs a file dialog with the givenparent andcaption that initially displays the contents of the specifieddirectory. The contents of the directory are filtered before being shown in the dialog, using a semicolon-separated list of filters specified byfilter.

QFileDialog::~QFileDialog()

Destroys the file dialog.

[virtual protected]void QFileDialog::accept()

Reimplemented fromQDialog::accept().

[virtual protected]void QFileDialog::changeEvent(QEvent * e)

Reimplemented fromQWidget::changeEvent().

[signal]void QFileDialog::currentChanged(constQString & path)

When the current file changes, this signal is emitted with the new file name as thepath parameter.

See alsofilesSelected().

QDir QFileDialog::directory() const

Returns the directory currently being displayed in the dialog.

See alsosetDirectory().

[signal]void QFileDialog::directoryEntered(constQString & directory)

This signal is emitted when the user enters adirectory.

This function was introduced in Qt 4.3.

[virtual protected]void QFileDialog::done(int result)

Reimplemented fromQDialog::done().

[signal]void QFileDialog::fileSelected(constQString & file)

When the selection changes and the dialog is accepted, this signal is emitted with the (possibly empty) selectedfile.

See alsocurrentChanged() andQDialog::Accepted.

[signal]void QFileDialog::filesSelected(constQStringList & selected)

When the selection changes and the dialog is accepted, this signal is emitted with the (possibly empty) list ofselected files.

See alsocurrentChanged() andQDialog::Accepted.

QDir::Filters QFileDialog::filter() const

Returns the filter that is used when displaying files.

This function was introduced in Qt 4.4.

See alsosetFilter().

[signal]void QFileDialog::filterSelected(constQString & filter)

This signal is emitted when the user selects afilter.

This function was introduced in Qt 4.3.

[static]QString QFileDialog::getExistingDirectory(QWidget * parent = 0, constQString & caption = QString(), constQString & dir = QString(),Options options = ShowDirsOnly)

This is a convenience static function that will return an existing directory selected by the user.

QString dir=QFileDialog::getExistingDirectory(this, tr("Open Directory"),"/home",QFileDialog::ShowDirsOnly|QFileDialog::DontResolveSymlinks);

This function creates a modal file dialog with the givenparent widget. Ifparent is not 0, the dialog will be shown centered over the parent widget.

The dialog's working directory is set todir, and the caption is set tocaption. Either of these may be an empty string in which case the current directory and a default caption will be used respectively.

Theoptions argument holds various options about how to run the dialog, see theQFileDialog::Option enum for more information on the flags you can pass. To ensure a native file dialog,ShowDirsOnly must be set.

On Windows, Mac OS X and Symbian^3, this static function will use the native file dialog and not aQFileDialog. On Windows CE, if the device has no native file dialog, aQFileDialog will be used.

On Unix/X11, the normal behavior of the file dialog is to resolve and follow symlinks. For example, if/usr/tmp is a symlink to/var/tmp, the file dialog will change to/var/tmp after entering/usr/tmp. Ifoptions includesDontResolveSymlinks, the file dialog will treat symlinks as regular directories.

On Windows the dialog will spin a blocking modal event loop that will not dispatch any QTimers, and ifparent is not 0 then it will position the dialog just below the parent's title bar.

On Symbian^3 theoptions parameter is only used to define if the native file dialog is used.

Warning: Do not deleteparent during the execution of the dialog. If you want to do this, you should create the dialog yourself using one of theQFileDialog constructors.

See alsogetOpenFileName(),getOpenFileNames(), andgetSaveFileName().

[static]QString QFileDialog::getOpenFileName(QWidget * parent = 0, constQString & caption = QString(), constQString & dir = QString(), constQString & filter = QString(),QString * selectedFilter = 0,Options options = 0)

This is a convenience static function that returns an existing file selected by the user. If the user presses Cancel, it returns a null string.

QString fileName=QFileDialog::getOpenFileName(this, tr("Open File"),"/home",                                                tr("Images (*.png *.xpm *.jpg)"));

The function creates a modal file dialog with the givenparent widget. Ifparent is not 0, the dialog will be shown centered over the parent widget.

The file dialog's working directory will be set todir. Ifdir includes a file name, the file will be selected. Only files that match the givenfilter are shown. The filter selected is set toselectedFilter. The parametersdir,selectedFilter, andfilter may be empty strings. If you want multiple filters, separate them with ';;', for example:

"Images (*.png *.xpm *.jpg);;Text files (*.txt);;XML files (*.xml)"

Theoptions argument holds various options about how to run the dialog, see theQFileDialog::Option enum for more information on the flags you can pass.

The dialog's caption is set tocaption. Ifcaption is not specified then a default caption will be used.

On Windows, Mac OS X and Symbian^3, this static function will use the native file dialog and not aQFileDialog.

On Windows the dialog will spin a blocking modal event loop that will not dispatch any QTimers, and ifparent is not 0 then it will position the dialog just below the parent's title bar.

On Unix/X11, the normal behavior of the file dialog is to resolve and follow symlinks. For example, if/usr/tmp is a symlink to/var/tmp, the file dialog will change to/var/tmp after entering/usr/tmp. Ifoptions includesDontResolveSymlinks, the file dialog will treat symlinks as regular directories.

On Symbian^3 the parameterselectedFilter has no meaning and theoptions parameter is only used to define if the native file dialog is used.

Warning: Do not deleteparent during the execution of the dialog. If you want to do this, you should create the dialog yourself using one of theQFileDialog constructors.

See alsogetOpenFileNames(),getSaveFileName(), andgetExistingDirectory().

[static]QStringList QFileDialog::getOpenFileNames(QWidget * parent = 0, constQString & caption = QString(), constQString & dir = QString(), constQString & filter = QString(),QString * selectedFilter = 0,Options options = 0)

This is a convenience static function that will return one or more existing files selected by the user.

QStringList files=QFileDialog::getOpenFileNames(this,"Select one or more files to open","/home","Images (*.png *.xpm *.jpg)");

This function creates a modal file dialog with the givenparent widget. Ifparent is not 0, the dialog will be shown centered over the parent widget.

The file dialog's working directory will be set todir. Ifdir includes a file name, the file will be selected. The filter is set tofilter so that only those files which match the filter are shown. The filter selected is set toselectedFilter. The parametersdir,selectedFilter andfilter may be empty strings. If you need multiple filters, separate them with ';;', for instance:

"Images (*.png *.xpm *.jpg);;Text files (*.txt);;XML files (*.xml)"

The dialog's caption is set tocaption. Ifcaption is not specified then a default caption will be used.

On Windows, Mac OS X and Symbian^3, this static function will use the native file dialog and not aQFileDialog.

On Windows the dialog will spin a blocking modal event loop that will not dispatch any QTimers, and ifparent is not 0 then it will position the dialog just below the parent's title bar.

On Unix/X11, the normal behavior of the file dialog is to resolve and follow symlinks. For example, if/usr/tmp is a symlink to/var/tmp, the file dialog will change to/var/tmp after entering/usr/tmp. Theoptions argument holds various options about how to run the dialog, see theQFileDialog::Option enum for more information on the flags you can pass.

Note:If you want to iterate over the list of files, you should iterate over a copy. For example:

QStringList list= files;QStringList::Iterator it= list.begin();while(it!= list.end()) {    myProcessing(*it);++it;}

On Symbian^3 the parameterselectedFilter has no meaning and theoptions parameter is only used to define if the native file dialog is used. On Symbian^3, this function can only return a single filename.

Warning: Do not deleteparent during the execution of the dialog. If you want to do this, you should create the dialog yourself using one of theQFileDialog constructors.

See alsogetOpenFileName(),getSaveFileName(), andgetExistingDirectory().

[static]QString QFileDialog::getSaveFileName(QWidget * parent = 0, constQString & caption = QString(), constQString & dir = QString(), constQString & filter = QString(),QString * selectedFilter = 0,Options options = 0)

This is a convenience static function that will return a file name selected by the user. The file does not have to exist.

It creates a modal file dialog with the givenparent widget. Ifparent is not 0, the dialog will be shown centered over the parent widget.

QString fileName=QFileDialog::getSaveFileName(this, tr("Save File"),"/home/jana/untitled.png",                           tr("Images (*.png *.xpm *.jpg)"));

The file dialog's working directory will be set todir. Ifdir includes a file name, the file will be selected. Only files that match thefilter are shown. The filter selected is set toselectedFilter. The parametersdir,selectedFilter, andfilter may be empty strings. Multiple filters are separated with ';;'. For instance:

"Images (*.png *.xpm *.jpg);;Text files (*.txt);;XML files (*.xml)"

Theoptions argument holds various options about how to run the dialog, see theQFileDialog::Option enum for more information on the flags you can pass.

The default filter can be chosen by settingselectedFilter to the desired value.

The dialog's caption is set tocaption. Ifcaption is not specified, a default caption will be used.

On Windows, Mac OS X and Symbian^3, this static function will use the native file dialog and not aQFileDialog.

On Windows the dialog will spin a blocking modal event loop that will not dispatch any QTimers, and ifparent is not 0 then it will position the dialog just below the parent's title bar. On Mac OS X, with its native file dialog, the filter argument is ignored.

On Unix/X11, the normal behavior of the file dialog is to resolve and follow symlinks. For example, if/usr/tmp is a symlink to/var/tmp, the file dialog will change to/var/tmp after entering/usr/tmp. Ifoptions includesDontResolveSymlinks the file dialog will treat symlinks as regular directories.

On Symbian^3 the parametersfilter andselectedFilter have no meaning. Theoptions parameter is only used to define if the native file dialog is used.

Warning: Do not deleteparent during the execution of the dialog. If you want to do this, you should create the dialog yourself using one of theQFileDialog constructors.

See alsogetOpenFileName(),getOpenFileNames(), andgetExistingDirectory().

QStringList QFileDialog::history() const

Returns the browsing history of the filedialog as a list of paths.

See alsosetHistory().

QFileIconProvider * QFileDialog::iconProvider() const

Returns the icon provider used by the filedialog.

See alsosetIconProvider().

QAbstractItemDelegate * QFileDialog::itemDelegate() const

Returns the item delegate used to render the items in the views in the filedialog.

See alsosetItemDelegate().

QString QFileDialog::labelText(DialogLabel label) const

Returns the text shown in the filedialog in the specifiedlabel.

See alsosetLabelText().

QStringList QFileDialog::nameFilters() const

Returns the file type filters that are in operation on this file dialog.

This function was introduced in Qt 4.4.

See alsosetNameFilters().

void QFileDialog::open(QObject * receiver, constchar * member)

This is an overloaded function.

This function connects one of its signals to the slot specified byreceiver andmember. The specific signal depends isfilesSelected() iffileMode isExistingFiles andfileSelected() iffileMode is anything else.

The signal will be disconnected from the slot when the dialog is closed.

This function was introduced in Qt 4.5.

QAbstractProxyModel * QFileDialog::proxyModel() const

Returns the proxy model used by the file dialog. By default no proxy is set.

See alsosetProxyModel().

bool QFileDialog::restoreState(constQByteArray & state)

Restores the dialogs's layout, history and current directory to thestate specified.

Typically this is used in conjunction withQSettings to restore the size from a past session.

Returns false if there are errors

This function was introduced in Qt 4.3.

QByteArray QFileDialog::saveState() const

Saves the state of the dialog's layout, history and current directory.

Typically this is used in conjunction withQSettings to remember the size for a future session. A version number is stored as part of the data.

This function was introduced in Qt 4.3.

void QFileDialog::selectFile(constQString & filename)

Selects the givenfilename in the file dialog.

See alsoselectedFiles().

void QFileDialog::selectNameFilter(constQString & filter)

Sets the current file typefilter. Multiple filters can be passed infilter by separating them with semicolons or spaces.

This function was introduced in Qt 4.4.

See alsosetNameFilter(),setNameFilters(), andselectedNameFilter().

QStringList QFileDialog::selectedFiles() const

Returns a list of strings containing the absolute paths of the selected files in the dialog. If no files are selected, or the mode is notExistingFiles orExistingFile, selectedFiles() contains the current path in the viewport.

See alsoselectedNameFilter() andselectFile().

QString QFileDialog::selectedNameFilter() const

Returns the filter that the user selected in the file dialog.

This function was introduced in Qt 4.4.

See alsoselectedFiles().

void QFileDialog::setDirectory(constQString & directory)

Sets the file dialog's currentdirectory.

See alsodirectory().

void QFileDialog::setDirectory(constQDir & directory)

This is an overloaded function.

void QFileDialog::setFilter(QDir::Filters filters)

Sets the filter used by the model tofilters. The filter is used to specify the kind of files that should be shown.

This function was introduced in Qt 4.4.

See alsofilter().

void QFileDialog::setHistory(constQStringList & paths)

Sets the browsing history of the filedialog to contain the givenpaths.

See alsohistory().

void QFileDialog::setIconProvider(QFileIconProvider * provider)

Sets the icon provider used by the filedialog to the specifiedprovider.

See alsoiconProvider().

void QFileDialog::setItemDelegate(QAbstractItemDelegate * delegate)

Sets the item delegate used to render items in the views in the file dialog to the givendelegate.

Warning: You should not share the same instance of a delegate between views. Doing so can cause incorrect or unintuitive editing behavior since each view connected to a given delegate may receive thecloseEditor() signal, and attempt to access, modify or close an editor that has already been closed.

Note that the model used isQFileSystemModel. It has custom item data roles, which is described by theRoles enum. You can use aQFileIconProvider if you only want custom icons.

See alsoitemDelegate(),setIconProvider(), andQFileSystemModel.

void QFileDialog::setLabelText(DialogLabel label, constQString & text)

Sets thetext shown in the filedialog in the specifiedlabel.

See alsolabelText().

void QFileDialog::setNameFilter(constQString & filter)

Sets the filter used in the file dialog to the givenfilter.

Iffilter contains a pair of parentheses containing one or more ofanything*something, separated by spaces, then only the text contained in the parentheses is used as the filter. This means that these calls are all equivalent:

dialog.setNameFilter("All C++ files (*.cpp *.cc *.C *.cxx *.c++)");dialog.setNameFilter("*.cpp *.cc *.C *.cxx *.c++");

This function was introduced in Qt 4.4.

See alsosetNameFilters().

void QFileDialog::setNameFilters(constQStringList & filters)

Sets thefilters used in the file dialog.

QStringList filters;filters<<"Image files (*.png *.xpm *.jpg)"<<"Text files (*.txt)"<<"Any files (*)";QFileDialog dialog(this);dialog.setNameFilters(filters);dialog.exec();

This function was introduced in Qt 4.4.

See alsonameFilters().

void QFileDialog::setOption(Option option,bool on = true)

Sets the givenoption to be enabled ifon is true; otherwise, clears the givenoption.

This function was introduced in Qt 4.5.

See alsooptions andtestOption().

void QFileDialog::setProxyModel(QAbstractProxyModel * proxyModel)

Sets the model for the views to the givenproxyModel. This is useful if you want to modify the underlying model; for example, to add columns, filter data or add drives.

Any existing proxy model will be removed, but not deleted. The file dialog will take ownership of theproxyModel.

This function was introduced in Qt 4.3.

See alsoproxyModel().

void QFileDialog::setSidebarUrls(constQList<QUrl> & urls)

Sets theurls that are located in the sidebar.

For instance:

QList<QUrl> urls;    urls<<QUrl::fromLocalFile("/home/gvatteka/dev/qt-45")<<QUrl::fromLocalFile(QDesktopServices::storageLocation(QDesktopServices::MusicLocation));QFileDialog dialog;    dialog.setSidebarUrls(urls);    dialog.setFileMode(QFileDialog::AnyFile);if(dialog.exec()) {// ...    }

The file dialog will then look like this:

This function was introduced in Qt 4.3.

See alsosidebarUrls().

[virtual]void QFileDialog::setVisible(bool visible)

Reimplemented fromQWidget::setVisible().

QList<QUrl> QFileDialog::sidebarUrls() const

Returns a list of urls that are currently in the sidebar

This function was introduced in Qt 4.3.

See alsosetSidebarUrls().

bool QFileDialog::testOption(Option option) const

Returns true if the givenoption is enabled; otherwise, returns false.

This function was introduced in Qt 4.5.

See alsooptions andsetOption().

© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.


[8]ページ先頭

©2009-2025 Movatter.jp