PDA

View Full Version : QFileDialog::getSaveFileName - would like to disable save button for read only folder



Rajesh.Rathod
28th December 2016, 12:40
Dear All,

I would like to disable file save dialog's save button if the current selected folder is read only folder, I mean I want read only folder indication the moment user selects folder on file save dialog.

Here is the code, I have written to show file save dialog...


// Show the SaveAs dialog
QString sessionNameStr = QFileDialog::getSaveFileName(
pParent,
("Save Session File"),
primarySessionPath,
("Sessions (*.sess)") );

This problem is on Mac OS (El Capitan)
I am using Qt 4.7.3.

Please suggest me a solution, if any one has any idea about it.

Overriding QFileDialog or writing some other custom class is the last option I would like to choose.

Thanks,

d_stranz
29th December 2016, 18:56
I don't think you can do this with the static QFileDialog::getSaveFileName() method. What you will probably have to do is implement a method that uses QFileDialog::exec() (i.e. just like you would for a normal QDialog-based modal dialog) and connect a slot to the QFileDialog::directoryEntered() signal. In that slot, you can check for read-only status for the directory and set a flag that disallows choosing a file from that directory.

I don't think you can get access to the buttons themselves, because Qt uses the native dialogs on each platform, and of course these are not Qt dialogs, just Qt wrappers around the native dialogs.

anda_skoa
30th December 2016, 11:19
I don't think you can get access to the buttons themselves, because Qt uses the native dialogs on each platform, and of course these are not Qt dialogs, just Qt wrappers around the native dialogs.

Generally true, but one can force non-native dialogs, i.e. use Qt built-in ones, see QFileDialog::DontUseNativeDialog

Cheers,
_

d_stranz
30th December 2016, 17:56
Generally true, but one can force non-native dialogs

Sure, but can you get access to the dialog buttons if you use a built-in Qt one? And what is the look and feel compared to a native dialog? I suppose if you wanted to manually search out the children and find the buttons you could do that, assuming they were implemented as QPushButton in the first place.

anda_skoa
31st December 2016, 08:45
Right, one would have to look for the buttons manually, but I am pretty sure the dialog would be using QDialogButtonBox so that should be trivial.

Cheers,
_

Rajesh.Rathod
2nd January 2017, 07:02
@anda_skoa & @d_stranz
Thank you very much for your inputs, I got the possible way from your suggestions and will use them according to my requirement.

Thanks,