From 9adfe70d6b97c1e73d98ce8bc8fbd04fe969306f Mon Sep 17 00:00:00 2001 From: huhaha120 Date: Tue, 2 Jun 2026 17:36:47 +0800 Subject: [PATCH] docs: clarify macOS PyQt embedding --- README.rst | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/README.rst b/README.rst index db57f22..8b6efa2 100644 --- a/README.rst +++ b/README.rst @@ -267,7 +267,7 @@ python-mpv is using mpv via libmpv. libmpv is meant for embedding into other app GUI features such as the OSD or keyboard input. To enable the built-in GUI, use the following options when initializing the MPV instance. See `Issue 102`_ for more details -.. _`issue 102`: https://github.com/jaseg/python-mpv/issues/61 +.. _`issue 102`: https://github.com/jaseg/python-mpv/issues/102 .. code:: python @@ -284,6 +284,11 @@ the MPV instance. See `Issue 102`_ for more details PyQT embedding .............. +On macOS, libmpv may hang when it tries to create its own window. In that case, create a native Qt window on the main +thread and pass its window id to ``MPV`` using ``wid``. Qt itself must run on the main thread; move the rest of your +application work to worker threads or processes instead of starting ``QApplication`` in a background thread. Also keep +the ``MPV`` instance referenced for as long as the window is alive. + .. code:: python #!/usr/bin/env python3 @@ -300,11 +305,10 @@ PyQT embedding self.setCentralWidget(self.container) self.container.setAttribute(Qt.WA_DontCreateNativeAncestors) self.container.setAttribute(Qt.WA_NativeWindow) - player = mpv.MPV(wid=str(int(self.container.winId())), - vo='x11', # You may not need this + self.player = mpv.MPV(wid=str(int(self.container.winId())), log_handler=print, loglevel='debug') - player.play('test.webm') + self.player.play('test.webm') app = QApplication(sys.argv) @@ -400,4 +404,3 @@ For details, see `the mpv copyright page`_. .. _Robozman: https://gitlab.com/robozman .. _dfaker: https://github.com/dfaker .. _`the mpv copyright page`: https://github.com/mpv-player/mpv/blob/master/Copyright -