1

I'm using QtQuick Dialogs 1.2 in Qt application over Linux and I want to restrict my FileDialog to just two paths specified by me. My FileDialog is something like that:

FileDialog {
    id: fileDialogExample
    title: qsTr("File Dialog example")
    nameFilters: [qsTr("Image files %1").arg("(*.jpg *.png)")]
    folder: '/home/user/Downloads'
}

I want my file dialog only accept jpg/png files and start in specified path, but can move only to /mnt. Is this possible with stock FileDialog in Qt Dialogs 1.2?

Juan Garcia
  • 843
  • 2
  • 11
  • 34

1 Answers1

0

Documentation does not mention allowing specific directories. What I have done in similar case was something like this:

FileDialog {
    onFolderChanged: {
        if (/* folder not allowed */)
            folder = /* closest allowed dir */  // does not do anything with stock FileDialog
    }
}

Unfortunately this does not work with stock FileDialog. I have been using custom component and I had full control of it. I think that it is not possible to do what you need with current FileDialog. Of course you can close the dialog when user opens unwanted folder and then reopen it with correct path but I would not recommend it.

Filip Hazubski
  • 1,668
  • 1
  • 17
  • 33