QFileDialog 類

The QFileDialog 類提供允許用戶選擇文件 (或目錄) 的對話框。 更多...

頭: #include <QFileDialog>
繼承: QDialog

公共類型

enum AcceptMode { AcceptOpen, AcceptSave }
enum DialogLabel { LookIn, FileName, FileType, Accept, Reject }
enum FileMode { AnyFile, ExistingFile, Directory, ExistingFiles, DirectoryOnly }
typedef Mode
enum Option { ShowDirsOnly, DontResolveSymlinks, DontConfirmOverwrite, DontUseNativeDialog, ..., DontUseCustomDirectoryIcons }
flags Options
enum ViewMode { Detail, List }

特性

公共函數

QFileDialog (QWidget * parent , Qt::WindowFlags flags )
QFileDialog (QWidget * parent = 0, const QString & caption = QString(), const QString & directory = QString(), const QString & filter = QString())
~QFileDialog ()
AcceptMode acceptMode () const
QString defaultSuffix () const
QDir directory () const
FileMode fileMode () const
QDir::Filters filter () const
QStringList history () const
QFileIconProvider * iconProvider () const
QAbstractItemDelegate * itemDelegate () const
QString labelText (DialogLabel label ) const
QStringList nameFilters () const
void open (QObject * receiver , const char * member )
選項 options () const
QAbstractProxyModel * proxyModel () const
bool restoreState (const QByteArray & state )
QByteArray saveState () const
void selectFile (const QString & filename )
void selectNameFilter (const QString & filter )
QStringList selectedFiles () const
QString selectedNameFilter () const
void setAcceptMode (AcceptMode mode )
void setDefaultSuffix (const QString & suffix )
void setDirectory (const QString & directory )
void setDirectory (const QDir & directory )
void setFileMode (FileMode mode )
void setFilter (QDir::Filters filters )
void setHistory (const QStringList & paths )
void setIconProvider (QFileIconProvider * provider )
void setItemDelegate (QAbstractItemDelegate * delegate )
void setLabelText (DialogLabel label , const QString & text )
void setNameFilter (const QString & filter )
void setNameFilters (const QStringList & filters )
void setOption (Option option , bool on = true)
void setOptions (Options options )
void setProxyModel (QAbstractProxyModel * proxyModel )
void setSidebarUrls (const QList<QUrl> & urls )
void setViewMode (ViewMode mode )
QList<QUrl> sidebarUrls () const
bool testOption (Option option ) const
ViewMode viewMode () const

重實現公共函數

virtual void setVisible (bool visible )

信號

void currentChanged (const QString & path )
void directoryEntered (const QString & directory )
void fileSelected (const QString & file )
void filesSelected (const QStringList & selected )
void filterSelected (const QString & filter )

靜態公共成員

QString getExistingDirectory (QWidget * parent = 0, const QString & caption = QString(), const QString & dir = QString(), Options options = ShowDirsOnly)
QString getOpenFileName (QWidget * parent = 0, const QString & caption = QString(), const QString & dir = QString(), const QString & filter = QString(), QString * selectedFilter = 0, Options options = 0)
QStringList getOpenFileNames (QWidget * parent = 0, const QString & caption = QString(), const QString & dir = QString(), const QString & filter = QString(), QString * selectedFilter = 0, Options options = 0)
QString getSaveFileName (QWidget * parent = 0, const QString & caption = QString(), const QString & dir = QString(), const QString & filter = QString(), QString * selectedFilter = 0, Options options = 0)

重實現保護函數

virtual void accept ()
virtual void changeEvent (QEvent * e )
virtual void done (int result )

額外繼承成員

詳細描述

The QFileDialog 類提供允許用戶選擇文件 (或目錄) 的對話框。

The QFileDialog 類使用戶能夠遍曆文件係統,以選擇一個或多個文件或目錄。

最輕鬆方式創建 QFileDialog 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)"));
					

在以上範例中,模態 QFileDialog 的創建是使用靜態函數。對話框初始顯示 /home/jana 目錄的內容,並顯示與字符串 Image files (*.png *.jpg *.bmp) 中給定模式匹配的文件。文件對話框父級被設為 this ,且窗口標題被設為 Open Image。

若想要使用多個過濾器,分隔每過濾器采用 two 分號。例如:

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

可以創建自己的 QFileDialog 無需使用靜態函數。通過調用 setFileMode (),可以指定用戶必須在對話框中選擇什麼:

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

