Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Functions fromWinId and createWindowContainer not working on Linux
Forum Updated to NodeBB v4.3 + New Features

Functions fromWinId and createWindowContainer not working on Linux

Scheduled Pinned Locked Moved Unsolved Qt for Python
pythonpyside2qt for python
1 Posts 1 Posters 420 Views 2 Watching
  • 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.
  • C Offline
    C Offline
    Claire-C
    wrote on 30 Mar 2023, 16:23 last edited by
    #1

    I am developping a gui application on Python with PySide2. I'm using fromWinId and createWindowContainer functions to embed an external window app in my app. It's perfectly working on Windows, I can access my embedded app (Paint app for example). But on Linux, it's not working the same. I manage to get the window id of the external app and to embed it my app, but when it's embedded, I only have a frozen image of the external app. This is my code :

    import Xlib.display
    from PySide2.QtGui import QWindow
    from PySide2.QtWidgets import QWidget, QApplication, QPushButton, QMainWindow, QVBoxLayout
    
    
    def _get_window_id_win32(title):
        import win32gui
        return win32gui.FindWindow(None, title)
    
    
    def get_window_id_linux(name):
        display = Xlib.display.Display()
        root = display.screen().root
        window_ids = root.get_full_property(display.intern_atom('_NET_CLIENT_LIST'), Xlib.X.AnyPropertyType).value
        for window_id in window_ids:
            window = display.create_resource_object('window', window_id)
            window_name = window.get_wm_name()
            if window_name and name in window_name:
                return window_id
    
    
    def run_app(window_id):
        app = QApplication([])
    
        main = QMainWindow()
        widget_central = QWidget()
        layout = QVBoxLayout()
    
        button = QPushButton()
        button.setText('CLICK')
        layout.addWidget(button)
    
        window = QWindow.fromWinId(window_id)
        widget = QWidget.createWindowContainer(window)
        layout.addWidget(widget)
    
        widget_central.setLayout(layout)
        main.setCentralWidget(widget_central)
        main.show()
    
        app.exec_()
    
    
    if __name__ == '__main__':
        window_id = get_window_id_linux('Window Title') # REPLACE 'Window Title' by the title of the window you want to embed
        # window_id = _get_window_id_win32('Window Title') IF YOU WANT TO TEST ON WINDOWS
        if window_id:
            run_app(window_id)
    
    1 Reply Last reply
    0

    1/1

    30 Mar 2023, 16:23

    • Login

    • Login or register to search.
    1 out of 1
    • First post
      1/1
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved