utils: Qt helpers#
Miscellaneous helpers for Qt
concurrent#
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 
 
image#
This module provides conversions between numpy.ndarray and QImage
- convertArrayToQImage(array)[source]#
- 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. 
- Return type:
- QImage
- Returns:
- Corresponding Qt image with RGB888 or ARGB32 format. 
 
- convertQImageToArray(image)[source]#
- Convert a QImage to a numpy array. - If QImage format is not one of: - Format_Grayscale8 
- Format_RGB888 
- Format_RGBA8888 
- Format_ARGB32, 
 - it is first converted to one of this format. - The created numpy array is using a copy of the QImage data. - Parameters:
- image ( - QImage) – The QImage to convert.
- image 
 
- Return type:
- ndarray
- Returns:
- Image array of uint8 of shape: - (height, width) for grayscale images 
- (height, width, channels (3 or 4)) for RGB and RGBA images 
 
 
