Qt file dialog options




















You can set the DontUseNativeDialog option to ensure that the widget-based implementation will be used instead of the native dialog. This enum is used to indicate what the user may select in the file dialog; i.

It stores an OR combination of Option values. This enum describes the view mode of the file dialog; i. 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. The file mode defines the number and type of items that the user is expected to select in the dialog. It is possible to set custom text after the call to setFileMode.

Options particularly the DontUseNativeDialogs option should be set before changing dialog properties or showing the dialog. Setting options while the dialog is visible is not guaranteed to have an immediate effect on the dialog depending on the option and on the platform. See also setOption and testOption.

Setting this property allows to restrict the type of URLs the user will be able to select. It is a way for the application to declare the protocols it will support to fetch the file content.

An empty list means that no restriction is applied the default. Supported for local files "file" scheme is implicit and always enabled; it is not necessary to include it in the restriction. By default, the Detail mode is used to display information about files and directories.

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.

When the current file changes for local operations, this signal is emitted with the new file name as the path parameter. When the current file changes, this signal is emitted with the new file URL as the url parameter.

When the selection changes for local operations and the dialog is accepted, this signal is emitted with the possibly empty selected file. See also currentChanged and QDialog::Accepted. When the selection changes for local operations and the dialog is accepted, this signal is emitted with the possibly empty list of selected files.

When the selection changes and the dialog is accepted, this signal is emitted with the possibly empty selected url. When the selection changes and the dialog is accepted, this signal is emitted with the possibly empty list of selected urls.

This is a convenience static function that will return an existing directory selected by the user. This function creates a modal file dialog with the given parent widget. If parent is not nullptr , 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. To ensure a native file dialog, ShowDirsOnly must be set. However, the native Windows file dialog does not support displaying files in the directory chooser.

If options includes DontResolveSymlinks , the file dialog will treat symlinks as regular directories. On Windows, the dialog will spin a blocking modal event loop that will not dispatch any QTimers, and if parent is not nullptr then it will position the dialog just below the parent's title bar. Warning: Do not delete parent during the execution of the dialog. If you want to do this, you should create the dialog yourself using one of the QFileDialog constructors.

If the user presses Cancel, it returns an empty url. In particular parent , caption , dir and options are used in the exact same way. The main difference with QFileDialog::getExistingDirectory comes from the ability offered to the user to select a remote directory. That's why the return type and the type of dir is QUrl.

The supportedSchemes argument allows to restrict the type of URLs the user will be able to select. When possible, this static function will use the native file dialog and not a QFileDialog.

On platforms which don't support selecting remote files, Qt will allow to select only local files. This is a convenience static function that will return the content of a file selected by the user. This function is used to access local files on Qt for WebAssembly, where the web sandbox places restrictions on how such access may happen. If no files are selected, or the mode is not ExistingFiles or ExistingFile , selectedUrls contains the current path in the viewport.

See also selectedNameFilter and selectUrl. For this to be enabled, the Info. See Info. This feature was added in Qt 5. See also directoryUrl and QUuid. Sets the filter used by the model to filters. The filter is used to specify the kind of files that should be shown. Sets the item delegate used to render items in the views in the file dialog to the given delegate. Any existing delegate will be removed, but not deleted. QFileDialog does not take ownership of 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. Note that the model used is QFileSystemModel. It has custom item data roles, which is described by the Roles enum. You can use a QFileIconProvider if you only want custom icons.

Convenience method for setNameFilters. Calling setMimeTypeFilters overrides any previously set name filters, and changes the return value of nameFilters. If filter contains a pair of parentheses containing one or more filename-wildcard patterns, separated by spaces, then only the text contained in the parentheses is used as the filter. This means that these calls are all equivalent:. Note: With Android's native file dialog, the mime type matching the given name filter is used because only mime types are supported.

It is possible to have a file with no dot in its name for example, Makefile. Sets the given option to be enabled if on is true; otherwise, clears the given option. See also options and testOption. Sets the model for the views to the given proxyModel.

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 proxyModel. See also options and setOption. Documentation contributions included herein are the copyrights of their respective owners.

Qt and respective logos are trademarks of The Qt Company Ltd. All other trademarks are property of their respective owners. Detailed Description 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. QFileDialog dialog this ; dialog. QStringList fileNames; if dialog. QFileDialog::Directory 2 The name of a directory. Both files and directories are displayed.

By default both files and directories are shown. Valid only in the Directory file mode. By default symlinks are resolved.

By default confirmation is requested. Some platforms allow the user to set a different icon. Custom icon lookup cause a big performance impact over network or removable drives. This enum value was added in Qt 5. In this section, we've used Qt Designer in Edit Widgets mode, which is the default mode.

