Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to resize XEmbed in Qt5 with window size change



  • Hi,
    I'm trying to resize external application which is attached to application using QWidget::createWindowContainer for simplicity in example xterm is used:

    #include <QApplication>
    #include <QWidget>
    #include <QVBoxLayout>
    #include <QWindow>
    #include <QProcess>
    
    int main(int argc, char *argv[])
    {
        QApplication app(argc, argv);
        QWidget widget;
        QWindow window;
        QWidget *container = QWidget::createWindowContainer(&window, &widget);
        QVBoxLayout layout;
        QProcess process;
        QStringList arguments;
        
        layout.addWidget(container);
        widget.setLayout(&layout);
        widget.show();
        arguments << "-into" << QString::number(container->winId());  // also doesn't work properly with window.winId()
        process.start("xterm", arguments);
    
        return app.exec();
    }
    

    And in this example xterm is not resized when main widget is resized, following example works in Qt4 with QX11EmbedContainer:

    #include <QApplication>
    #include <QWidget>
    #include <QX11EmbedContainer>
    #include <QVBoxLayout>
    #include <QProcess>
    
    int main(int argc, char *argv[])
    {
        QApplication app(argc, argv);
        QWidget widget;
        QX11EmbedContainer container(&widget);
        QVBoxLayout layout;
        QProcess process;
        QStringList arguments;
    
        layout.addWidget(&container);
        widget.setLayout(&layout);
        widget.show();
        arguments << "-into" << QString::number(container.winId());
        process.start("xterm", arguments);
    
        return app.exec();
    }
    

    Does anybody have idea how I can achieve such effect in Qt5 like in Qt4 with QX11EmbedContainer? Any tips will be very helpful.



  • It looks that solution in GTK is quite simple, it's sad that Qt5 hasn't nothing to offer like it was in Qt4 with QX11EmbedContainer...

    Simple example in GTK3 using python:

    import gi
    gi.require_version("Gtk", "3.0")
    from gi.repository import Gtk
    from subprocess import Popen
    
    window = Gtk.Window(title="Xterm embed")
    socket = Gtk.Socket()
    window.add(socket)
    sock_id = str(socket.get_id())
    
    # sendEvents required according to xterm documentation
    cmd = ["xterm", '-xrm', "xterm*.allowSendEvents: true", "-into", sock_id]
    
    Popen(cmd)
    socket.show()
    window.show()
    window.connect("destroy", Gtk.main_quit)
    Gtk.main()
    

  • Lifetime Qt Champion



  • @mrjj I didn't recieve any message about your response, and I saw it when I tried to find solution of this problem once again after while :P

    I already saw this repository but I didn't used because I would like to find solution without compiling additional plugins also repository looks like not developed anymore.


Log in to reply