Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Threading a Qt6 fullscreen image
QtWS25 Last Chance

Threading a Qt6 fullscreen image

Scheduled Pinned Locked Moved Unsolved Qt for Python
pythonthreadingsplashscreen
5 Posts 3 Posters 1.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mullman1
    wrote on last edited by
    #1

    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()
    
    jsulmJ 1 Reply Last reply
    0
    • M mullman1

      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()
      
      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @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.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      3
      • M Offline
        M Offline
        mullman1
        wrote on last edited by
        #3

        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?

        jsulmJ 1 Reply Last reply
        0
        • M mullman1

          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?

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @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.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • S Offline
            S Offline
            SimonSchroeder
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved