
We bake cookies in your browser for a better experience. Using this site means that you consent.Read More
TheQ3FileDialog class provides dialogs that allow users to select files or directories.More...
| Header: | #include <Q3FileDialog> |
| Inherits: | QDialog |
| enum | Mode { AnyFile, ExistingFile, Directory, DirectoryOnly, ExistingFiles } |
| enum | PreviewMode { NoPreview, Contents, Info } |
| enum | ViewMode { List, Detail } |
|
|
| Q3FileDialog(const QString & dirName, const QString & filter = QString(), QWidget * parent = 0, const char * name = 0, bool modal = false) | |
| Q3FileDialog(QWidget * parent = 0, const char * name = 0, bool modal = false) | |
| ~Q3FileDialog() | |
| void | addFilter(const QString & filter) |
| const QDir * | dir() const |
| QString | dirPath() const |
| bool | isContentsPreviewEnabled() const |
| bool | isInfoPreviewEnabled() const |
| Mode | mode() const |
| PreviewMode | previewMode() const |
| void | rereadDir() |
| void | resortDir() |
| void | selectAll(bool b) |
| QString | selectedFile() const |
| QStringList | selectedFiles() const |
| QString | selectedFilter() const |
| void | setContentsPreview(QWidget * w, Q3FilePreview * preview) |
| void | setContentsPreviewEnabled(bool) |
| void | setDir(const QDir & dir) |
| void | setInfoPreview(QWidget * w, Q3FilePreview * preview) |
| void | setInfoPreviewEnabled(bool) |
| void | setMode(Mode) |
| void | setPreviewMode(PreviewMode m) |
| virtual void | setSelectedFilter(const QString & mask) |
| virtual void | setSelectedFilter(int n) |
| void | setSelection(const QString & filename) |
| void | setShowHiddenFiles(bool s) |
| void | setViewMode(ViewMode m) |
| bool | showHiddenFiles() const |
| Q3Url | url() const |
| ViewMode | viewMode() const |
| virtual bool | eventFilter(QObject * o, QEvent * e) |
| virtual void | done(int i) |
| void | setDir(const QString & pathstr) |
| void | setFilter(const QString & newFilter) |
| void | setFilters(const QString & filters) |
| void | setFilters(const char ** types) |
| void | setFilters(const QStringList & types) |
| void | setUrl(const Q3UrlOperator & url) |
| void | dirEntered(const QString & directory) |
| void | fileHighlighted(const QString & file) |
| void | fileSelected(const QString & file) |
| void | filesSelected(const QStringList & files) |
| void | filterSelected(const QString & filter) |
| QString | getExistingDirectory(const QString & dir = QString(), QWidget * parent = 0, const char * name = 0, const QString & caption = QString(), bool dirOnly = true, bool resolveSymlinks = true) |
| QString | getOpenFileName(const QString & startWith = QString(), const QString & filter = QString(), QWidget * parent = 0, const char * name = 0, const QString & caption = QString(), QString * selectedFilter = 0, bool resolveSymlinks = true) |
| QStringList | getOpenFileNames(const QString & filter = QString(), const QString & dir = QString(), QWidget * parent = 0, const char * name = 0, const QString & caption = QString(), QString * selectedFilter = 0, bool resolveSymlinks = true) |
| QString | getSaveFileName(const QString & startWith = QString(), const QString & filter = QString(), QWidget * parent = 0, const char * name = 0, const QString & caption = QString(), QString * selectedFilter = 0, bool resolveSymlinks = true) |
| Q3FileIconProvider * | iconProvider() |
| void | setIconProvider(Q3FileIconProvider * provider) |
| void | addLeftWidget(QWidget * w) |
| void | addRightWidget(QWidget * w) |
| void | addToolButton(QAbstractButton * b, bool separator = false) |
| void | addWidgets(QLabel * l, QWidget * w, QPushButton * b) |
| virtual void | keyPressEvent(QKeyEvent * ke) |
| virtual void | resizeEvent(QResizeEvent * e) |
TheQ3FileDialog class provides dialogs that allow users to select files or directories.
TheQ3FileDialog class enables a user to traverse their file system in order to select one or many files or a directory.
The easiest way to create aQ3FileDialog 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.
QString s=Q3FileDialog::getOpenFileName("/home","Images (*.png *.xpm *.jpg)",this,"open file dialog","Choose a file");
In the above example, a modalQ3FileDialog 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 tothis 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 withtwo semicolons, e.g.
"Images (*.png *.xpm *.jpg);;Text files (*.txt);;XML files (*.xml)"You can create your ownQ3FileDialog without using the static functions. By callingsetMode(), you can set what can be returned by theQ3FileDialog.
Q3FileDialog* fd=newQ3FileDialog(this,"file dialog",true);fd->setMode(Q3FileDialog::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 "File Save As" file dialog. UseExistingFile if the user must select an existing file orDirectory if only a directory may be selected. (See theQ3FileDialog::Mode enum for the complete list of modes.)
You can retrieve the dialog's mode withmode(). UsesetFilter() to set the dialog's file filter, e.g.
fd->setFilter("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 theQ3FileDialog. You can apply several filters by usingsetFilters() and add additional filters withaddFilter(). UsesetSelectedFilter() to select one of the filters you've given as the file dialog's default filter. Whenever the user changes the filter thefilterSelected() signal is emitted.
The file dialog has two view modes,Q3FileDialog::List which simply lists file and directory names andQ3FileDialog::Detail which displays additional information alongside each name, e.g. file size, modification date, etc. Set the mode withsetViewMode().
fd->setViewMode(Q3FileDialog::Detail);
The last important function you will need to use when creating your own file dialog isselectedFile().
QString fileName;if (fd->exec()==QDialog::Accepted) fileName= fd->selectedFile();
In the above example, a modal file dialog is created and shown. If the user clicked OK, then the file they selected is put infileName.
If you are using theExistingFiles mode then you will need to useselectedFiles() which will return the selected files in aQStringList.
The dialog's working directory can be set withsetDir(). The display of hidden files is controlled withsetShowHiddenFiles(). The dialog can be forced to re-read the directory withrereadDir() and re-sort the directory withresortDir(). All the files in the current directory can be selected withselectAll().
There are two kinds of preview widgets that can be used with Q3FileDialogs:content preview widgets andinformation preview widgets. They are created and used in the same way except that the function names differ, e.g.setContentsPreview() andsetInfoPreview().
A preview widget is a widget that is placed inside aQ3FileDialog so that the user can see either the contents of the file, or information about the file.
class Preview :publicQLabel,publicQ3FilePreview{public: Preview(QWidget*parent=0) :QLabel(parent) {}void previewUrl(constQ3Url&u) {QString path= u.path();QPixmap pix(path);if (pix.isNull()) setText("This is not a pixmap");else setPixmap(pix); }};
In the above snippet, we create a preview widget which inherits fromQLabel andQ3FilePreview. File preview widgetsmust inherit fromQ3FilePreview.
Inside the class we reimplementQ3FilePreview::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:
Preview* p=new Preview;Q3FileDialog* fd=newQ3FileDialog(this);fd->setContentsPreviewEnabled(true);fd->setContentsPreview(p, p);fd->setPreviewMode(Q3FileDialog::Contents);fd->show();
The first line creates an instance of our preview widget. We then create our file dialog and callsetContentsPreviewEnabled(true), this tell the file dialog to preview the contents of the currently selected file. We then callsetContentsPreview() -- note that we pass the same preview widget twice. Finally, before showing the file dialog, we callsetPreviewMode() setting the mode toContents which will show the contents preview of the file that the user has selected.
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 callsetInfoPreviewEnabled(), andsetInfoPreview(). Then the user will be able to switch between the two preview modes.
For more information about creating aQ3FilePreview widget seeQ3FilePreview.
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.
| Constant | Value | Description |
|---|---|---|
Q3FileDialog::AnyFile | 0 | The name of a file, whether it exists or not. |
Q3FileDialog::ExistingFile | 1 | The name of a single existing file. |
Q3FileDialog::Directory | 2 | The name of a directory. Both files and directories are displayed. |
Q3FileDialog::DirectoryOnly | 4 | The name of a directory. The file dialog will only display directories. |
Q3FileDialog::ExistingFiles | 3 | The names of zero or more existing files. |
SeesetMode().
This enum describes the preview mode of the file dialog.
| Constant | Value | Description |
|---|---|---|
Q3FileDialog::NoPreview | 0 | No preview is shown at all. |
Q3FileDialog::Contents | 1 | Show a preview of the contents of the current file using the contents preview widget. |
Q3FileDialog::Info | 2 | Show information about the current file using the info preview widget. |
SeesetPreviewMode(),setContentsPreview() andsetInfoPreview().
This enum describes the view mode of the file dialog, i.e. what information about each file will be displayed.
| Constant | Value | Description |
|---|---|---|
Q3FileDialog::List | 1 | Display file and directory names with icons. |
Q3FileDialog::Detail | 0 | Display file and directory names with icons plus additional information, such as file size and modification date. |
SeesetViewMode().
This property holds whether the file dialog can provide a contents preview of the currently selected file.
The default is false.
Access functions:
| bool | isContentsPreviewEnabled() const |
| void | setContentsPreviewEnabled(bool) |
See alsosetContentsPreview() andsetInfoPreviewEnabled().
This property holds the file dialog's working directory.
Access functions:
| QString | dirPath() const |
This property holds whether the file dialog can provide preview information about the currently selected file.
The default is false.
Access functions:
| bool | isInfoPreviewEnabled() const |
| void | setInfoPreviewEnabled(bool) |
This property holds the file dialog's mode.
The default mode isExistingFile.
Access functions:
| Mode | mode() const |
| void | setMode(Mode) |
This property holds the preview mode for the file dialog.
If you set the mode to be a mode other thanNoPreview, you must usesetInfoPreview() orsetContentsPreview() to set the dialog's preview widget to your preview widget and enable the preview widget(s) withsetInfoPreviewEnabled() orsetContentsPreviewEnabled().
Access functions:
| PreviewMode | previewMode() const |
| void | setPreviewMode(PreviewMode m) |
See alsoinfoPreview,contentsPreview, andviewMode.
This property holds the name of the selected file.
If a file was selected selectedFile contains the file's name including its absolute path; otherwise selectedFile is empty.
Access functions:
| QString | selectedFile() const |
See alsoQString::isEmpty(),selectedFiles, andselectedFilter.
This property holds the list of selected files.
If one or more files are selected, selectedFiles contains their names including their absolute paths. If no files are selected or the mode isn'tExistingFiles selectedFiles is an empty list.
It is more convenient to useselectedFile() if the mode isExistingFile,Directory orDirectoryOnly.
Note that if you want to iterate over the list, you should iterate over a copy, e.g.
QStringList list= myFileDialog.selectedFiles();QStringList::Iterator it= list.begin();while(it!= list.end()) { myProcessing(*it);++it;}
Access functions:
| QStringList | selectedFiles() const |
See alsoselectedFile,selectedFilter, andQList::isEmpty().
This property holds the filter which the user has selected in the file dialog.
Access functions:
| QString | selectedFilter() const |
See alsofilterSelected(),selectedFiles, andselectedFile.
This property holds whether hidden files are shown in the file dialog.
The default is false, i.e. don't show hidden files.
Access functions:
| bool | showHiddenFiles() const |
| void | setShowHiddenFiles(bool s) |
This property holds the file dialog's view mode.
If you set the view mode to beDetail (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.
If you set the view mode to beList, then you will just see a list of the files and folders.
Access functions:
| ViewMode | viewMode() const |
| void | setViewMode(ViewMode m) |
Constructs a file dialog calledname with the parent,parent. Ifmodal is true then the file dialog is modal; otherwise it is modeless.
IfdirName 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. Iffilter is specified it will be used as the dialog's file filter.
Constructs a file dialog calledname, with the parent,parent. Ifmodal is true then the file dialog is modal; otherwise it is modeless.
Destroys the file dialog.
Adds the filterfilter to the list of filters and makes it the current filter.
Q3FileDialog* fd=newQ3FileDialog(this);fd->addFilter("Images (*.png *.jpg *.xpm)");fd->show();
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.
See alsosetFilter() andsetFilters().
[protected]void Q3FileDialog::addLeftWidget(QWidget * w)Adds the widgetw to the left-hand side of the file dialog.
See alsoaddRightWidget(),addWidgets(), andaddToolButton().
[protected]void Q3FileDialog::addRightWidget(QWidget * w)Adds the widgetw to the right-hand side of the file dialog.
See alsoaddLeftWidget(),addWidgets(), andaddToolButton().
[protected]void Q3FileDialog::addToolButton(QAbstractButton * b,bool separator = false)Adds the tool buttonb to the row of tool buttons at the top of the file dialog. The button is appended to the right of this row. Ifseparator is true, a small space is inserted between the last button of the row and the new buttonb.
See alsoaddWidgets(),addLeftWidget(), andaddRightWidget().
[protected]void Q3FileDialog::addWidgets(QLabel * l,QWidget * w,QPushButton * b)Adds the specified widgets to the bottom of the file dialog. The labell is placed underneath the "file name" and the "file types" labels. The widgetw is placed underneath the file types combobox. The buttonb is placed underneath the Cancel push button.
MyFileDialog::MyFileDialog(QWidget* parent,constchar* name) :Q3FileDialog(parent, name){QLabel* label=newQLabel("Added widgets",this);QLineEdit* lineedit=newQLineEdit(this);QPushButton* pushbutton=newQPushButton(this); addWidgets(label, lineedit, pushbutton);}
If you don't want to have one of the widgets added, pass 0 in that widget's position.
Every time you call this function, a new row of widgets will be added to the bottom of the file dialog.
See alsoaddToolButton(),addLeftWidget(), andaddRightWidget().
Returns the current directory shown in the file dialog.
The ownership of theQDir pointer is transferred to the caller, so it must be deleted by the caller when no longer required.
See alsosetDir().
[signal]void Q3FileDialog::dirEntered(constQString & directory)This signal is emitted when the user enters the givendirectory.
See alsodir().
[virtual slot]void Q3FileDialog::done(int i)Reimplemented fromQDialog::done().
[virtual]bool Q3FileDialog::eventFilter(QObject * o,QEvent * e)Reimplemented fromQObject::eventFilter().
[signal]void Q3FileDialog::fileHighlighted(constQString & file)This signal is emitted when the user highlights the givenfile, i.e. makes it the current file.
Note:SignalfileHighlighted is overloaded in this class. To connect to this one using the function pointer syntax, you must specify the signal type in a static cast, as shown in this example:
connect(3FileDialog,static_cast<void(Q3FileDialog::*)(constQString&)>(&Q3FileDialog::fileHighlighted),[=](constQString&file){/* ... */ });
See alsofileSelected() andfilesSelected().
[signal]void Q3FileDialog::fileSelected(constQString & file)This signal is emitted when the user selects the givenfile.
Note:SignalfileSelected is overloaded in this class. To connect to this one using the function pointer syntax, you must specify the signal type in a static cast, as shown in this example:
connect(3FileDialog,static_cast<void(Q3FileDialog::*)(constQString&)>(&Q3FileDialog::fileSelected),[=](constQString&file){/* ... */ });
See alsofilesSelected(),fileHighlighted(), andselectedFile().
[signal]void Q3FileDialog::filesSelected(constQStringList & files)This signal is emitted when the user selects the givenfiles inExistingFiles mode.
See alsofileSelected(),fileHighlighted(), andselectedFiles().
[signal]void Q3FileDialog::filterSelected(constQString & filter)This signal is emitted when the user selects the givenfilter.
See alsoselectedFilter().
[static]QString Q3FileDialog::getExistingDirectory(constQString & dir = QString(),QWidget * parent = 0, constchar * name = 0, constQString & caption = QString(),bool dirOnly = true,bool resolveSymlinks = true)This is a convenience static function that will return an existing directory selected by the user.
QString s=Q3FileDialog::getExistingDirectory("/home",this,"get existing directory","Choose a directory",true);
This function creates a modal file dialog calledname, with parent,parent. If parent is not 0, the dialog will be shown centered over the parent.
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.
IfdirOnly is true, then only directories will be shown in the file dialog; otherwise both directories and files will be shown.
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. IfresolveSymlinks is false, the file dialog will treat symlinks as regular directories.
Note that 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 under the parent's title bar.
See alsogetOpenFileName(),getOpenFileNames(), andgetSaveFileName().
[static]QString Q3FileDialog::getOpenFileName(constQString & startWith = QString(), constQString & filter = QString(),QWidget * parent = 0, constchar * name = 0, constQString & caption = QString(),QString * selectedFilter = 0,bool resolveSymlinks = true)This is a convenience static function that returns an existing file selected by the user. If the user pressed Cancel, it returns a null string.
QString s=Q3FileDialog::getOpenFileName("/home","Images (*.png *.xpm *.jpg)",this,"open file dialog","Choose a file to open");
The function creates a modal file dialog calledname, with parent,parent. If a parent is not 0, the dialog will be shown centered over the parent.
The file dialog's working directory will be set tostartWith. IfstartWith 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 parametersstartWith,selectedFilter andfilter may be an empty string.
The dialog's caption is set tocaption. Ifcaption is not specified then a default caption will be used.
Under Windows and Mac OS X, this static function will use the native file dialog and not aQ3FileDialog, 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 QTimers and if parent is not 0 then it will position the dialog just under the parent's title bar).
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. IfresolveSymlinks is false, the file dialog will treat symlinks as regular directories.
See alsogetOpenFileNames(),getSaveFileName(), andgetExistingDirectory().
[static]QStringList Q3FileDialog::getOpenFileNames(constQString & filter = QString(), constQString & dir = QString(),QWidget * parent = 0, constchar * name = 0, constQString & caption = QString(),QString * selectedFilter = 0,bool resolveSymlinks = true)This is a convenience static function that will return one or more existing files selected by the user.
QStringList files=Q3FileDialog::getOpenFileNames("Images (*.png *.xpm *.jpg)","/home",this,"open files dialog","Select one or more files to open");
This function creates a modal file dialog calledname, with parentparent. Ifparent is not 0, the dialog will be shown centered over the parent.
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.
The dialog's caption is set tocaption. Ifcaption is not specified then a default caption will be used.
Under Windows and Mac OS X, this static function will use the native file dialog and not aQ3FileDialog, 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 QTimers and if parent is not 0 then it will position the dialog just under the parent's title bar).
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. IfresolveSymlinks is false, the file dialog will treat symlinks as regular directories.
Note that if you want to iterate over the list of files, you should iterate over a copy, e.g.
QStringList list= files;QStringList::Iterator it= list.begin();while(it!= list.end()) { myProcessing(*it);++it;}
See alsogetOpenFileName(),getSaveFileName(), andgetExistingDirectory().
[static]QString Q3FileDialog::getSaveFileName(constQString & startWith = QString(), constQString & filter = QString(),QWidget * parent = 0, constchar * name = 0, constQString & caption = QString(),QString * selectedFilter = 0,bool resolveSymlinks = true)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 calledname, with parent,parent. If a parent is not 0, the dialog will be shown centered over the parent.
QString s=Q3FileDialog::getSaveFileName("/home","Images (*.png *.xpm *.jpg)",this,"save file dialog","Choose a filename to save under");
The file dialog's working directory will be set tostartWith. IfstartWith 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 parametersstartWith,selectedFilter andfilter may be an empty string.
The dialog's caption is set tocaption. Ifcaption is not specified then a default caption will be used.
Under Windows and Mac OS X, this static function will use the native file dialog and not aQ3FileDialog, 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 QTimers and if parent is not 0 then it will position the dialog just under the parent's title bar. And on the Mac the filter argument is ignored).
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. IfresolveSymlinks is false, the file dialog will treat symlinks as regular directories.
See alsogetOpenFileName(),getOpenFileNames(), andgetExistingDirectory().
[static]Q3FileIconProvider * Q3FileDialog::iconProvider()Returns a pointer to the icon provider currently set on the file dialog. By default there is no icon provider, and this function returns 0.
See alsosetIconProvider() andQ3FileIconProvider.
[virtual protected]void Q3FileDialog::keyPressEvent(QKeyEvent * ke)Reimplemented fromQWidget::keyPressEvent().
Rereads the current directory shown in the file dialog.
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.
See alsoresortDir().
[virtual protected]void Q3FileDialog::resizeEvent(QResizeEvent * e)Reimplemented fromQWidget::resizeEvent().
Re-sorts the displayed directory.
See alsorereadDir().
Ifb is true then all the files in the current directory are selected; otherwise, they are deselected.
Sets the widget to be used for displaying the contents of the file to the widgetw and a preview of those contents to theQ3FilePreviewpreview.
Normally you would create a preview widget that derives from bothQWidget andQ3FilePreview, so you should pass the same widget twice.
class Preview :publicQLabel,publicQ3FilePreview{public: Preview(QWidget*parent=0) :QLabel(parent) {}void previewUrl(constQ3Url&u) {QString path= u.path();QPixmap pix(path);if (pix.isNull()) setText("This is not a pixmap");else setPixmap(pix); }};//...int main(int argc,char** argv){ Preview* p=new Preview;Q3FileDialog* fd=newQ3FileDialog(this); fd->setContentsPreviewEnabled(true); fd->setContentsPreview(p, p); fd->setPreviewMode(Q3FileDialog::Contents); fd->show();}
See alsosetContentsPreviewEnabled(),setInfoPreview(), andsetPreviewMode().
Sets the file dialog's working directory todir.
See alsodir().
[slot]void Q3FileDialog::setDir(constQString & pathstr)This is an overloaded function.
Sets the file dialog's working directory topathstr.
See alsodir().
[slot]void Q3FileDialog::setFilter(constQString & newFilter)Sets the filter used in the file dialog tonewFilter.
IfnewFilter contains a pair of parentheses containing one or more of "anything*something" separated by spaces or by semicolons then only the text contained in the parentheses is used as the filter. 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++");
See alsosetFilters().
[slot]void Q3FileDialog::setFilters(constQString & filters)Sets the filters used in the file dialog tofilters. Each group of filters must be separated by;; (two semicolons).
QString types("Image files (*.png *.xpm *.jpg);;""Text files (*.txt);;""Any files (*)");Q3FileDialog fd=newQ3FileDialog(this);fd->setFilters(types);fd->show();
[slot]void Q3FileDialog::setFilters(constchar ** types)This is an overloaded function.
types must be a null-terminated list of strings.
[slot]void Q3FileDialog::setFilters(constQStringList & types)This is an overloaded function.
types is a list of filter strings.
[static]void Q3FileDialog::setIconProvider(Q3FileIconProvider * provider)Sets theQ3FileIconProvider used by the file dialog toprovider.
The default is that there is noQ3FileIconProvider andQ3FileDialog just draws a folder icon next to each directory and nothing next to files.
See alsoQ3FileIconProvider andiconProvider().
Sets the widget to be used for displaying information about the file to the widgetw and a preview of that information to theQ3FilePreviewpreview.
Normally you would create a preview widget that derives from bothQWidget andQ3FilePreview, so you should pass the same widget twice.
class Preview :publicQLabel,publicQ3FilePreview{public: Preview(QWidget*parent=0) :QLabel(parent) {}void previewUrl(constQ3Url&u) {QString path= u.path();QPixmap pix(path);if (pix.isNull()) setText("This is not a pixmap");else setText("This is a pixmap"); }};//...int main(int argc,char** argv){ Preview* p=new Preview;Q3FileDialog* fd=newQ3FileDialog(this); fd->setInfoPreviewEnabled(true); fd->setInfoPreview(p, p); fd->setPreviewMode(Q3FileDialog::Info); fd->show();}
See alsosetContentsPreview(),setInfoPreviewEnabled(), andsetPreviewMode().
[virtual]void Q3FileDialog::setSelectedFilter(constQString & mask)Sets the current filter selected in the file dialog to the first one that contains the textmask.
See alsoselectedFilter().
[virtual]void Q3FileDialog::setSelectedFilter(int n)This is an overloaded function.
Sets the current filter selected in the file dialog to then-th filter in the filter list.
See alsofilterSelected(),selectedFilter(),selectedFiles(), andselectedFile().
Sets the default selection tofilename. Iffilename is absolute,setDir() is also called to set the file dialog's working directory to the filename's directory.
[slot]void Q3FileDialog::setUrl(constQ3UrlOperator & url)Sets the file dialog's working directory to the directory specified aturl.
See alsourl().
Returns the URL of the current working directory in the file dialog.
See alsosetUrl().
© 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.