QFileDialog::getOpenFileName() not initially focussed
I am seeing "unexpected" (but not fatal) behaviour with the static function
QFileDialog::getOpenFileName()--- and with
QFileDialog::getSaveFileName()--- under Linux (Ubuntu, Unity desktop), Qt 5.7, and using the native file dialog. I do not know what the behaviour is under other flavors of Linux/desktops, nor under Windows.
I start from a
QDialog. I click a button whose handler calls
QFileDialog::getOpenFileName(), with the calling dialog as the parent; I am passing no options. Note that this means I do not pass in
QFileDialog::DontUseNativeDialog. There is nothing of note in the code.
At this point the native "file selector" dialog opens. It is up-front. However, it is not "focussed". This means, for example that its title, native close/expand buttons, content is "dimmed". I can click on it. As soon as I do so, it becomes "fully focussed", so that its buttons/content etc. "light up" instead of being dimmed. Once that has happened, it never returns to "dimmed", no matter where I click in the windows/desktop.
I believe this is the case only via the
QFileDialog::getOpenFileName()-type static functions, not the instance ones (though I could be mistaken). I believe this only happens if I use the native dialog, not the Qt one.
Wondering if anyone else is able to reproduce this behaviour under Linux, may require Unity desktop, I don't know. But if you have that set up you could have a look. If nobody does have that environment, doubtless I won't get anywhere with this question.
It had focus on Linux mint XFCE.
Also on windows 10.
I have no UNITY to test on as i dislike it as much as you do windows. :)
You should share a minimal sample that allows people to test your issue on their system.
Couldn't be more minimal (no need for a calling dialog, apparently):
import sys from PyQt5 import QtWidgets class Main(QtWidgets.QMainWindow): def __init__(self): super().__init__() self.button = QtWidgets.QPushButton("Click", self) self.button.clicked.connect(self.openFileDialog) def openFileDialog(self): QtWidgets.QFileDialog.getOpenFileName(self) if __name__ == '__main__': app = QtWidgets.QApplication(sys.argv) main = Main() main.show() sys.exit(app.exec_())
- Click button to show file dialog.
- Click any of the buttons to exit file dialog.
- Click button to show file dialog a second time.
[I am not able to illustrate how it looks "focussed" at #1 but "dimmed" at #3, because the act of taking a screenshot causes it to become "focussed"/"undimmed", just like clicking anywhere does.]
@mrjj In the light of this discovery, would you mind doing your tests again with a second click to display the file dialog again?
Oh, that i did when testing.
In the Dialog, i open/closed the file dialog
multiple times (in same run) on both platforms,
Yeah, thank you, not unexpected. Since it only happens when using the native dialog from Qt, plus it's to do with windows & focussing. Which is why I said initially that unless someone has Unity to test on, it probably would not get anywhere (and so didn't bother showing code for it) ....
Ah well. Unless someone does have a similar environment I'll have to put it down to probably Unity only....
Are you using your distribution provided PyQt and Qt ?
Absolutely yes! As are all my users. Everybody wants to use standard, supported
apt-getfor installing all packages they use under Linux (for Qt we're all at 5.7, provided for Ubuntu 17.04), nobody is interested in downloading packages from individual-product sites, that's why we're using Linux and not Windows.