Question

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?

Was it helpful?

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.

OTHER TIPS

If you use the static functions of QFileDialog, such as getExistingDirectory() and getOpenFileName() you get native OS X file dialogs. However, if you create your own QFileDialog without using the static functions you should get a Qt file dialog for which you can specify what the user must select in the dialog by calling setFileMode(). I think the Qt file dialog will let the user manually change the path in the dialog.

Of course if you only want to have the user manually type in a directory path you could also use a simple QInputDialog.

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