How to specify the QFileDialog :: getExistingDirectory () method?

Using the method / command:

OpenCreateDirectory() { QString Directory = QFileDialog::getExistingDirectory(this, tr("Choose Or Create Directory"), "/home", QFileDialog::DontResolveSymlinks); } 

I can create a new directory or select an existing one. Is there a way to disable the ability to create a new directory? Also, is there a way to disable the ability to select an existing directory?

More precisely: when I use the method above, a pop-up window appears in which I can create a new directory or open an existing directory. What I want to do is to restrict the method so that I can simply create a new directory without being able to simply open an existing directory or in another case, restrict this method so that I can simply open an existing directory without being able to create a new directory .

+4
source share
2 answers

You can prevent the creation of a new directory using the following options:

 QFileDialog::DontUseNativeDialog | QFileDialog::ReadOnly | QFileDialog::ShowDirsOnly 

ReadOnly options have no effect if you use your own dialogs, at least on Windows.


And to disable the selection of an existing directory, you can not.
But you can either add the name of the directory that will be created as a separate parameter, or check that the selected directory is not empty.
+3
source

Yes, you can add QFileDialog::ReadOnly options when creating a QFileDialog . So create it with:

 QString Directory = QFileDialog::getExistingDirectory(this, tr("Choose Or Create Directory"), "/home", QFileDialog::DontResolveSymlinks | QFileDialog::ReadOnly); 

The Create Directory button in the file dialog still exists, but you cannot create the directory. I have successfully used this feature on Ubuntu.

+3
source

Source: https://habr.com/ru/post/1400385/


All Articles