[PyQt] Directory selection dialog on windows

Hey there,

is there any way to have a decent directory selector using PyQt without rolling your own? By default using QFileDialog().getExistingDirectory() Qt is resorting to the native windows directory selector. And even the worse variation of it. It offers only a tree view and does not allow pasting of paths or proper browsing. When forcing Qt to use its own dialog, the dialog is better, but it also does not allow pasting paths. All i want is a standard windows file dialog that allows me to choose a directory.

Any hints?

Regards,
Thorsten

I use this with no problems (within Maya), I get a standard Windows File Dialog Browser with all the bells and whistles.

        startingDir = cmds.workspace(q=True, rootDirectory=True)
        destDir = QtGui.QFileDialog.getExistingDirectory(None, 
                                                         'Open working directory', 
                                                         startingDir, 
                                                         QtGui.QFileDialog.ShowDirsOnly)

Using your snipped i get this dialog:

Do you get a different one??

I do, I get the standard Windows Dialog…i wonder if it’s tied to Maya’s preferences. I do not use the new Maya dialog boxes - i reverted to the OS dialog. Maybe there is some strange interactions between pyqt and that option?

Weird. That seems to hint tho that it is at least possible. Thanks!

I also have DirectFolders installed (great app, everyone should use it!) - that may be hijacking the creation of the dialog box.

I’ll try that and check if this changes the behavior maybe. Rolling that out is sadly not an option currently.

Regards,
Thorsten

i looked at this on some other machines with different setups and everyone is getting standard window dialogs… not sure why you are getting a pared-down dialog…

So maybe this is either a matter of the Qt or Python version used. To the bat cave!

Hello, I was wondering if someone could help me with a similar issue. I just want to open up a regular windows explorer window, but when my file dialog opens I can only see directories. This is what I’m working with:

startingDir = 'C:/Program Files'
dialog = QtGui.QFileDialog()
dialog.setFileMode( QtGui.QFileDialog.FileMode() )
dialog.getExistingDirectory( None, 'Open working directory', startingDir )

[QUOTE=borbs727;29054]Hello, I was wondering if someone could help me with a similar issue. I just want to open up a regular windows explorer window, but when my file dialog opens I can only see directories. This is what I’m working with:

startingDir = 'C:/Program Files'
dialog = QtGui.QFileDialog()
dialog.setFileMode( QtGui.QFileDialog.FileMode() )
dialog.getExistingDirectory( None, 'Open working directory', startingDir )

[/QUOTE]

Are you trying to open a file? If so you can try replacing the last line with:

dialog.getOpenFileName( None, 'Open working directory', startingDir )

if you just want to open a regular Explorer window, you can use

os.startfile(startingDir)