Unsolved QFileDialog::getOpenFileName() not initially focussed
-
I am seeing "unexpected" (but not fatal) behaviour with the static function
QFileDialog::getOpenFileName()
--- and withQFileDialog::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 callsQFileDialog::getOpenFileName()
, with the calling dialog as the parent; I am passing no options. Note that this means I do not pass inQFileDialog::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.
-
Hi
Test Case
MainWindow->button->released()
Dialog d(this);
d.exec()
d->Button->released()->
QFileDialog::getOpenFileName();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. :) -
Hi,
You should share a minimal sample that allows people to test your issue on their system.
-
@SGaist
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_())
@mrjj, and @SGaist
I had not realised, the pattern is: first timeQFileDialog
is shown it is correctly focussed, subsequent times it is shown unfocussed. So you must:- 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, -
@mrjj
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 ?
-
@SGaist
Absolutely yes! As are all my users. Everybody wants to use standard, supportedapt-get
for 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.