I'm trying to take a screenshot using PySide (and return a QPixmap). This is part of a larger script. Unfortunately, I'm running into a wall at the moment.
Here's a simplified snippet that I'm trying to get to work:
from PySide2 import QtGui, QtWidgets
screen = QtWidgets.QApplication.primaryScreen()
winid = QtWidgets.QApplication.desktop().winId()
pixmap = screen.grabWindow(winid)
label = QtWidgets.QLabel("test")
label.setPixmap(pixmap)
label.show()
When executing this, it throws the following error:
TypeError: 'PySide2.QtGui.QScreen.grabWindow' called with wrong argument types:
PySide2.QtGui.QScreen.grabWindow(int)
Supported signatures:
PySide2.QtGui.QScreen.grabWindow(quintptr, int = 0, int = 0, int = -1, int = -1)
I'm using PySide version 2.0.0~alpha0 (which is the version that ships with the host application I'm using). I've tested the same code in a new version of the host application that uses PySide2 version 5.12.2, which executed as expected, without any errors... However, I'm limited to using the older version of the host application.
Does anyone know of a workaround?
First that came to mind was using PyQt5 to generate the QPixmap, and have PySide take it from there, but when testing this it turned out the PyQt QPixmap wasn't compatible with PySide. Porting the entire script to PyQt isnt an option either.