Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. how can I set qdialog parent with another process(x11 based)'s main window

how can I set qdialog parent with another process(x11 based)'s main window

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 1.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    java9d
    wrote on last edited by
    #1

    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.
    alt text

    JonBJ 1 Reply Last reply
    0
    • J java9d

      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.
      alt text

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @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....

      1 Reply Last reply
      3
      • J Offline
        J Offline
        java9d
        wrote on last edited by
        #3

        @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);
        
        JonBJ 1 Reply Last reply
        0
        • J java9d

          @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);
          
          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @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.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved