Threading a Qt6 fullscreen image
-
Hello everybody,
I am trying to thread a splash screen which is displayed in full screen after clicking a button in a GUI. Unfortunately it appears that the threading makes the application crash. Not sure what I am doing wrong, since the function itself without threading works fine. Also the threading is starting but the splash.show() functions seem to crash it. I am a bit clueless...
Basically i want to make the GUI accessable and not frozen while the BMP is displayed on the second screen.
Here is my method for the display of the BMP:
import sys import time import threading import PyQt6.QtGui from PyQt6.QtWidgets import QApplication, QSplashScreen from PyQt6.QtGui import QPixmap from PyQt6.QtCore import Qt def Display(): s = app.screens()[0] # Get the right screen 0 or 1 # Display info about secondary screen print('Screen Name: {} Size: {}x{} Available geometry {}x{} '.format(s.name(), s.size().width(), s.size().height(), s.availableGeometry().width(), s.availableGeometry().height())) # Select desired image to be displayed and set Resolutions PyQt6.QtCore.QSize(s.size().width(), s.size().height()) pmpath = 'layer0000.bmp' print('Bitmap path: ' + pmpath) pixmap = QPixmap(pmpath) QPixmap() pixmap2 = pixmap.scaled(s.size().width(), s.size().height()) print("Original Bitmap size: ", pixmap.size()) # show pixmap size print("Scaled to: ", pixmap2.size()) # show pixmap size # Splash screen approach splash = QSplashScreen(pixmap2) # Set the splash screen to desired image splash.show() # Show the splash screen splash.windowHandle().setScreen(s) # Set splash screen to secondary monitor splash.showFullScreen() # Show the splash screen splash.setCursor(Qt.CursorShape.BlankCursor) # Set Cursor Invisible on Splascreen time.sleep(3) splash.destroy() end_time = time.time() splash.destroy() print('Execution time: ', end_time - start_time) app = QApplication(sys.argv) start_time = time.time() #Threading the method t1 = threading.Thread(target=Display) t1.start() # If i run this, it works properly. But in a thread it crashes -> #Display()
-
@mullman1 said in Threading a Qt6 fullscreen image:
Unfortunately it appears that the threading makes the application crash
You should never do any UI stuff in other threads than GUI thread!
And there is no need for any threads when using QSplashScreen. -
I see...
Well this is just a simplification of my code.
So in my application i press the button and then i show the BMP file on a screen, so that a microcrontroller driven projector can output it to a DMD to project the image to the lens.
This process takes some time, so would like the GUI not to be frozen while this process is running.How would i solve it then if you say I should not do any threading in UI?
-
@mullman1 said in Threading a Qt6 fullscreen image:
How would i solve it then if you say I should not do any threading in UI?
Move the long lasting operations in a thread, not GUI stuff.
-
You can pre-compute the BMP in a separate thread and then access the finished image in the main thread to use it in the splash screen.