Question

I would like to save a file using QFileDialog::getSaveFileName without allowing to choose the path or at least hide folders. Reading the doc I tried to set QFileDialog::ShowDirsOnly as an option like this:

QString fileName = QFileDialog::getSaveFileName(this,
                                                tr("..."), path, tr("... (*.txt)"), 0, QFileDialog::ShowDirsOnly);

but it's not working or it's not what I want.

Is there a way to save a file without being able to seek a location in the system and using QFileDialog::getSaveFileName please? Or do I need to build my own QFileDialog where I will just write the name of the file?

I hope someone will understand my problem.

Was it helpful?

Solution

As indicated in the comment, you are looking for a bit specific behavior which is not quite a QFileDialog, albeit somewhat similar, admittedly.

I believe it is not possible to shrink this feature down from QFileDialog, so I would personally go for implementing my own input box with the required sanity check in the background.

The QFileDialog implementation might give some hint for such checks, but it is not vital to see the source code of it as these are relatively simple operations.

You could then provide warning and error messages with message box. That being said, it might be more beneficial for Qt 5 to consider QML for such operations.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top