在以上範例中,文件對話框的模式被設為 AnyFile ,意味著用戶可以選擇任何文件,甚至指定不存在的文件。此模式對於創建 Save As (另存為) 文件對話框很有用。使用 ExistingFile 若用戶必須選擇現有文件,或 Directory 若隻有目錄可以被選擇。見 QFileDialog::FileMode 枚舉瞭解模式的完整列錶。

The fileMode 特性包含對話框的操作模式;這指示用戶期望選擇什麼類型的對象。使用 setNameFilter () 以設置對話框的文件過濾器。例如:

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

在以上範例中,把過濾器設為 "Images (*.png *.xpm *.jpg)" ,這意味著僅文件具有擴展名 png , xpm ,或 jpg 將展示在 QFileDialog 。可以應用多個過濾器通過使用 setNameFilters ()。使用 selectNameFilter () 以選擇給齣的某一過濾器作為文件對話框默認過濾器。

文件對話框有 2 種查看模式: List and Detail . List 將當前目錄內容呈現為文件和目錄名稱列錶。 Detail 顯示文件和目錄名稱列錶,但每個名稱旁邊還提供額外信息 (譬如:文件大小和修改日期)。設置模式采用 setViewMode ():

dialog.setViewMode(QFileDialog::Detail);
					

當創建自己的文件對話框時需要使用的最後一個重要函數是 selectedFiles ().

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

在以上範例中,創建並展示模態文件對話框。若用戶點擊 OK,選中文件被放入 fileName .

可以設置對話框的工作目錄采用 setDirectory ()。可以選擇當前目錄中的每個文件使用 selectFile () 函數。

The 標準對話框 範例展示如何使用 QFileDialog 及其它內置 Qt 對話框。

另請參閱 QDir , QFileInfo , QFile , QPrintDialog , QColorDialog , QFontDialog , 標準對話框範例 ,和 應用程序範例 .

成員類型文檔編製

enum QFileDialog:: AcceptMode

常量
QFileDialog::AcceptOpen 0
QFileDialog::AcceptSave 1

enum QFileDialog:: DialogLabel

常量
QFileDialog::LookIn 0
QFileDialog::FileName 1
QFileDialog::FileType 2
QFileDialog::Accept 3
QFileDialog::Reject 4

enum QFileDialog:: FileMode

此枚舉被用於指示用戶可以在文件對話框中選擇什麼。即:對話框將返迴什麼,若用戶點擊 OK。

常量 描述
QFileDialog::AnyFile 0 文件的名稱,無論它是否存在。
QFileDialog::ExistingFile 1 單個現有文件的名稱。
QFileDialog::Directory 2 The name of a directory. Both files and directories are displayed.
QFileDialog::ExistingFiles 3 零個或多個現有文件的名稱。

從 Qt 4.5 起此值已過時:

常量 描述
QFileDialog::DirectoryOnly 4 使用 Directory and setOption ( ShowDirsOnly , true) 代替。

另請參閱 setFileMode ().

typedef QFileDialog:: Mode

使用 QFileDialog::FileMode 代替。

enum QFileDialog:: Option
flags QFileDialog:: Options

常量 描述
QFileDialog::ShowDirsOnly 0x00000001 Only show directories in the file dialog. By default both files and directories are shown. (Valid only in the Directory file mode.)
QFileDialog::DontResolveSymlinks 0x00000002 不解析文件對話框中的符號鏈接。默認情況下,解析符號鏈接。
QFileDialog::DontConfirmOverwrite 0x00000004 不要求確認,若選中現有文件。默認情況下,請求確認。
QFileDialog::DontUseNativeDialog 0x00000010 Don't use the native file dialog. By default, the native file dialog is used unless you use a subclass of QFileDialog 包含 Q_OBJECT 宏。
QFileDialog::ReadOnly 0x00000020 指示模型為隻讀。
QFileDialog::HideNameFilterDetails 0x00000040 指示是否隱藏文件名過濾器細節。
QFileDialog::DontUseSheet 0x00000008 In 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, use QFileDialog::open () 代替。
QFileDialog::DontUseCustomDirectoryIcons 0x00000080 Always 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.

Options 類型是 typedef 對於 QFlags <Option>。它存儲 Option 值的 OR (或) 組閤。

enum QFileDialog:: ViewMode

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

常量 描述
QFileDialog::Detail 0 Displays an icon, a name, and details for each item in the directory.
QFileDialog::List 1 Displays only an icon and a name for each item in the directory.

