# Using native file dialog for selecting files and folders

**URL:** <https://discourse.slicer.org/t/using-native-file-dialog-for-selecting-files-and-folders/17926>\
**Category:** Support\
**Created:** [June 1, 2021, 8:58pm UTC](https://discourse.slicer.org/t/using-native-file-dialog-for-selecting-files-and-folders/17926 "2021-06-01T20:58:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![tbillah](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/tbillah/32/4139_2.png) [@tbillah](https://discourse.slicer.org/u/tbillah)\
**Post date:** [June 1, 2021, 8:58pm UTC](https://discourse.slicer.org/t/using-native-file-dialog-for-selecting-files-and-folders/17926/1 "2021-06-01T20:58:31Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [June 2, 2021, 1:35pm UTC](https://discourse.slicer.org/t/using-native-file-dialog-for-selecting-files-and-folders/17926/2 "2021-06-02T13:35:52Z")

</div>

2 posts were merged into an existing topic: [Loading data in Slicer from terminal](https://discourse.slicer.org/t/loading-data-in-slicer-from-terminal/17912/5)

---

<div class="post-metadata">

**Author:** ![jamesobutler](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jamesobutler/32/7511_2.png) [@jamesobutler](https://discourse.slicer.org/u/jamesobutler)\
**Post date:** [June 2, 2021, 12:50pm UTC](https://discourse.slicer.org/t/using-native-file-dialog-for-selecting-files-and-folders/17926/3 "2021-06-02T12:50:51Z")

</div>

> [@Loading data in Slicer from terminal](https://discourse.slicer.org/t/loading-data-in-slicer-from-terminal/17912/6):
>
> I usually drag-and-drop data into the application window and hit Enter to open it.

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?

```auto
qfiledialog = qt.QFileDialog()
tuple_file_paths = qfiledialog.getOpenFileNames() # Select file(s)
directory = qfiledialog.getExistingDirectory() # Select directory

```

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [June 2, 2021, 1:39pm UTC](https://discourse.slicer.org/t/using-native-file-dialog-for-selecting-files-and-folders/17926/4 "2021-06-02T13:39:58Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![jamesobutler](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jamesobutler/32/7511_2.png) [@jamesobutler](https://discourse.slicer.org/u/jamesobutler)\
**Post date:** [June 4, 2021, 3:42pm UTC](https://discourse.slicer.org/t/using-native-file-dialog-for-selecting-files-and-folders/17926/5 "2021-06-04T15:42:15Z")

</div>

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](https://github.com/Slicer/Slicer/pull/5674).
