QFileDialog - enter key behaviour
Hi, here is a directory chooser code:
The problem is the keyboard-enter behaviour: when user type a dir using keyboard and press enter, it immediately calls accept().
But I prefer to show the content of given dir when the directory-lineEdit has a focus - without closing the dialog...
Is there any way to change keyboard-enter behaviour?
d2uriel last edited by
Without looking in the docs I guess you'd have to subclass QFileDialog and change it's keyPressEvent().
One thing you can do is check whether the dialog input is a valid directory. If not, pop the dialog again...
You don't really need to instantiate a QFileDialog object, you can simply do something like this:
QString dir = QFileDialog::getExistingDirectory(this, tr("Open Directory"), "/home", QFileDialog::ShowDirsOnly);@
yes, i know that native dialog works, but it is not so beautiful as styled Qt dialog :o)
The problem is with network path - typically the user types a machine name: \computer\ and then he wants to pick the dir...
Well, you can always write your own custom input dialog it is fairly easy, or subclass QFileDialog and modify it.
Ok, that's the way.
But I think that the default behaviour of the qt-style dialog si buggy, because no one wants to choose dir with enter when the edit line is focused...
Ironically, the native dialog is working very well for me, I can type folder names, press enter and pretty much navigate everywhere, ugly - maybe, but I am more about functional anyway :)
If you really think it is a bug you can always "file a bug report":http://bugreports.qt.nokia.com/ :)
For now, I have switched to native dialog too :)