Using native file dialog for selecting files and folders

In fsleyes I can load data from the terminal:

fsleyes img1.nii.gz img2.nii.gz

Can I do a similar thing with Slicer? I am asking because it is a little difficult to navigate to my required directory from within the GUI.

2 posts were merged into an existing topic: Loading data in Slicer from terminal

Users from my group almost exclusively do this because they hate using the standard QFileDialog to navigate to directories. They much prefer using the native file explorer to find the files they want to load. @lassoan I’m assuming this behavior of using drag-and-drop is also a result of this similar preference to the native file dialog over the QFileDialog?

Could we change to the following which uses native file explorer?

qfiledialog = qt.QFileDialog()
tuple_file_paths = qfiledialog.getOpenFileNames()  # Select file(s)
directory = qfiledialog.getExistingDirectory()  # Select directory
1 Like

I agree that Qt’s own (non-native) QFileDialog is not nice. It still the same as 10 years ago, while native file dialogs have improved substantially.

In the past, there were concerns in the past about limitations of the native dialog (e.g., on Mac filtered out files are shown as gray instead of being hidden), but I think those have been fixed since then, and the native file dialogs have more advantages anyway. Qt internal file dialogs also allow adding custom widgets inside, such as “Copy” checkbox in DICOM import file selector, but I think these cases should be possible to address using alternative designs.

I’m in favor of replacing Qt internal file dialogs by native ones (either by using the static methods you mentioned above qt.QFileDialog.getOpenFileNames() or by removing the QFileDialog::DontUseNativeDialog flag), but we should do it consistently, switching to native dialogs everywhere.

@jamesobutler could you review QFileDialog usages in Slicer and CTK and send a pull request that switches them to use native dialogs?

Proposed usage of native dialogs instead of the Qt widget-based dialog has been posted at:
ENH: Improve directory and file selection by using native dialogs by jamesobutler · Pull Request #5674 · Slicer/Slicer · GitHub.

1 Like