Search code examples
macosqtqt4qt5qfiledialog

Qt on Mac: how to get a file dialog that allows to write the desired file path manually?


On Mac OS-X, usually directory dialogues are shown without the possibility to enter the path with the keyboard. This seems to be the default behaviour when I build a Qt application on OS-X.

How can I specify that I do want the path to be manually entered?


Solution

  • I'd recommend using the native dialog obtained thought he QFileDialog's static methods. With the new sandboxing requirements from apple, you must use the standard dialogs for your application to get access to the file system. Its interesting actually, the actual dialog given to the user in a sandboxed application is though something called Powerbox. You can read more about it here in the NSPanel documentation.

    Also as elmigranto pointed out in all the file dialogs on the Mac, you can hit command + shift + g to enter the path to navigate to.

    Note: In the newer Qt versions the documentation implies that they corrected this such that using the static functions on QFileDialog gets you a native dialog that also goes through PowerBox. I haven't tried it myself though and the bug on the issue remains open against Qt 5.5.0 and 5.6.0. Overriding QFileDialog doesn't get you a native dialog however. If you need a customized dialog, going the NSSavePanel route is the way to go.