另請參閱 setViewMode ().

特性文檔編製

acceptMode : AcceptMode

此特性保持對話框的接受方式。

動作模式定義對話框是用於打開文件還是保存文件。

默認情況下,此特性被設為 AcceptOpen .

訪問函數:

AcceptMode acceptMode () const
void setAcceptMode (AcceptMode mode )

另請參閱 AcceptMode .

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).

訪問函數:

QString defaultSuffix () const
void setDefaultSuffix (const QString & suffix )

fileMode : FileMode

此特性保持對話框的文件模式。

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

默認情況下,此特性被設為 AnyFile .

This function will set the labels for the FileName and Accept DialogLabel s. It is possible to set custom text after the call to setFileMode().

訪問函數:

FileMode fileMode () const
void setFileMode (FileMode mode )

另請參閱 FileMode .

options : Options

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

默認情況下,所有選項是被禁用的。

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).

該特性在 Qt 4.5 引入。

訪問函數:

選項 options () const
void setOptions (Options options )

另請參閱 setOption () 和 testOption ().

viewMode : ViewMode

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

默認情況下, Detail mode is used to display information about files and directories.

訪問函數:

ViewMode viewMode () const
void setViewMode (ViewMode mode )

另請參閱 ViewMode .

成員函數文檔編製

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

構造文件對話框采用給定 parent 和小部件 flags .

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

構造文件對話框采用給定 parent and caption that initially displays the contents of the specified directory . The contents of the directory are filtered before being shown in the dialog, using a semicolon-separated list of filters specified by filter .

QFileDialog:: ~QFileDialog ()

銷毀文件對話框。

[virtual protected] void QFileDialog:: accept ()

重實現自 QDialog::accept ().

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

重實現自 QWidget::changeEvent ().

[signal] void QFileDialog:: currentChanged (const QString & path )

When the current file changes, this signal is emitted with the new file name as the path 參數。

另請參閱 filesSelected ().

QDir QFileDialog:: directory () const

返迴目前顯示在對話框中的目錄。

另請參閱 setDirectory ().

[signal] void QFileDialog:: directoryEntered (const QString & directory )

此信號被發射當用戶鍵入 directory .

該函數在 Qt 4.3 引入。

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

重實現自 QDialog::done ().

[signal] void QFileDialog:: fileSelected (const QString & file )

當選定改變且對話框接受時,此信號發射帶有 (可能空) 選中 file .

另請參閱 currentChanged () 和 QDialog::Accepted .

[signal] void QFileDialog:: filesSelected (const QStringList & selected )

When the selection changes and the dialog is accepted, this signal is emitted with the (possibly empty) list of selected 文件。

另請參閱 currentChanged () 和 QDialog::Accepted .

QDir::Filters QFileDialog:: filter () const

返迴所用過濾器,當顯示文件時。

該函數在 Qt 4.4 引入。

另請參閱 setFilter ().

[signal] void QFileDialog:: filterSelected (const QString & filter )

此信號被發射,當用戶選擇 filter .

該函數在 Qt 4.3 引入。

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

這是將返迴由用戶選擇的現有目錄的方便靜態函數。

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

此函數創建模態文件對話框采用給定 parent 小部件。若 parent 非 0,對話框將展示在父級 Widget 中心。

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

The options 自變量保持有關如何運行對話框的各種選項,見 QFileDialog::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 a QFileDialog . On Windows CE, if the device has no native file dialog, a QFileDialog 會被使用。

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 。若 options 包括 DontResolveSymlinks , 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 if parent is not 0 then it will position the dialog just below the parent's title bar.

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

警告: 不要刪除 parent during the execution of the dialog. If you want to do this, you should create the dialog yourself using one of the QFileDialog 構造函數。

另請參閱 getOpenFileName (), getOpenFileNames (),和 getSaveFileName ().

