Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Unsolved Shortcuts problem in migration from QX11EmbedContainer to QWidget.createWindowContainer

    General and Desktop
    1
    2
    282
    Loading More Posts
    • 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.
    • D
      devqore last edited by

      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.

      1 Reply Last reply Reply Quote 0
      • D
        devqore last edited by

        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()
        
        1 Reply Last reply Reply Quote 0
        • First post
          Last post