Search code examples
qtx11

Embed Qt application into external window


I have Qt application that I want to render onto a window provided by external application in Linux / X environment.

I know it is possible to start some applications and tell them to project themselves on one of my widgets: I get internally QWidget::winId() and start erxternal application with this as a parameter. I want to do reverse: start my Qt application with xid provided from elsewhere. I can't find how to do this direction.


Solution

  • Finally found out (explanation in comments):

    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
    
        // create QWindow
        int hwnd = 35651603; // provided from other app, should be dynamic
        QWindow *nativeWindow = QWindow::fromWinId(hwnd);
    
        // Prepare something to show
        MainWindow w;
        
        // move displayed widget to desired location
        w.windowHandle()->setParent(nativeWindow);
        w.move(0, 0);
    
        // actually display. Must be done last
        w.show();
    
        return a.exec();
    }