Qt Jambi Home

com.trolltech.qt.gui
Class QFileDialog

java.lang.Object
  extended by com.trolltech.qt.QSignalEmitter
      extended by com.trolltech.qt.QtJambiObject
          extended by com.trolltech.qt.core.QObject
              extended by com.trolltech.qt.gui.QWidget
                  extended by com.trolltech.qt.gui.QDialog
                      extended by com.trolltech.qt.gui.QFileDialog
All Implemented Interfaces:
QPaintDeviceInterface, QtJambiInterface

public class QFileDialog
extends QDialog

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

The QFileDialog 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 a QFileDialog 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.

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

In the above example, a modal QFileDialog 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 to this, and the window title is set to "Open Image".

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

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

You can create your own QFileDialog without using the static functions. By calling setFileMode, 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 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 "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 QFileDialog::FileMode enum for the complete list of modes.

The fileMode property contains the mode of operation for the dialog; this indicates what types of objects the user is expected to select. Use setFilter to set the dialog's file filter. For example:

    dialog.setFilter(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 extension png, xpm, or jpg will be shown in the QFileDialog. You can apply several filters by using setFilters. Use selectFilter to select one of the filters you've given as the file dialog's default filter.

The file dialog has two view modes: List and Detail. 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 with setViewMode:

    dialog.setViewMode(QFileDialog::Detail);

The last important function you will need to use when creating your own file dialog is selectedFiles.

    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 in fileName.

The dialog's working directory can be set with setDirectory. Each file in the current directory can be selected using the selectFile function.

The Standard Dialogs example shows how to use QFileDialog as well as other built-in Qt dialogs.

See Also:
QDir, QFileInfo, QFile, QPrintDialog, QColorDialog, QFontDialog, Dialogs Example, Application Example

Nested Class Summary
static class QFileDialog.AcceptMode
          Press link for info on QFileDialog.AcceptMode
static class QFileDialog.DialogLabel
          Press link for info on QFileDialog.DialogLabel
static class 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.
static class QFileDialog.Filter
           
static class QFileDialog.Option
          Press link for info on QFileDialog.Option
static class QFileDialog.Options
          This QFlag class provides flags for the int enum.
static class QFileDialog.ViewMode
          This enum describes the view mode of the file dialog; i.e. what information about each file will be displayed.
 
Nested classes/interfaces inherited from class com.trolltech.qt.gui.QDialog
QDialog.DialogCode
 
Nested classes/interfaces inherited from class com.trolltech.qt.gui.QWidget
QWidget.RenderFlag, QWidget.RenderFlags
 
Nested classes/interfaces inherited from class com.trolltech.qt.QSignalEmitter
QSignalEmitter.AbstractSignal, QSignalEmitter.Signal0, QSignalEmitter.Signal1<A>, QSignalEmitter.Signal2<A,B>, QSignalEmitter.Signal3<A,B,C>, QSignalEmitter.Signal4<A,B,C,D>, QSignalEmitter.Signal5<A,B,C,D,E>, QSignalEmitter.Signal6<A,B,C,D,E,F>, QSignalEmitter.Signal7<A,B,C,D,E,F,G>, QSignalEmitter.Signal8<A,B,C,D,E,F,G,H>, QSignalEmitter.Signal9<A,B,C,D,E,F,G,H,I>
 
Field Summary
 QSignalEmitter.Signal1<java.lang.String> currentChanged
          When the current file changes, this signal is emitted with the new file name as the path parameter.
 QSignalEmitter.Signal1<java.lang.String> directoryEntered
          This signal is emitted when the user enters a directory.
 QSignalEmitter.Signal1<java.util.List<java.lang.String>> filesSelected
           
 QSignalEmitter.Signal1<java.lang.String> filterSelected
          This signal is emitted when the user selects a filter.
 
Fields inherited from class com.trolltech.qt.gui.QDialog
accepted, finished, rejected
 
Fields inherited from class com.trolltech.qt.gui.QWidget
customContextMenuRequested
 
Constructor Summary
QFileDialog()
          Equivalent to QFileDialog(0, QString(), QString(), QString()).
QFileDialog(QWidget parent)
          Equivalent to QFileDialog(parent, QString(), QString(), QString()).
QFileDialog(QWidget parent, Qt.WindowFlags f)
          Constructs a file dialog with the given parent and widget f.
QFileDialog(QWidget parent, java.lang.String caption)
          Equivalent to QFileDialog(parent, caption, QString(), QString()).
QFileDialog(QWidget parent, java.lang.String caption, java.lang.String directory)
          Equivalent to QFileDialog(parent, caption, directory, QString()).
QFileDialog(QWidget parent, java.lang.String caption, java.lang.String directory, java.lang.String filter)
          Constructs a file dialog with the given parent and caption that initially displays the contents of the specified directory.
 
Method Summary
 void accept()
          This function is reimplemented for internal reasons.
 QFileDialog.AcceptMode acceptMode()
          Returns the accept mode of the dialog.
protected  void changeEvent(QEvent e)
          This function is reimplemented for internal reasons.
 boolean confirmOverwrite()
          Returns whether the filedialog should ask before accepting a selected file, when the accept mode is AcceptSave.
 java.lang.String defaultSuffix()
          Returns suffix added to the filename if no other suffix was specified.
 QDir directory()
          Returns the directory currently being displayed in the dialog.
 void done(int result)
          This function is reimplemented for internal reasons.
 QFileDialog.FileMode fileMode()
          Returns the file mode of the dialog.
 java.util.List<java.lang.String> filters()
          Returns the file type filters that are in operation on this file dialog.
static QFileDialog fromNativePointer(QNativePointer nativePointer)
          This function returns the QFileDialog instance pointed to by nativePointer
static java.lang.String getExistingDirectory()
          Equivalent to getExistingDirectory(0, QString(), QString(), ShowDirsOnly).
static java.lang.String getExistingDirectory(QWidget parent)
          Equivalent to getExistingDirectory(parent, QString(), QString(), ShowDirsOnly).
static java.lang.String getExistingDirectory(QWidget parent, java.lang.String caption)
          Equivalent to getExistingDirectory(parent, caption, QString(), ShowDirsOnly).
static java.lang.String getExistingDirectory(QWidget parent, java.lang.String caption, java.lang.String dir)
          Equivalent to getExistingDirectory(parent, caption, dir, ShowDirsOnly).
static java.lang.String getExistingDirectory(QWidget parent, java.lang.String caption, java.lang.String dir, QFileDialog.Option... options)
          This is a convenience static function that will return an existing directory selected by the user.
static java.lang.String getExistingDirectory(QWidget parent, java.lang.String caption, java.lang.String dir, QFileDialog.Options options)
          This is a convenience static function that will return an existing directory selected by the user.
static java.lang.String getOpenFileName()
          This is an overloaded function provided for convenience.
static java.lang.String getOpenFileName(QWidget parent)
          This is an overloaded function provided for convenience.
static java.lang.String getOpenFileName(QWidget parent, java.lang.String caption)
          This is an overloaded function provided for convenience.
static java.lang.String getOpenFileName(QWidget parent, java.lang.String caption, java.lang.String dir)
          This is an overloaded function provided for convenience.
static java.lang.String getOpenFileName(QWidget parent, java.lang.String caption, java.lang.String dir, QFileDialog.Filter filter)
          This is an overloaded function provided for convenience.
static java.lang.String getOpenFileName(QWidget parent, java.lang.String caption, java.lang.String dir, QFileDialog.Filter filter, QFileDialog.Option... options)
          This is an overloaded function provided for convenience.
static java.lang.String getOpenFileName(QWidget parent, java.lang.String caption, java.lang.String dir, QFileDialog.Filter filter, QFileDialog.Options options)
          This is a convenience static function that returns an existing file selected by the user.
static java.util.List<java.lang.String> getOpenFileNames()
          This is an overloaded function provided for convenience.
static java.util.List<java.lang.String> getOpenFileNames(QWidget parent)
          This is an overloaded function provided for convenience.
static java.util.List<java.lang.String> getOpenFileNames(QWidget parent, java.lang.String caption)
          This is an overloaded function provided for convenience.
static java.util.List<java.lang.String> getOpenFileNames(QWidget parent, java.lang.String caption, java.lang.String dir)
          This is an overloaded function provided for convenience.
static java.util.List<java.lang.String> getOpenFileNames(QWidget parent, java.lang.String caption, java.lang.String dir, QFileDialog.Filter filter)
          This is an overloaded function provided for convenience.
static java.util.List<java.lang.String> getOpenFileNames(QWidget parent, java.lang.String caption, java.lang.String dir, QFileDialog.Filter filter, QFileDialog.Option... options)
          This is an overloaded function provided for convenience.
static java.util.List<java.lang.String> getOpenFileNames(QWidget parent, java.lang.String caption, java.lang.String dir, QFileDialog.Filter filter, QFileDialog.Options options)
          This is a convenience static function that will return one or more existing files selected by the user.
static java.lang.String getSaveFileName()
          This is an overloaded function provided for convenience.
static java.lang.String getSaveFileName(QWidget parent)
          This is an overloaded function provided for convenience.
static java.lang.String getSaveFileName(QWidget parent, java.lang.String caption)
          This is an overloaded function provided for convenience.
static java.lang.String getSaveFileName(QWidget parent, java.lang.String caption, java.lang.String dir)
          This is an overloaded function provided for convenience.
static java.lang.String getSaveFileName(QWidget parent, java.lang.String caption, java.lang.String dir, QFileDialog.Filter filter)
          This is an overloaded function provided for convenience.
static java.lang.String getSaveFileName(QWidget parent, java.lang.String caption, java.lang.String dir, QFileDialog.Filter filter, QFileDialog.Option... options)
          This is an overloaded function provided for convenience.
static java.lang.String getSaveFileName(QWidget parent, java.lang.String caption, java.lang.String dir, QFileDialog.Filter filter, QFileDialog.Options options)
          This is a convenience static function that will return a file name selected by the user.
 java.util.List<java.lang.String> history()
          returns the browsing history of the filedialog as a list of paths.
 QFileIconProvider iconProvider()
          returns the icon provider used by the filedialog.
 boolean isReadOnly()
          Returns Whether the filedialog is readonly..
 QAbstractItemDelegate itemDelegate()
          returns the item delegate used to render the items in the views in the filedialog
 java.lang.String labelText(QFileDialog.DialogLabel label)
          returns the text shown in the filedialog in the specified label
 QAbstractProxyModel proxyModel()
          Returns the proxy model used by the file dialog.
 boolean resolveSymlinks()
          Returns whether the filedialog should resolve shortcuts.
 boolean restoreState(QByteArray state)
          Restores the dialogs's layout, history and current directory to the state specified.
 QByteArray saveState()
          Saves the state of the dialog's layout, history and current directory.
 java.util.List<java.lang.String> selectedFiles()
          Returns a list of strings containing the absolute paths of the selected files in the dialog.
 java.lang.String selectedFilter()
          Returns the filter that the user selected in the file dialog.
 void selectFile(java.lang.String filename)
          Selects the given filename in the file dialog.
 void selectFilter(java.lang.String filter)
          Sets the current file type filter.
 void setAcceptMode(QFileDialog.AcceptMode mode)
          Sets the accept mode of the dialog to mode.
 void setConfirmOverwrite(boolean enabled)
          Sets whether the filedialog should ask before accepting a selected file, when the accept mode is AcceptSave to enabled.
 void setDefaultSuffix(java.lang.String suffix)
          Sets suffix added to the filename if no other suffix was specified to suffix.
 void setDirectory(QDir directory)
          Set the current directory of this QFileDialog to directory.
 void setDirectory(java.lang.String directory)
          Sets the file dialog's current directory.
 void setFileMode(QFileDialog.FileMode mode)
          Sets the file mode of the dialog to mode.
 void setFilter(java.lang.String filter)
          Sets the filter used in the file dialog to the given filter.
 void setFilters(java.util.List<java.lang.String> filters)
          Sets the filters used in the file dialog.
 void setHistory(java.util.List<java.lang.String> paths)
          Sets the browsing history of the filedialog to contain the given paths.
 void setIconProvider(QFileIconProvider provider)
          set the icon provider used by the filedialog to the specified provider
 void setItemDelegate(QAbstractItemDelegate delegate)
          Sets the item delegate used to render items in the views in the file dialog to the given delegate.
 void setLabelText(QFileDialog.DialogLabel label, java.lang.String text)
          set the text shown in the filedialog in the specified label
 void setProxyModel(QAbstractProxyModel model)
          Sets the model for the views to the given model.
 void setReadOnly(boolean enabled)
          Sets Whether the filedialog is readonly. to enabled.
 void setResolveSymlinks(boolean enabled)
          Sets whether the filedialog should resolve shortcuts to enabled.
 void setSidebarUrls(java.util.List<QUrl> urls)
          Sets the urls that are located in the sidebar
 void setViewMode(QFileDialog.ViewMode mode)
          Sets the way files and directories are displayed in the dialog to mode.
 java.util.List<QUrl> sidebarUrls()
          Returns a list of urls that are currently in the sidebar
 QFileDialog.ViewMode viewMode()
          Returns the way files and directories are displayed in the dialog.
 
Methods inherited from class com.trolltech.qt.gui.QDialog
adjustPosition, closeEvent, contextMenuEvent, eventFilter, exec, isSizeGripEnabled, keyPressEvent, minimumSizeHint, reject, resizeEvent, result, setModal, setResult, setSizeGripEnabled, setVisible, showEvent, sizeHint
 
Methods inherited from class com.trolltech.qt.gui.QWidget
acceptDrops, accessibleDescription, accessibleName, actionEvent, actions, activateWindow, addAction, addActions, adjustSize, autoFillBackground, backgroundRole, baseSize, childAt, childAt, childrenRect, childrenRegion, clearFocus, clearMask, close, contentsRect, contextMenuPolicy, createWinId, cursor, depth, destroy, destroy, destroy, devType, dragEnterEvent, dragLeaveEvent, dragMoveEvent, dropEvent, ensurePolished, enterEvent, event, focusInEvent, focusNextChild, focusNextPrevChild, focusOutEvent, focusPolicy, focusPreviousChild, focusProxy, focusWidget, font, fontInfo, fontMetrics, foregroundRole, frameGeometry, frameSize, geometry, getContentsMargins, grabKeyboard, grabMouse, grabMouse, grabShortcut, grabShortcut, hasFocus, hasMouseTracking, height, heightForWidth, heightMM, hide, hideEvent, inputContext, inputMethodEvent, inputMethodQuery, insertAction, insertActions, isActiveWindow, isAncestorOf, isEnabled, isEnabledTo, isFullScreen, isHidden, isLeftToRight, isMaximized, isMinimized, isModal, isRightToLeft, isVisible, isVisibleTo, isWindow, isWindowModified, keyboardGrabber, keyReleaseEvent, layout, layoutDirection, leaveEvent, locale, logicalDpiX, logicalDpiY, lower, mapFrom, mapFromGlobal, mapFromParent, mapTo, mapToGlobal, mapToParent, mask, maximumHeight, maximumSize, maximumWidth, metric, minimumHeight, minimumSize, minimumWidth, mouseDoubleClickEvent, mouseGrabber, mouseMoveEvent, mousePressEvent, mouseReleaseEvent, move, move, moveEvent, nextInFocusChain, normalGeometry, numColors, overrideWindowFlags, overrideWindowFlags, overrideWindowState, overrideWindowState, paintEngine, paintEvent, paintingActive, palette, parentWidget, physicalDpiX, physicalDpiY, pos, raise, rect, releaseKeyboard, releaseMouse, releaseShortcut, removeAction, render, render, render, render, render, repaint, repaint, repaint, repaint, resetInputContext, resize, resize, restoreGeometry, saveGeometry, scroll, scroll, setAcceptDrops, setAccessibleDescription, setAccessibleName, setAttribute, setAttribute, setAutoFillBackground, setBackgroundRole, setBaseSize, setBaseSize, setContentsMargins, setContentsMargins, setContextMenuPolicy, setCursor, setDisabled, setEnabled, setFixedHeight, setFixedSize, setFixedSize, setFixedWidth, setFocus, setFocus, setFocusPolicy, setFocusProxy, setFont, setForegroundRole, setGeometry, setGeometry, setHidden, setInputContext, setLayout, setLayoutDirection, setLocale, setMask, setMask, setMaximumHeight, setMaximumSize, setMaximumSize, setMaximumWidth, setMinimumHeight, setMinimumSize, setMinimumSize, setMinimumWidth, setMouseTracking, setPalette, setParent, setParent, setParent, setShortcutAutoRepeat, setShortcutAutoRepeat, setShortcutEnabled, setShortcutEnabled, setSizeIncrement, setSizeIncrement, setSizePolicy, setSizePolicy, setStatusTip, setStyle, setStyleSheet, setTabOrder, setToolTip, setUpdatesEnabled, setWhatsThis, setWindowFlags, setWindowFlags, setWindowIcon, setWindowIconText, setWindowModality, setWindowModified, setWindowOpacity, setWindowRole, setWindowState, setWindowState, setWindowTitle, show, showFullScreen, showMaximized, showMinimized, showNormal, size, sizeIncrement, sizePolicy, stackUnder, statusTip, style, styleSheet, tabletEvent, testAttribute, toolTip, underMouse, unsetCursor, unsetLayoutDirection, unsetLocale, update, update, update, update, updateGeometry, updateMicroFocus, updatesEnabled, visibleRegion, whatsThis, wheelEvent, width, widthMM, window, windowFlags, windowIcon, windowIconText, windowModality, windowOpacity, windowRole, windowState, windowTitle, windowType, winId, x, y
 
Methods inherited from class com.trolltech.qt.core.QObject
blockSignals, childEvent, children, connectSlotsByName, customEvent, disposeLater, dumpObjectInfo, dumpObjectTree, dynamicPropertyNames, findChild, findChild, findChild, findChildren, findChildren, findChildren, findChildren, installEventFilter, isWidgetType, killTimer, moveToThread, objectName, parent, property, removeEventFilter, setObjectName, setParent, setProperty, signalsBlocked, startTimer, thread, timerEvent
 
Methods inherited from class com.trolltech.qt.QtJambiObject
dispose, disposed, finalize, reassignNativeResources, tr, tr, tr
 
Methods inherited from class com.trolltech.qt.QSignalEmitter
disconnect, disconnect, signalSender
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.trolltech.qt.QtJambiInterface
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership
 

Field Detail

currentChanged

public final QSignalEmitter.Signal1<java.lang.String> currentChanged

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

Compatible Slot Signatures:
void mySlot(java.lang.String path)
void mySlot()
See Also:
filesSelected


directoryEntered

public final QSignalEmitter.Signal1<java.lang.String> directoryEntered

This signal is emitted when the user enters a directory.

Compatible Slot Signatures:
void mySlot(java.lang.String directory)
void mySlot()


filesSelected

public final QSignalEmitter.Signal1<java.util.List<java.lang.String>> filesSelected

filterSelected

public final QSignalEmitter.Signal1<java.lang.String> filterSelected

This signal is emitted when the user selects a filter.

Compatible Slot Signatures:
void mySlot(java.lang.String filter)
void mySlot()

Constructor Detail

QFileDialog

public QFileDialog(QWidget parent,
                   Qt.WindowFlags f)

Constructs a file dialog with the given parent and widget f.


QFileDialog

public QFileDialog(QWidget parent,
                   java.lang.String caption,
                   java.lang.String directory)

Equivalent to QFileDialog(parent, caption, directory, QString()).


QFileDialog

public QFileDialog(QWidget parent,
                   java.lang.String caption)

Equivalent to QFileDialog(parent, caption, QString(), QString()).


QFileDialog

public QFileDialog(QWidget parent)

Equivalent to QFileDialog(parent, QString(), QString(), QString()).


QFileDialog

public QFileDialog()

Equivalent to QFileDialog(0, QString(), QString(), QString()).


QFileDialog

public QFileDialog(QWidget parent,
                   java.lang.String caption,
                   java.lang.String directory,
                   java.lang.String filter)

Constructs a file dialog with the given 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.

Method Detail

acceptMode

public final QFileDialog.AcceptMode acceptMode()

Returns the accept mode of the dialog.

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

See Also:
setAcceptMode, AcceptMode

confirmOverwrite

public final boolean confirmOverwrite()

Returns whether the filedialog should ask before accepting a selected file, when the accept mode is AcceptSave.

If this property is set to true and the accept mode is AcceptSave, the filedialog will ask whether the user wants to overwrite the file before accepting the file.

See Also:
setConfirmOverwrite

defaultSuffix

public final java.lang.String defaultSuffix()

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

See Also:
setDefaultSuffix

directory

public final QDir directory()

Returns the directory currently being displayed in the dialog.

See Also:
setDirectory

fileMode

public final QFileDialog.FileMode fileMode()

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

See Also:
setFileMode, FileMode

filters

public final java.util.List<java.lang.String> filters()

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

See Also:
setFilters

history

public final java.util.List<java.lang.String> history()

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

See Also:
setHistory

iconProvider

public final QFileIconProvider iconProvider()

returns the icon provider used by the filedialog.

See Also:
setIconProvider

isReadOnly

public final boolean isReadOnly()

Returns Whether the filedialog is readonly..

If this property is set to false, the filedialog will allow renaming, and deleting of files and directories and creating directories.

The default value is false.


itemDelegate

public final QAbstractItemDelegate itemDelegate()

returns the item delegate used to render the items in the views in the filedialog

See Also:
setItemDelegate

labelText

public final java.lang.String labelText(QFileDialog.DialogLabel label)

returns the text shown in the filedialog in the specified label

See Also:
setLabelText

proxyModel

public final QAbstractProxyModel proxyModel()

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

See Also:
setProxyModel

resolveSymlinks

public final boolean resolveSymlinks()

Returns whether the filedialog should resolve shortcuts.

If this property is set to true, the file dialog will resolve shortcuts.

See Also:
setResolveSymlinks

restoreState

public final boolean restoreState(QByteArray state)

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

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

Returns false if there are errors


saveState

public final QByteArray saveState()

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

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


selectFile

public final void selectFile(java.lang.String filename)

Selects the given filename in the file dialog.

See Also:
selectedFiles

selectFilter

public final void selectFilter(java.lang.String filter)

Sets the current file type filter. Multiple filters can be passed in filter by separating them with semicolons or spaces.

See Also:
setFilter, setFilters, selectedFilter

selectedFiles

public final java.util.List<java.lang.String> selectedFiles()

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, selectedFiles is an empty string list.

See Also:
selectedFilter, selectFile

selectedFilter

public final java.lang.String selectedFilter()

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

See Also:
selectedFiles

setAcceptMode

public final void setAcceptMode(QFileDialog.AcceptMode mode)

Sets the accept mode of the dialog to mode.

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

See Also:
acceptMode, AcceptMode

setConfirmOverwrite

public final void setConfirmOverwrite(boolean enabled)

Sets whether the filedialog should ask before accepting a selected file, when the accept mode is AcceptSave to enabled.

If this property is set to true and the accept mode is AcceptSave, the filedialog will ask whether the user wants to overwrite the file before accepting the file.

See Also:
confirmOverwrite

setDefaultSuffix

public final void setDefaultSuffix(java.lang.String suffix)

Sets suffix added to the filename if no other suffix was specified to suffix.

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

See Also:
defaultSuffix

setDirectory

public final void setDirectory(QDir directory)
Set the current directory of this QFileDialog to directory.


setDirectory

public final void setDirectory(java.lang.String directory)

Sets the file dialog's current directory.


setFileMode

public final void setFileMode(QFileDialog.FileMode mode)

Sets the file mode of the dialog to mode.

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

See Also:
fileMode, FileMode

setFilter

public final void setFilter(java.lang.String filter)

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

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

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

See Also:
setFilters

setFilters

public final void setFilters(java.util.List<java.lang.String> filters)

Sets the filters used in the file dialog.

    QStringList filters;
    filters << "Image files (*.png *.xpm *.jpg)"
            << "Text files (*.txt)"
            << "Any files (*)";

    QFileDialog dialog(this);
    dialog.setFilters(filters);
    dialog.exec();

See Also:
filters

setHistory

public final void setHistory(java.util.List<java.lang.String> paths)

Sets the browsing history of the filedialog to contain the given paths.

See Also:
history

setIconProvider

public final void setIconProvider(QFileIconProvider provider)

set the icon provider used by the filedialog to the specified provider

See Also:
iconProvider

setItemDelegate

public final void setItemDelegate(QAbstractItemDelegate delegate)

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

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 the closeEditor() signal, and attempt to access, modify or close an editor that has already been closed.

See Also:
itemDelegate

setLabelText

public final void setLabelText(QFileDialog.DialogLabel label,
                               java.lang.String text)

set the text shown in the filedialog in the specified label

See Also:
labelText

setProxyModel

public final void setProxyModel(QAbstractProxyModel model)

Sets the model for the views to the given model. 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 the model.

See Also:
proxyModel

setReadOnly

public final void setReadOnly(boolean enabled)

Sets Whether the filedialog is readonly. to enabled.

If this property is set to false, the filedialog will allow renaming, and deleting of files and directories and creating directories.

The default value is false.

See Also:
isReadOnly

setResolveSymlinks

public final void setResolveSymlinks(boolean enabled)

Sets whether the filedialog should resolve shortcuts to enabled.

If this property is set to true, the file dialog will resolve shortcuts.

See Also:
resolveSymlinks

setSidebarUrls

public final void setSidebarUrls(java.util.List<QUrl> urls)

Sets the urls that are located in the sidebar

See Also:
sidebarUrls

setViewMode

public final void setViewMode(QFileDialog.ViewMode mode)

Sets the way files and directories are displayed in the dialog to mode.

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

See Also:
viewMode, ViewMode

sidebarUrls

public final java.util.List<QUrl> sidebarUrls()

Returns a list of urls that are currently in the sidebar

See Also:
setSidebarUrls

viewMode

public final QFileDialog.ViewMode viewMode()

Returns the way files and directories are displayed in the dialog.

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

See Also:
setViewMode, ViewMode

accept

public void accept()

This function is reimplemented for internal reasons.

Overrides:
accept in class QDialog
See Also:
reject, done

changeEvent

protected void changeEvent(QEvent e)

This function is reimplemented for internal reasons.

Overrides:
changeEvent in class QWidget

done

public void done(int result)

This function is reimplemented for internal reasons.

Overrides:
done in class QDialog
See Also:
accept, reject, QApplication::activeWindow, QApplication::quit

getExistingDirectory

public static java.lang.String getExistingDirectory(QWidget parent,
                                                    java.lang.String caption,
                                                    java.lang.String dir,
                                                    QFileDialog.Option... options)

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 given parent widget. If the parent is not 0, the dialog will be shown centered over the parent 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 argument holds various options about how to run the dialog, see the QFileDialog::Option enum for more information on the flags you can pass.

Under Windows and Mac OS X, this static function will use the native file dialog and not a QFileDialog. On Mac OS X, the dir argument is ignored, the native dialog always displays the last visited directory.

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 options includes DontResolveSymlinks, 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 Also:
getOpenFileName, getOpenFileNames, getSaveFileName

getExistingDirectory

public static java.lang.String getExistingDirectory(QWidget parent,
                                                    java.lang.String caption,
                                                    java.lang.String dir)

Equivalent to getExistingDirectory(parent, caption, dir, ShowDirsOnly).


getExistingDirectory

public static java.lang.String getExistingDirectory(QWidget parent,
                                                    java.lang.String caption)

Equivalent to getExistingDirectory(parent, caption, QString(), ShowDirsOnly).


getExistingDirectory

public static java.lang.String getExistingDirectory(QWidget parent)

Equivalent to getExistingDirectory(parent, QString(), QString(), ShowDirsOnly).


getExistingDirectory

public static java.lang.String getExistingDirectory()

Equivalent to getExistingDirectory(0, QString(), QString(), ShowDirsOnly).


getExistingDirectory

public static java.lang.String getExistingDirectory(QWidget parent,
                                                    java.lang.String caption,
                                                    java.lang.String dir,
                                                    QFileDialog.Options options)

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 given parent widget. If the parent is not 0, the dialog will be shown centered over the parent 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 argument holds various options about how to run the dialog, see the QFileDialog::Option enum for more information on the flags you can pass.

Under Windows and Mac OS X, this static function will use the native file dialog and not a QFileDialog. On Mac OS X, the dir argument is ignored, the native dialog always displays the last visited directory.

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 options includes DontResolveSymlinks, 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 Also:
getOpenFileName, getOpenFileNames, getSaveFileName

fromNativePointer

public static QFileDialog fromNativePointer(QNativePointer nativePointer)
This function returns the QFileDialog instance pointed to by nativePointer

Parameters:
nativePointer - the QNativePointer of which object should be returned.

getOpenFileName

public static java.lang.String getOpenFileName(QWidget parent,
                                               java.lang.String caption,
                                               java.lang.String dir,
                                               QFileDialog.Filter filter,
                                               QFileDialog.Options options)
This is a convenience static function that returns an existing file selected by the user. If the user presses Cancel, it returns null.

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

The file dialog's working directory will be set to dir. If dir includes a file name, the file will be selected. Only files that match the given filter are shown. The parameter dir can be an empty string. The options argument holds various options about how to run the dialog, see the QFileDialog. Option enum for more information on the flags you can pass.

The dialog's caption is set to caption. If caption 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 a QFileDialog. On Mac OS X, the dir argument is ignored, the native dialog always displays the last visited directory.

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 \c{/usr/tmp} is a symlink to \c{/var/tmp}, the file dialog will change to \c{/var/tmp} after entering \c{/usr/tmp}. If options includes DontResolveSymlinks, the file dialog will treat symlinks as regular directories.


getOpenFileName

public static java.lang.String getOpenFileName(QWidget parent,
                                               java.lang.String caption,
                                               java.lang.String dir,
                                               QFileDialog.Filter filter,
                                               QFileDialog.Option... options)
This is an overloaded function provided for convenience.


getOpenFileName

public static java.lang.String getOpenFileName(QWidget parent,
                                               java.lang.String caption,
                                               java.lang.String dir,
                                               QFileDialog.Filter filter)
This is an overloaded function provided for convenience.


getOpenFileName

public static java.lang.String getOpenFileName(QWidget parent,
                                               java.lang.String caption,
                                               java.lang.String dir)
This is an overloaded function provided for convenience.


getOpenFileName

public static java.lang.String getOpenFileName(QWidget parent,
                                               java.lang.String caption)
This is an overloaded function provided for convenience.


getOpenFileName

public static java.lang.String getOpenFileName(QWidget parent)
This is an overloaded function provided for convenience.


getOpenFileName

public static java.lang.String getOpenFileName()
This is an overloaded function provided for convenience.


getOpenFileNames

public static java.util.List<java.lang.String> getOpenFileNames(QWidget parent,
                                                                java.lang.String caption,
                                                                java.lang.String dir,
                                                                QFileDialog.Filter filter,
                                                                QFileDialog.Options options)
This is a convenience static function that will return one or more existing files selected by the user.

This function creates a modal file dialog with the given parent widget. If the parent is not null, the dialog will be shown centered over the parent widget.

The file dialog's working directory will be set to dir. If 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. The parameters dir parameter may be an empty string.

The dialog's caption is set to caption. If caption 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 a QFileDialog. On Mac OS X, the dir argument is ignored, the native dialog always displays the last visited directory.

Note that on Windows the dialog will spin a blocking modal event loop that will not dispatch any QTimers, and if parent is not null 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. The options argument holds various options about how to run the dialog, see the QFileDialog.Option enum for more information on the flags you can pass.

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


getOpenFileNames

public static java.util.List<java.lang.String> getOpenFileNames(QWidget parent,
                                                                java.lang.String caption,
                                                                java.lang.String dir,
                                                                QFileDialog.Filter filter,
                                                                QFileDialog.Option... options)
This is an overloaded function provided for convenience.


getOpenFileNames

public static java.util.List<java.lang.String> getOpenFileNames(QWidget parent,
                                                                java.lang.String caption,
                                                                java.lang.String dir,
                                                                QFileDialog.Filter filter)
This is an overloaded function provided for convenience.


getOpenFileNames

public static java.util.List<java.lang.String> getOpenFileNames(QWidget parent,
                                                                java.lang.String caption,
                                                                java.lang.String dir)
This is an overloaded function provided for convenience.


getOpenFileNames

public static java.util.List<java.lang.String> getOpenFileNames(QWidget parent,
                                                                java.lang.String caption)
This is an overloaded function provided for convenience.


getOpenFileNames

public static java.util.List<java.lang.String> getOpenFileNames(QWidget parent)
This is an overloaded function provided for convenience.


getOpenFileNames

public static java.util.List<java.lang.String> getOpenFileNames()
This is an overloaded function provided for convenience.


getSaveFileName

public static java.lang.String getSaveFileName(QWidget parent,
                                               java.lang.String caption,
                                               java.lang.String dir,
                                               QFileDialog.Filter filter,
                                               QFileDialog.Options options)
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 given parent widget. If the parent is not null, the dialog will be shown centered over the parent widget.

The file dialog's working directory will be set to dir. If dir includes a file name, the file will be selected. Only files that match the filter are shown. The parameter dir may be an empty string. The options argument holds various options about how to run the dialog, see the QFileDialog.Option enum for more information on the flags you can pass.

The dialog's caption is set to caption. If caption 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 a QFileDialog.

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. On Mac OS X, the filter argument is ignored.

Under Unix/X11, the normal behavior of the file dialog is to resolve and follow symlinks. For example, if \c{/usr/tmp} is a symlink to /var/tmp, the file dialog will change to /var/tmp after entering /usr/tmp. If options includes DontResolveSymlinks, the file dialog will treat symlinks as regular directories.


getSaveFileName

public static java.lang.String getSaveFileName(QWidget parent,
                                               java.lang.String caption,
                                               java.lang.String dir,
                                               QFileDialog.Filter filter,
                                               QFileDialog.Option... options)
This is an overloaded function provided for convenience.


getSaveFileName

public static java.lang.String getSaveFileName(QWidget parent,
                                               java.lang.String caption,
                                               java.lang.String dir,
                                               QFileDialog.Filter filter)
This is an overloaded function provided for convenience.


getSaveFileName

public static java.lang.String getSaveFileName(QWidget parent,
                                               java.lang.String caption,
                                               java.lang.String dir)
This is an overloaded function provided for convenience.


getSaveFileName

public static java.lang.String getSaveFileName(QWidget parent,
                                               java.lang.String caption)
This is an overloaded function provided for convenience.


getSaveFileName

public static java.lang.String getSaveFileName(QWidget parent)
This is an overloaded function provided for convenience.


getSaveFileName

public static java.lang.String getSaveFileName()
This is an overloaded function provided for convenience.


Qt Jambi Home