how can I set qdialog parent with another process(x11 based)'s main window
-
I am doing qt app required to have a dialog show in browsers,etc,chrome,firefox,.., I use QWindow::setTransientParent,here is my code:
QApplication a(argc, argv); // wait for browser becoming active std::this_thread::sleep_for(std::chrono::seconds(5)); // get browser's native window handle with x11 lib, // to get active window ,see : // https://gist.githubusercontent.com/kui/2622504/raw/c11f4c94e11107311f3c8c20732ce1472dba25ed/gistfile1.c Window w = get_active_top_window(); auto qw = QWindow::fromWinId(w); QDialog dlg; // here is my dialog dlg.winId(); // ensure to create native window dlg.windowHandle()->setTransientParent(qw); dlg.exec();
everything is good ,except that my qdialog is fixed in the browser ,when i drag the dialog's titlebar, the browser move also, how can I get it work? TIA.
-
@java9d
I have just had to move to Ubuntu 18.04, so I got moved from Unity desktop to GNOME desktop, which is what you have. As far as I know that behaviour whereby dragging a sub-dialog around drags its parent along with it, is a native GNOME behaviour, nothing to do with Qt. If anything at all can be done to alter it I would expect it to be via GNOME settings tweaks. Just a heads-up, unless you/someone else knows any better.... -
@JonB
thanks for your reply.
I don't know whether I understand QWindow::setTransientParent exactly. When I set QDialog parent with main window in identical process, the problem is still here://your code here int main() { QApplication a(argc, argv); // wait for browser becoming active std::this_thread::sleep_for(std::chrono::seconds(5)); MainWindow w; w.show(); a.exec(); } // click listener void button1_click() { // get browser's native window handle with x11 lib, // to get active window ,see : // https://gist.githubusercontent.com/kui/2622504/raw/c11f4c94e11107311f3c8c20732ce1472dba25ed/gistfile1.c Window w = get_active_top_window(); auto qw = QWindow::fromWinId(w); QDialog dlg; // here is my dialog dlg.winId(); // ensure to create native window dlg.windowHandle()->setTransientParent(qw); }
It's quite simple in windows platform, I just want an equivalence of X11 :
HWND hwndDialog = ...; // my dialog HWND fore = GetForegroundWindow(); // get active window API , possibly in another process. SetWindowLongPtr(hwndDialog, GWLP_HWNDPARENT, (LONG_PTR)fore);
-
@java9d
I know nothing about "transient parent".When I set QDialog parent with main window in identical process, the problem is still here:
Yes, as I said, it seems to be the behaviour of GNOME (at least by default) that dragging a dialog drags its parent/main window with it.