The easiest way to create a TQFileDialog is to use the static functions. On Windows, these static functions will call the native Windows file dialog and on Mac OS X, these static function will call the native Mac OS X file dialog.
In the above example, a modal TQFileDialog is created using a static function. The startup directory is set to "/home". The file filter is set to "Images (*.png *.xpm *.jpg)". The parent of the file dialog is set to \fIthis\fR and it is given the identification name - "open file dialog". The caption at the top of file dialog is set to "Choose a file". If you want to use multiple filters, separate each one with \fItwo\fR semi-colons, e.g.
In the above example, the mode of the file dialog is set to AnyFile, meaning that the user can select any file, or even specify a file that doesn't exist. This mode is useful for creating a "File Save As" file dialog. Use ExistingFile if the user must select an existing file or Directory if only a directory may be selected. (See the TQFileDialog::Mode enum for the complete list of modes.)
In the above example, the filter is set to "Images (*.png *.xpm *.jpg)", this means that only files with the extension \fCpng\fR, \fCxpm\fR or \fCjpg\fR will be shown in the TQFileDialog. You can apply several filters by using setFilters() and add additional filters with addFilter(). Use setSelectedFilter() to select one of the filters you've given as the file dialog's default filter. Whenever the user changes the filter the filterSelected() signal is emitted.
The file dialog has two view modes, TQFileDialog::List which simply lists file and directory names and TQFileDialog::Detail which displays additional information alongside each name, e.g. file size, modification date, etc. Set the mode with setViewMode().
The dialog's working directory can be set with setDir(). The display of hidden files is controlled with setShowHiddenFiles(). The dialog can be forced to re-read the directory with rereadDir() and re-sort the directory with resortDir(). All the files in the current directory can be selected with selectAll().
There are two kinds of preview widgets that can be used with TQFileDialogs: \fIcontent\fR preview widgets and \fIinformation\fR preview widgets. They are created and used in the same way except that the function names differ, e.g. setContentsPreview() and setInfoPreview().
A preview widget is a widget that is placed inside a TQFileDialog so that the user can see either the contents of the file, or information about the file.
In the above snippet, we create a preview widget which inherits from TQLabel and TQFilePreview. File preview widgets \fImust\fR inherit from TQFilePreview.
Inside the class we reimplement TQFilePreview::previewUrl(), this is where we determine what happens when a file is selected. In the above example we only show a preview of the file if it is a valid pixmap. Here's how to make a file dialog use a preview widget:
The first line creates an instance of our preview widget. We then create our file dialog and call setContentsPreviewEnabled( TRUE ), this tell the file dialog to preview the contents of the currently selected file. We then call setContentsPreview() -- note that we pass the same preview widget twice. Finally, before showing the file dialog, we call setPreviewMode() setting the mode to \fIContents\fR which will show the contents preview of the file that the user has selected.
.PP
If you create another preview widget that is used for displaying information about a file, create it in the same way as the contents preview widget and call setInfoPreviewEnabled(), and setInfoPreview(). Then the user will be able to switch between the two preview modes.
Constructs a file dialog called \fIname\fR with the parent, \fIparent\fR. If \fImodal\fR is TRUE then the file dialog is modal; otherwise it is modeless.
.PP
If \fIdirName\fR is specified then it will be used as the dialog's working directory, i.e. it will be the directory that is shown when the dialog appears. If \fIfilter\fR is specified it will be used as the dialog's file filter.
Constructs a file dialog called \fIname\fR, with the parent, \fIparent\fR. If \fImodal\fR is TRUE then the file dialog is modal; otherwise it is modeless.
In the above example, a file dialog is created, and the file filter "Images (*.png *.jpg *.xpm)" is added and is set as the current filter. The original filter, "All Files (*)", is still available.
Adds the tool button \fIb\fR to the row of tool buttons at the top of the file dialog. The button is appended to the right of this row. If \fIseparator\fR is TRUE, a small space is inserted between the last button of the row and the new button \fIb\fR.
.PP
See also addWidgets(), addLeftWidget(), and addRightWidget().
Adds the specified widgets to the bottom of the file dialog. The label \fIl\fR is placed underneath the "file name" and the "file types" labels. The widget \fIw\fR is placed underneath the file types combobox. The button \fIb\fR is placed underneath the Cancel pushbutton.
This function creates a modal file dialog called \fIname\fR, with parent, \fIparent\fR. If parent is not 0, the dialog will be shown centered over the parent.
The dialog's working directory is set to \fIdir\fR, and the caption is set to \fIcaption\fR. Either of these may be TQString::null in which case the current directory and a default caption will be used respectively.
If \fIdirOnly\fR is TRUE, then only directories will be shown in the file dialog; otherwise both directories and files will be shown.
.PP
Under 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. If \fIresolveSymlinks\fR is FALSE, the file dialog will treat symlinks as regular directories.
Under Windows and Mac OS X, this static function will use the native file dialog and not a TQFileDialog, unless the style of the application is set to something other than the native style. (Note that on Windows the dialog will spin a blocking modal event loop that will not dispatch any TQTimers and if parent is not 0 then it will position the dialog just under the parent's titlebar).
The function creates a modal file dialog called \fIname\fR, with parent, \fIparent\fR. If a parent is not 0, the dialog will be shown centered over the parent.
The file dialog's working directory will be set to \fIstartWith\fR. If \fIstartWith\fR includes a file name, the file will be selected. The filter is set to \fIfilter\fR so that only those files which match the filter are shown. The filter selected is set to \fIselectedFilter\fR. The parameters \fIstartWith\fR, \fIselectedFilter\fR and \fIfilter\fR may be TQString::null.
Under Windows and Mac OS X, this static function will use the native file dialog and not a TQFileDialog, unless the style of the application is set to something other than the native style (Note that on Windows the dialog will spin a blocking modal event loop that will not dispatch any TQTimers and if parent is not 0 then it will position the dialog just under the parent's titlebar).
Under 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. If \fIresolveSymlinks\fR is FALSE, the file dialog will treat symlinks as regular directories.
.PP
See also getOpenFileNames(), getSaveFileName(), and getExistingDirectory().
.PP
Examples:
.)l action/application.cpp, addressbook/mainwindow.cpp, application/application.cpp, distributor/distributor.ui.h, network/ftpclient/ftpmainwindow.ui.h, qwerty/qwerty.cpp, and showimg/showimg.cpp.
This function creates a modal file dialog called \fIname\fR, with parent \fIparent\fR. If \fIparent\fR is not 0, the dialog will be shown centered over the parent.
The file dialog's working directory will be set to \fIdir\fR. If \fIdir\fR includes a file name, the file will be selected. The filter is set to \fIfilter\fR so that only those files which match the filter are shown. The filter selected is set to \fIselectedFilter\fR. The parameters \fIdir\fR, \fIselectedFilter\fR and \fIfilter\fR may be TQString::null.
Under Windows and Mac OS X, this static function will use the native file dialog and not a TQFileDialog, unless the style of the application is set to something other than the native style. (Note that on Windows the dialog will spin a blocking modal event loop that will not dispatch any TQTimers and if parent is not 0 then it will position the dialog just under the parent's titlebar).
Under 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. If \fIresolveSymlinks\fR is FALSE, the file dialog will treat symlinks as regular directories.
.PP
Note that if you want to iterate over the list of files, you should iterate over a copy, e.g.
The file dialog's working directory will be set to \fIstartWith\fR. If \fIstartWith\fR includes a file name, the file will be selected. The filter is set to \fIfilter\fR so that only those files which match the filter are shown. The filter selected is set to \fIselectedFilter\fR. The parameters \fIstartWith\fR, \fIselectedFilter\fR and \fIfilter\fR may be TQString::null.
Under Windows and Mac OS X, this static function will use the native file dialog and not a TQFileDialog, unless the style of the application is set to something other than the native style. (Note that on Windows the dialog will spin a blocking modal event loop that will not dispatch any TQTimers and if parent is not 0 then it will position the dialog just under the parent's titlebar.
Under 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. If \fIresolveSymlinks\fR is FALSE, the file dialog will treat symlinks as regular directories.
.PP
See also getOpenFileName(), getOpenFileNames(), and getExistingDirectory().
.PP
Examples:
.)l action/application.cpp, addressbook/mainwindow.cpp, application/application.cpp, network/ftpclient/ftpmainwindow.ui.h, qmag/qmag.cpp, qwerty/qwerty.cpp, and showimg/showimg.cpp.
Returns TRUE if the file dialog can provide a contents preview of the currently selected file; otherwise returns FALSE. See the "contentsPreview" property for details.
Returns TRUE if the file dialog can provide preview information about the currently selected file; otherwise returns FALSE. See the "infoPreview" property for details.
Rereads the current directory shown in the file dialog.
.PP
The only time you will need to call this function is if the contents of the directory change and you wish to refresh the file dialog to reflect the change.
Sets the widget to be used for displaying the contents of the file to the widget \fIw\fR and a preview of those contents to the TQFilePreview \fIpreview\fR.
Normally you would create a preview widget that derives from both TQWidget and TQFilePreview, so you should pass the same widget twice. If you don't, you must remember to delete the preview object in order to avoid memory leaks.
Sets the filter used in the file dialog to \fInewFilter\fR.
.PP
If \fInewFilter\fR contains a pair of parentheses containing one or more of \fI\fBanything*something\fR\fR separated by spaces or by semi-colons then only the text contained in the parentheses is used as the filter. This means that these calls are all equivalent:
.PP
.nf
.br
fd->setFilter( "All C++ files (*.cpp *.cc *.C *.cxx *.c++)" );
.br
fd->setFilter( "*.cpp *.cc *.C *.cxx *.c++" );
.br
fd->setFilter( "All C++ files (*.cpp;*.cc;*.C;*.cxx;*.c++)" );
Sets the widget to be used for displaying information about the file to the widget \fIw\fR and a preview of that information to the TQFilePreview \fIpreview\fR.
Normally you would create a preview widget that derives from both TQWidget and TQFilePreview, so you should pass the same widget twice. If you don't, you must remember to delete the preview object in order to avoid memory leaks.
Sets the default selection to \fIfilename\fR. If \fIfilename\fR is absolute, setDir() is also called to set the file dialog's working directory to the filename's directory.
This property holds the file dialog's working directory.
.PP
Get this property's value with dirPath().
.PP
See also dir() and setDir().
.SH "bool infoPreview"
This property holds whether the file dialog can provide preview information about the currently selected file.
.PP
The default is FALSE.
.PP
Set this property's value with setInfoPreviewEnabled() and get this property's value with isInfoPreviewEnabled().
.SH "Mode mode"
This property holds the file dialog's mode.
.PP
The default mode is ExistingFile.
.PP
Set this property's value with setMode() and get this property's value with mode().
.SH "PreviewMode previewMode"
This property holds the preview mode for the file dialog.
.PP
If you set the mode to be a mode other than \fINoPreview\fR, you must use setInfoPreview() or setContentsPreview() to set the dialog's preview widget to your preview widget and enable the preview widget(s) with setInfoPreviewEnabled() or setContentsPreviewEnabled().
.PP
See also infoPreview, contentsPreview, and viewMode.
.PP
Set this property's value with setPreviewMode() and get this property's value with previewMode().
If one or more files are selected, selectedFiles contains their names including their absolute paths. If no files are selected or the mode isn't ExistingFiles selectedFiles is an empty list.
.PP
It is more convenient to use selectedFile() if the mode is ExistingFile, Directory or DirectoryOnly.
.PP
Note that if you want to iterate over the list, you should iterate over a copy, e.g.
This property holds the filter which the user has selected in the file dialog.
.PP
Get this property's value with selectedFilter().
.PP
See also filterSelected(), selectedFiles, and selectedFile.
.SH "bool showHiddenFiles"
This property holds whether hidden files are shown in the file dialog.
.PP
The default is FALSE, i.e. don't show hidden files.
.PP
Set this property's value with setShowHiddenFiles() and get this property's value with showHiddenFiles().
.SH "ViewMode viewMode"
This property holds the file dialog's view mode.
.PP
If you set the view mode to be \fIDetail\fR (the default), then you will see the file's details, such as the size of the file and the date the file was last modified in addition to the file's name.
.PP
If you set the view mode to be \fIList\fR, then you will just see a list of the files and folders.