Important: Please read the Qt Code of Conduct -

Shortcuts problem in migration from QX11EmbedContainer to QWidget.createWindowContainer

  • I'm trying to replace QX11EmbedContainer Qt4 with QWidget.createWindowContainer from Qt5, but I cannot achieve this same effect. Problematic is behavior of shortcuts, if I have defined some global shortcuts (e.g: ALT + TAB) they are captured by window manager (I'm using xfce4 with xfwm) but they should behave IMO like in qt4 and should be grabbed by x11 container. Do you have any idea how can achieve such behavior in qt5 to grab keyboard by the container?

    Bellow is simplified code in PyQt4:

    import sys
    from PyQt4 import QtGui
    from PyQt4 import QtCore
    app = QtGui.QApplication(sys.argv)
    container = QtGui.QX11EmbedContainer()
    container.setGeometry(10, 20, 1100, 800)
    process = QtCore.QProcess(container)
    winId = hex(int(container.winId()))
    process.start('/usr/bin/xfreerdp', "/v:someHost /u:someUser /p:somePassword /parent-window:{}".format(winId).split())

    this I tried in PyQt5:

    import sys
    from PyQt5 import QtWidgets
    from PyQt5.QtCore import QSize, QProcess
    from PyQt5.QtQuick import QQuickView
    app = QtWidgets.QApplication(sys.argv)
    mainWindow = QtWidgets.QWidget()
    vboxLayout = QtWidgets.QVBoxLayout()
    view = QQuickView()
    container = QtWidgets.QWidget.createWindowContainer(view, mainWindow)
    container.setMinimumSize(QSize(800, 800))
    winId = hex(int(view.winId()))
    process = QtCore.QProcess(container)
    process.start('/usr/bin/xfreerdp', "/v:someHost /u:someUser /p:somePassword /parent-window:{}".format(winId).split())

    I tried also write this code in C++ without PyQT, but there wasn't any difference in behavior.

  • It looks that could be easily achieved using GTK3, so the best solution is to migrate from Qt4 to GTK3 when QX11EmbedContainer is used ?

    import gi
    gi.require_version("Gtk", "3.0")
    from gi.repository import Gtk, Gdk
    from subprocess import Popen
    seat = Gdk.Display.get_default().get_default_seat()
    def plugged_added(plugged_socket):
        Gdk.Seat.grab(seat, plugged_socket.get_window(), Gdk.SeatCapabilities.KEYBOARD, True)
        print("xterm attached")
    def plugged_removed(plugged_socket):
        print("xterm detached")
    window = Gtk.Window(title="Xterm embed")
    socket = Gtk.Socket()
    sock_id = str(socket.get_id())
    socket.connect("plug-added", plugged_added)
    socket.connect("plug-removed", plugged_removed)
    cmd = ['/usr/bin/xfreerdp', "/v:someHost", "/u:someUser", "/p:somePassword", "/parent-window:{}".format(sock_id)]
    window.connect("destroy", Gtk.main_quit)

Log in to reply