Results 1 to 6 of 6

Thread: QFileDialog::getSaveFileName - would like to disable save button for read only folder

  1. #1
    Join Date
    Apr 2012
    Location
    India.
    Posts
    88
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default QFileDialog::getSaveFileName - would like to disable save button for read only folder

    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...

    Qt Code:
    1. // Show the SaveAs dialog
    2. QString sessionNameStr = QFileDialog::getSaveFileName(
    3. pParent,
    4. ("Save Session File"),
    5. primarySessionPath,
    6. ("Sessions (*.sess)") );
    To copy to clipboard, switch view to plain text mode 

    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,
    Last edited by Rajesh.Rathod; 28th December 2016 at 12:47.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QFileDialog::getSaveFileName - would like to disable save button for read only fo

    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.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QFileDialog::getSaveFileName - would like to disable save button for read only fo

    Quote Originally Posted by d_stranz View Post
    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,
    _

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QFileDialog::getSaveFileName - would like to disable save button for read only fo

    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.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  5. #5
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QFileDialog::getSaveFileName - would like to disable save button for read only fo

    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,
    _

  6. #6
    Join Date
    Apr 2012
    Location
    India.
    Posts
    88
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QFileDialog::getSaveFileName - would like to disable save button for read only fo

    @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,

Similar Threads

  1. Replies: 2
    Last Post: 16th November 2012, 03:42
  2. Replies: 2
    Last Post: 11th May 2011, 00:03
  3. QFileDialog::getSaveFileName Cancel Button
    By penny in forum Qt Programming
    Replies: 1
    Last Post: 8th April 2011, 17:46
  4. QFileDialog::getSaveFileName Save Button
    By penny in forum Qt Programming
    Replies: 1
    Last Post: 8th April 2011, 09:55
  5. How to disable a button in a QFileDialog?
    By TeresaML in forum Qt Programming
    Replies: 2
    Last Post: 18th June 2010, 19:41

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.