Array label

araviq6.labels provides QLabel subclasses to display numpy array.

class araviq6.labels.ScalableQLabel(*args: Any, **kwargs: Any)[source]

Bases: QLabel

A label which can scale the pixmap before displaying.

Pixmap can be downscaled or upscaled to fit to the label size, depending on pixmapScaleMode().

setPixmap() scales the input pixmap and update to label. originalPixmap() returns current unscaled pixmap.

Notes

Do not modify the size policy and minimum size value. Changing them makes the label not shrinkable.

class PixmapScaleMode(value)[source]

Bases: Enum

This enum defines how the pixmap is scaled before being displayed.

Attributes:
PM_NoScale

Pixmap is never scaled. If the label size is smaller than the pixmap size, only a part of the pixmap is displayed.

PM_DownScaleOnly

Pixmap is scaled, but never larger than its original size.

PM_UpScaleOnly

Pixmap is scaled, but never smaller than its original size.

PM_AllScale

Pixmap is scaled to any size.

originalPixmap() araviq6.qt_compat.QtGui.QPixmap[source]

Original pixmap before scaling.

pixmapScaleMode() PixmapScaleMode[source]

Mode to scale the pixmap. Default is PM_DownScaleOnly.

setPixmapScaleMode(flag: PixmapScaleMode)

Set pixmapScaleMode() to flag and update the label.

setPixmap(pixmap: araviq6.qt_compat.QtGui.QPixmap)

Scale the pixmap and display.

class araviq6.labels.NDArrayLabel(*args: Any, **kwargs: Any)[source]

Bases: ScalableQLabel

Scalable label which can receive and display numpy.ndarray image. Image array can be set by setArray().

Examples

>>> import cv2
>>> from PySide6.QtWidgets import QApplication
>>> import sys
>>> from araviq6 import NDArrayLabel, get_samples_path
>>> img = cv2.imread(get_samples_path('hello.jpg'))
>>> def runGUI():
...     app = QApplication(sys.argv)
...     label = NDArrayLabel()
...     label.setArray(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
...     label.show()
...     app.exec()
...     app.quit()
>>> runGUI()  
setArray(array: ndarray)

Convert the array to pixmap using qimage2ndarray.array2qimage(), and display.