[static] QString QFileDialog:: getOpenFileName ( QWidget * parent = 0, const QString & caption = QString(), const QString & dir = QString(), const QString & 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 given parent 小部件。若 parent 非 0,對話框將展示在父級 Widget 中心。

文件對話框的工作目錄將被設為 dir 。若 dir includes a file name, the file will be selected. Only files that match the given filter 纔被展示。選中過濾器被設為 selectedFilter 。參數 dir , selectedFilter ,和 filter may be empty strings. If you want multiple filters, separate them with ';;', for example:

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

The options 自變量保持有關如何運行對話框的各種選項,見 QFileDialog::Option 枚舉瞭解可以傳遞標誌的更多有關信息。

把對話框標題設為 caption 。若 caption 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 a QFileDialog .

On Windows the dialog will spin a blocking modal event loop that will not dispatch any QTimers, and if parent 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 。若 options 包括 DontResolveSymlinks , the file dialog will treat symlinks as regular directories.

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

警告: 不要刪除 parent during the execution of the dialog. If you want to do this, you should create the dialog yourself using one of the QFileDialog 構造函數。

另請參閱 getOpenFileNames (), getSaveFileName (),和 getExistingDirectory ().

[static] QStringList QFileDialog:: getOpenFileNames ( QWidget * parent = 0, const QString & caption = QString(), const QString & dir = QString(), const QString & 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)");
					

此函數創建模態文件對話框采用給定 parent 小部件。若 parent 非 0,對話框將展示在父級 Widget 中心。

文件對話框的工作目錄將被設為 dir 。若 dir includes a file name, the file will be selected. The filter is set to filter so that only those files which match the filter are shown. The filter selected is set to selectedFilter 。參數 dir , selectedFilter and filter may be empty strings. If you need multiple filters, separate them with ';;', for instance:

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

把對話框標題設為 caption 。若 caption 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 a QFileDialog .

On Windows the dialog will spin a blocking modal event loop that will not dispatch any QTimers, and if parent 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 options 自變量保持有關如何運行對話框的各種選項,見 QFileDialog::Option 枚舉瞭解可以傳遞標誌的更多有關信息。

注意: 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 parameter selectedFilter has no meaning and the options parameter is only used to define if the native file dialog is used. On Symbian^3, this function can only return a single filename.

警告: 不要刪除 parent during the execution of the dialog. If you want to do this, you should create the dialog yourself using one of the QFileDialog 構造函數。

另請參閱 getOpenFileName (), getSaveFileName (),和 getExistingDirectory ().

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

這是將返迴用戶選擇文件名的方便靜態函數。文件不必存在。

它創建模態文件對話框采用給定 parent 小部件。若 parent 非 0,對話框將展示在父級 Widget 中心。

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

文件對話框的工作目錄將被設為 dir 。若 dir 包括文件名,文件將被選中。文件匹配 filter 纔被展示。選中過濾器被設為 selectedFilter 。參數 dir , selectedFilter ,和 filter 可以是空字符串。多個過濾器采用 ;; 分隔。例如:

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

The options 自變量保持有關如何運行對話框的各種選項,見 QFileDialog::Option 枚舉瞭解可以傳遞標誌的更多有關信息。

可以選取默認過濾器通過設置 selectedFilter 到期望值。

把對話框標題設為 caption 。若 caption 未指定,將使用默認標題。

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

On Windows the dialog will spin a blocking modal event loop that will not dispatch any QTimers, and if parent 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 。若 options 包括 DontResolveSymlinks the file dialog will treat symlinks as regular directories.

On Symbian^3 the parameters filter and selectedFilter have no meaning. The options parameter is only used to define if the native file dialog is used.

警告: 不要刪除 parent during the execution of the dialog. If you want to do this, you should create the dialog yourself using one of the QFileDialog 構造函數。

另請參閱 getOpenFileName (), getOpenFileNames (),和 getExistingDirectory ().

QStringList QFileDialog:: history () const

以路徑列錶形式返迴文件對話框的瀏覽曆史。

另請參閱 setHistory ().

QFileIconProvider * QFileDialog:: iconProvider () const

返迴文件對話框使用的圖標提供程序。

另請參閱 setIconProvider ().

QAbstractItemDelegate * QFileDialog:: itemDelegate () const

返迴用於在文件對話框視圖中呈現項的項委托。

另請參閱 setItemDelegate ().

QString QFileDialog:: labelText ( DialogLabel label ) const

返迴文件對話框展示的文本在指定 label .

另請參閱 setLabelText ().

QStringList QFileDialog:: nameFilters () const

返迴在此文件對話框中運轉的文件類型過濾器。

該函數在 Qt 4.4 引入。

另請參閱 setNameFilters ().

void QFileDialog:: open ( QObject * receiver , const char * member )

這是重載函數。

This function connects one of its signals to the slot specified by receiver and member . The specific signal depends is filesSelected () 若 fileMode is ExistingFiles and fileSelected () 若 fileMode is anything else.

將從槽斷開信號連接,當關閉對話框時。

該函數在 Qt 4.5 引入。

QAbstractProxyModel * QFileDialog:: proxyModel () const

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

另請參閱 setProxyModel ().

bool QFileDialog:: restoreState (const QByteArray & state )

Restores the dialogs's layout, history and current directory to the state 指定。

通常,這用於結閤 QSettings to restore the size from a past session.

Returns false if there are errors

該函數在 Qt 4.3 引入。

QByteArray QFileDialog:: saveState () const

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

通常,這用於結閤 QSettings to remember the size for a future session. A version number is stored as part of the data.

該函數在 Qt 4.3 引入。

void QFileDialog:: selectFile (const QString & filename )

選擇給定 filename 在文件對話框。

另請參閱 selectedFiles ().

void QFileDialog:: selectNameFilter (const QString & filter )

設置當前文件類型 filter . Multiple filters can be passed in filter by separating them with semicolons or spaces.

該函數在 Qt 4.4 引入。

另請參閱 setNameFilter (), setNameFilters (),和 selectedNameFilter ().

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 not ExistingFiles or ExistingFile , selectedFiles() contains the current path in the viewport.

另請參閱 selectedNameFilter () 和 selectFile ().

QString QFileDialog:: selectedNameFilter () const

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

該函數在 Qt 4.4 引入。

另請參閱 selectedFiles ().

void QFileDialog:: setDirectory (const QString & directory )

設置文件對話框的當前 directory .

另請參閱 directory ().

void QFileDialog:: setDirectory (const QDir & directory )

這是重載函數。

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

將用於模型的過濾器設為 filters 。過濾器用於指定應展示的文件種類。

該函數在 Qt 4.4 引入。

另請參閱 filter ().

void QFileDialog:: setHistory (const QStringList & paths )

設置文件對話框瀏覽曆史以包含給定 paths .

另請參閱 history ().

void QFileDialog:: setIconProvider ( QFileIconProvider * provider )

將用於文件對話框的圖標提供程序設為指定 provider .

另請參閱 iconProvider ().

void QFileDialog:: setItemDelegate ( QAbstractItemDelegate * delegate )

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

警告: 不應該在視圖之間,共享實例化的相同委托。這樣做會導緻不正確 (或不直觀) 編輯行為,由於連接到給定委托的各視圖都可以接收 closeEditor() 信號,且試圖訪問、修改或關閉已關閉的編輯器。

Note that the model used is QFileSystemModel . It has custom item data roles, which is described by the Roles 枚舉。可以使用 QFileIconProvider 若隻想要自定義圖標。

另請參閱 itemDelegate (), setIconProvider (),和 QFileSystemModel .

void QFileDialog:: setLabelText ( DialogLabel label , const QString & text )

設置 text 展示在文件對話框在指定 label .

另請參閱 labelText ().

void QFileDialog:: setNameFilter (const QString & filter )

將用於文件對話框的過濾器設為給定 filter .

filter contains a pair of parentheses containing one or more of anything*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++");
					

該函數在 Qt 4.4 引入。

另請參閱 setNameFilters ().

void QFileDialog:: setNameFilters (const QStringList & filters )

設置 filters 用於文件對話框。

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

該函數在 Qt 4.4 引入。

另請參閱 nameFilters ().

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

設置給定 option 為被啓用若 on 為 true;否則,清零給定 option .

該函數在 Qt 4.5 引入。

另請參閱 options and testOption ().

void QFileDialog:: setProxyModel ( QAbstractProxyModel * proxyModel )

把視圖模型設為給定 proxyModel 。這很有用,若想要修改底層模型;例如:添加列、過濾數據、或添加驅動器。

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

該函數在 Qt 4.3 引入。

另請參閱 proxyModel ().

void QFileDialog:: setSidebarUrls (const QList < QUrl > & urls )

設置 urls 位於側邊欄中。

例如:

    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()) {
        // ...
    }
					

文件對話框看起來就像這樣:

該函數在 Qt 4.3 引入。

另請參閱 sidebarUrls ().

[虛擬] void QFileDialog:: setVisible ( bool visible )

重實現自 QWidget::setVisible ().

QList < QUrl > QFileDialog:: sidebarUrls () const

返迴目前在側邊欄中的 URL 列錶

該函數在 Qt 4.3 引入。

另請參閱 setSidebarUrls ().

bool QFileDialog:: testOption ( Option option ) const

Returns true if the given option 被啓用;否則,返迴 false。

該函數在 Qt 4.5 引入。

另請參閱 options and setOption ().