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 12
12
PYQT6 ,
13
13
PYSIDE2 ,
14
14
PYSIDE6 ,
15
+ QtBindingsNotFoundError ,
15
16
)
16
17
from .QtWidgets import QFileDialog
17
18
@@ -200,3 +201,14 @@ def isalive(obj):
200
201
201
202
return shiboken .isValid (obj )
202
203
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 1
1
"""Test the compat module."""
2
+
2
3
import sys
3
4
4
5
import pytest
5
6
6
7
from qtpy import QtWidgets , compat
8
+ from qtpy .QtCore import QRectF , QSize , Qt
9
+ from qtpy .QtGui import QBrush , QImage , QPainter
7
10
from qtpy .tests .utils import not_using_conda
8
11
9
12
@@ -22,3 +25,10 @@ def test_isalive(qtbot):
22
25
with qtbot .waitSignal (test_widget .destroyed ):
23
26
test_widget .deleteLater ()
24
27
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