In this mode, we can add widgets to our dialogs, edit widget's properties, lay out the widgets on the dialog's GUI, and so on. To activate the Edit Widgets mode, we can choose any of the three following options:. An element that can improve the usability of your dialogs is the tab order of the input widgets.

The default tab order is based on the order in which you place the widgets on the form. This is a kind of annoying behavior. The following screencast shows the problem:. To fix this problem, we need to change the tab order of the input widgets on our dialog. In Edit Tab Order mode, each input widget in the form is shown with a number that indicates its position in the tab order chain.

We can change the tab order by clicking on the number of each widget in the correct order. You can see how to do this in the following screencast:. In this example, we change the tab order of the input widgets by clicking on each number in the correct order. When we select a number, it changes to red to indicate that this is the currently edited position in the tab order.

When we click on another number, then that number will be second in the tab order, and so on. In case of a mistake, we can restart numbering by choosing Restart from the form's context menu.

To partially edit the tab order, we can select a number with the Ctrl key pressed. The tab order will be changed from that widget on. We can also right-click on a given number and then choose Start from Here from the context menu.

In Qt, buddies are connections between related widgets. These connections allow you to provide a quick keyboard shortcut to move the focus to a given input widget. By setting buddies, you'll improve the usability of your dialogs because you'll provide the user with a fast way to move around dialogs and windows.

In our Annual salary QLabel , that letter could be A or s or any other letter in the text of the label. The only restriction is that the selected letter doesn't clash with the letter of any other buddy in the dialog or window at hand. With this addition, we provide the letter to use in the keyboard shortcut. Once we have selected the letters to use and placed the corresponding ampersands, we need to set the buddies.

To define the buddies, we'll click on a label and drag it over the corresponding input widget. The whole process is illustrated in the following screencast:. To create buddies between labels and input widgets, we can select a label with our mouse and drag it to the input widget that we want to set as its buddy.

The label and the input widget will become buddies. Note that the buddy letters will be underlined to point the right key combination to use. There is a standard set of buttons that you can use when it comes to creating dialogs.

Even though Qt Designer's templates provide an OK button and a Cancel button, in practice you'll see dialogs that use different buttons like Apply , Close , Yes , No , and so on. In our employee example, we've used a Cancel and an OK button, which were placed in that same order from left to right. This is the usual order for buttons on Linux or macOS but not for Windows, where the order should be swapped. If we want that our GUI applications look as native as possible on different platforms, then we'll need to deploy different dialogs for different platforms just to show the buttons in the right order for the platform at hand.

Fortunately, PyQt provides an effective solution for this particular problem. Instead of adding a Cancel and an OK button directly, we can use the QDialogButtonBox class and select the buttons according to our needs. This PyQt class will automatically handle the order of the buttons for us according to the standard practice on the underlying platform. Button Box on Windows. Button Box on Linux. Button Box on macOS. That's because Qt Designer's dialog templates use a QDialogButtonBox object by default to lay out the buttons on the dialog.

We can select the buttons that we want to show on our dialogs by changing the. Take a look at the following screencast:. The Property Editor allows us to set the. Note that when we change the buttons in the QDialogButtonBox , they get placed according to the standard practice on the current platform.

When an event occurs, the widget at hand emits a signal to let you know that the event has occurred. To give life to your applications, you need to connect those signals to specific slots. The default label is typically Open or Save depending on which fileMode the dialog is used in. Unlike the selectedFile property, the currentFile property is updated while the user is selecting files in the dialog, even before the final selection has been made.

See also selectedFile , currentFiles , and currentFolder. Unlike the selectedFiles property, the currentFiles property is updated while the user is selecting files in the dialog, even before the final selection has been made. See also selectedFiles , currentFile , and currentFolder. This property holds the folder where files are selected.

It can be set to control the initial directory that is shown when the dialog is opened. This property holds a suffix that is added to selected files that have no suffix specified. The suffix is typically used to indicate the file type e. Different platforms may restrict the files that can be selected in different ways.

For example, macOS will disable file entries that do not match the filters, whereas Windows will hide them. It is possible to have a file with no dot in its name for example, Makefile. See also selectedNameFilter. Options should be set before showing the dialog. Setting them while the dialog is visible is not guaranteed to have an immediate effect on the dialog depending on the option and on the platform.

The default label is typically Cancel. Unlike the currentFile property, the selectedFile property is not updated while the user is selecting files in the dialog, but only after the final selection has been made. That is, when the user has clicked OK to accept a file.



0コメント

  • 1000 / 1000