简体   繁体   English

QT5 Widget 的 Python 3.7 屏幕截图是黑色的

[英]Python 3.7 Screenshot from QT5 Widget is black

I'm taking a screenshot of a QtWidget via我正在通过以下方式截取 QtWidget 的屏幕截图

import sys
import os
from PyQt5 import QtGui, QtCore, QtWidgets
from PyQt5.QtGui import QPixmap
from matplotlibwidget import MatplotlibWidget

screenshot = QtWidgets.QWidget.grab(uiCompareGraph.matplotlibwidget_compare) 
screenshot.save("screenshot.png", 'PNG')

which works basically fine when I only take one screenshot.当我只截取一张屏幕截图时,它基本上可以正常工作。 Now my issue is that my program can do a bulk analysis for my data and therefore creates a series of screenshots from which the first one is always black, all of the other one are good.现在我的问题是我的程序可以对我的数据进行批量分析,因此创建了一系列屏幕截图,其中第一个总是黑色的,其他的都很好。 I experimented with time delay before the screenshot but it didn't work.我在屏幕截图之前尝试了时间延迟,但没有用。 Is there an alternative simple method for creating a screenshot of a QtWidget?是否有另一种简单的方法来创建 QtWidget 的屏幕截图? Thank you!谢谢!

Black screen is sometimes a sign that program uses direct hardware rendering, but the case that it's always first one suggests more of like a bug.黑屏有时是程序使用直接硬件渲染的标志,但它总是第一个的情况更像是一个错误。

How about trying out standalone screenshoting library?试试独立的截图库怎么样? There are few for python, for eg https://pypi.org/project/pyscreenshot/ python很少,例如https://pypi.org/project/pyscreenshot/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM