Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/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)
    container.show()
    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())
    sys.exit(app.exec_())
    

    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()
    mainWindow.setLayout(vboxLayout)
    
    view = QQuickView()
    container = QtWidgets.QWidget.createWindowContainer(view, mainWindow)
    container.setMinimumSize(QSize(800, 800))
    container.grabKeyboard()
    winId = hex(int(view.winId()))
    vboxLayout.addWidget(container)
    process = QtCore.QProcess(container)
    process.start('/usr/bin/xfreerdp', "/v:someHost /u:someUser /p:somePassword /parent-window:{}".format(winId).split())
    
    mainWindow.show()
    sys.exit(app.exec_())
    

    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):
        Gdk.Seat.ungrab(seat)
        print("xterm detached")
    
    
    window = Gtk.Window(title="Xterm embed")
    socket = Gtk.Socket()
    window.add(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)]
    Popen(cmd)
    socket.show()
    window.show()
    window.connect("destroy", Gtk.main_quit)
    Gtk.main()
    

Log in to reply