utils: Qt helpers

Miscellaneous helpers for Qt


This module allows to run a function in Qt main thread from another thread

submitToQtMainThread(fn, *args, **kwargs)[source]

Run fn(args, kwargs) in Qt’s main thread.

If not called from the main thread, this is run asynchronously.

Parameters:fn (callable) – Function to call in main thread.
Returns:A future object to retrieve the result
Return type:concurrent.future.Future


This module provides conversions between numpy.ndarray and QImage


Convert an array-like image to a QImage.

The created QImage is using a copy of the array data.

Limitation: Only RGB or RGBA images with 8 bits per channel are supported.

Parameters:array (numpy.ndarray of uint8) – Array-like image data of shape (height, width, channels) Channels are expected to be either RGB or RGBA.
Returns:Corresponding Qt image with RGB888 or ARGB32 format.
Return type:QImage

Convert a QImage to a numpy array.

If QImage format is not Format_RGB888, Format_RGBA8888 or Format_ARGB32, it is first converted to one of this format depending on the presence of an alpha channel.

The created numpy array is using a copy of the QImage data.

Parameters:image (QImage) – The QImage to convert.
Returns:The image array of RGB or RGBA channels of shape (height, width, channels (3 or 4))
Return type:numpy.ndarray of uint8