File tree Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change 1212 PYQT6 ,
1313 PYSIDE2 ,
1414 PYSIDE6 ,
15+ QtBindingsNotFoundError ,
1516)
1617from .QtWidgets import QFileDialog
1718
@@ -200,3 +201,14 @@ def isalive(obj):
200201
201202 return shiboken .isValid (obj )
202203 return None
204+
205+
206+ # =============================================================================
207+ def getimagebytes (qimage ):
208+ if PYQT5 :
209+ return qimage .bits ().asstring (qimage .byteCount ())
210+ if PYQT6 :
211+ return qimage .bits ().asstring (qimage .sizeInBytes ())
212+ if PYSIDE2 or PYSIDE6 :
213+ return qimage .bits ().tobytes ()
214+ raise QtBindingsNotFoundError
Original file line number Diff line number Diff line change 11"""Test the compat module."""
2+
23import sys
34
45import pytest
56
67from qtpy import QtWidgets , compat
8+ from qtpy .QtCore import QRectF , QSize , Qt
9+ from qtpy .QtGui import QBrush , QImage , QPainter
710from qtpy .tests .utils import not_using_conda
811
912
@@ -22,3 +25,10 @@ def test_isalive(qtbot):
2225 with qtbot .waitSignal (test_widget .destroyed ):
2326 test_widget .deleteLater ()
2427 assert compat .isalive (test_widget ) is False
28+
29+
30+ def test_getimagebytes (qtbot ):
31+ """Test compat.getimagebytes"""
32+ image = QImage (QSize (100 , 100 ), QImage .Format_RGB32 )
33+ _bytes = compat .getimagebytes (image )
34+ assert len (_bytes ) == 100 * 100 * 4
You can’t perform that action at this time.
0 commit comments