PyQt6 and QWindowCapture

Jason Hallen hallenj at gmail.com
Thu Feb 22 22:50:49 GMT 2024


[image: image.png]
I was able to use QWindowCapture to successfully capture some of the
windows. For example, in the screenshot above I've captured a Finder
window. It had to do with needing to call self.window_capture.start() again
after I've set a new window.

My goal is to capture my PyQt window itself which is generating animations,
but I'm not seeing the window listed as a capturable window in the
QWindowCapture.capturableWindows() list. Note that the PyQt window is
called "TESTING TESTING", and it's not in the list. I've checked all these
capturable windows, and none of them are the PyQt window. *Is it just not
possible to capture a PyQt window with QWindowCapture?*

0 - Item-0 - <PyQt6.QtMultimedia.QCapturableWindow object at 0x1034f78b0>
1 - Sound - <PyQt6.QtMultimedia.QCapturableWindow object at 0x1034f7290>
2 - Battery - <PyQt6.QtMultimedia.QCapturableWindow object at 0x1034f6f80>
3 - WiFi - <PyQt6.QtMultimedia.QCapturableWindow object at 0x1034f6490>
4 - BentoBox - <PyQt6.QtMultimedia.QCapturableWindow object at 0x1034f65e0>
5 - Clock - <PyQt6.QtMultimedia.QCapturableWindow object at 0x1034f6650>
6 - CPU_mini - <PyQt6.QtMultimedia.QCapturableWindow object at 0x1034f6b90>
7 - RAM_memory - <PyQt6.QtMultimedia.QCapturableWindow object at
0x1034f6b20>
8 - Item-1 - <PyQt6.QtMultimedia.QCapturableWindow object at 0x1034f6c70>
9 - Item-0 - <PyQt6.QtMultimedia.QCapturableWindow object at 0x1034f6dc0>
10 - Menubar - <PyQt6.QtMultimedia.QCapturableWindow object at 0x1034f6e30>
11 - Dock - <PyQt6.QtMultimedia.QCapturableWindow object at 0x1034f6ff0>
12 - anim.py — anim - <PyQt6.QtMultimedia.QCapturableWindow object at
0x1034f6ea0>
13 - Window 0x33 - <PyQt6.QtMultimedia.QCapturableWindow object at
0x1034f70d0>
14 - Wallpaper- - <PyQt6.QtMultimedia.QCapturableWindow object at
0x1034f7220>
15 - Desktop - <PyQt6.QtMultimedia.QCapturableWindow object at 0x1034f7370>
16 - Desktop - <PyQt6.QtMultimedia.QCapturableWindow object at 0x1034f7680>

On Thu, Feb 22, 2024 at 2:37 PM Jason Hallen <hallenj at gmail.com> wrote:

> Wonderful, thank you! I upgraded to v6.6 and I now have access to
> QWindowCapture.
>
> However, I'm having trouble recording any windows. I must be missing
> something. Here's my code where I'm trying to capture my VS Code window.
>
> self.window_capture = QWindowCapture(self)
> self.window_capture.setWindow(QWindowCapture.capturableWindows()[13])   #
> VS Code window
> self.window_capture.start()
> self.media_capture_session = QMediaCaptureSession()
> self.media_capture_session.setWindowCapture(self.window_capture)
> self._video_widget = QVideoWidget(self)
> self._video_widget.resize(400, 300)
> self.media_capture_session.setVideoOutput(self._video_widget)
>
> When I run this I don't see anything in the video widget. Here's a
> screenshot.
>
> [image: Screenshot 2024-02-22 at 2.34.04 PM.png]
>
> When I instead use QScreenCapture in the MediaCaptureSession I see the
> video feed.
>
> [image: Screenshot 2024-02-22 at 2.35.37 PM.png]
>
> Can someone help me properly connect a window capture?
>
> Thanks,
> Jason
>
>
>
> On Thu, Feb 22, 2024 at 10:49 AM Phil Thompson <
> phil at riverbankcomputing.com> wrote:
>
>> On 22/02/2024 16:41, Jason Hallen wrote:
>> > That's great to hear. I wonder what's going wrong for me then. When
>> > importing the class I get this error:
>> >
>> > ImportError: cannot import name 'QWindowCapture' from
>> > 'PyQt6.QtMultimedia'
>> >
>> (/Users/hallenj/miniconda3/envs/csound/lib/python3.11/site-packages/PyQt6/
>> > QtMultimedia.abi3.so)
>> >
>> > I've got the 6.5.1 version. Is there a different version or a
>> > particular
>> > distribution of PyQt6 I should be using?
>>
>> As QWindowCapture was added to Qt v6.6 then you need PyQt v6.6 at least.
>>
>> Phil
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20240222/c176009a/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Screenshot 2024-02-22 at 2.34.04?PM.png
Type: image/png
Size: 49057 bytes
Desc: not available
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20240222/c176009a/attachment-0003.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Screenshot 2024-02-22 at 2.35.37?PM.png
Type: image/png
Size: 75121 bytes
Desc: not available
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20240222/c176009a/attachment-0004.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 60852 bytes
Desc: not available
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20240222/c176009a/attachment-0005.png>


More information about the PyQt mailing list