"GTK" warning for Native QFileDialog under Linux
The following question will need a Qt expert who is prepared to look at the Qt source code!
- It definitely happens under Linux Ubuntu with GNOME desktop.
- I do not know whether it happens under Linux with other desktops.
- I do not know whether it happens under Windows.
Someone will have to be kind enough to try and see!
If you open the Native (not Qt)
QFileDialog.getOpenFileName(parent, caption, directory, filter, initialFilter, options)), you always get a warning:
Gtk-Message: GtkDialog mapped without a transient parent. This is discouraged.
This is explained (to some extent) in, say, https://stackoverflow.com/questions/44392504/run-python-gtk3-dialog-or-message-dialog-without-no-transient-parent-warning or https://stackoverflow.com/questions/29883211/gtkdialog-mapped-without-a-transient-parent
Note that this warning still occurs whatever widget I pass as
QFileDialog, I have tried the calling Dialog widget, the Main Window and NULL/None to no effect.
The warning does not matter so much inside a debugger, but it appears in the output from my application, e.g. in a terminal window if I invoke it from there. If you are an expert you will know why running my app with
2>/dev/nullis not a good solution!
If I understand those posts (especially https://stackoverflow.com/questions/44392504/run-python-gtk3-dialog-or-message-dialog-without-no-transient-parent-warning) correctly, it's down to how Qt source code --- which I take to be using GTK --- actually invokes the native file dialog. You would have thought it was passing the parent I give to
QFileDialog, but maybe not?
Can anyone see what's going on in the source for this? Given that, is there any possible workaround for me?
From a quick look, it doesn't seem there's anything that can be done currently see here.
Thank you for that. I note that the call seems to be:
gtk_file_chooser_dialog_new("", 0, ...)
parent, which I understand to be the cause of the warning. Seems strange that the "parent" we pass to
QFileDialogfunction does not get passed down to native dialog call?
@JNBarchan said in "GTK" warning for Native QFileDialog under Linux:
Seems strange that the "parent" we pass to QFileDialog function does not get passed down to native dialog call?
Because it can't. GTK does not know anything about any Qt classes - so it cannot use Qt classes as parents.
Sorry, yes, I meant, when we pass a Qt parent widget as parent to QFileDialog it would pass the corresponding native window onto GTK level as parent. But I don't know anything about GTK!
@JNBarchan But since it is a Qt application there is no native GTK window. Qt does not use GTK on Linux - as far as I know it draws by itself.
But a native QFileDialog might be GTK ?
@mrjj Yes, the native dialog is GTK, but there is no other GTK window to use as parent, right?
Ah in that way. yes that would be hard to have in plain Qt app.
- The native file dialog is a special kind of window: a "GTK" window. (This applies to Linux/X11? Ubuntu? Unity desktop only?)
- It would like another GTK window as its parent.
- But the Qt window which is its parent in
QFileDialogis not a GTK window.
- So the code passes
NULLfor the parent, and that causes the warning.
@JonB Yes, if you use native dialogs on Linux then Qt simply uses GTK dialogs (GTK is isn't related to Unity, see https://www.gtk.org/). Yes, as GTK does not know anything about Qt it is not possible to pass a parent to GTK dialogs from a Qt app.
All makes sense now! I had assumed that a normal Qt (X11?) window/dialog would serve as the parent for (what turns out to be a GTK) native file dialog. Now I get the problem, and the reason for the warning!