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. QWidget is not updated at the right time
Qt 6.11 is out! See what's new in the release blog

QWidget is not updated at the right time

Scheduled Pinned Locked Moved Solved Qt for Python
6 Posts 4 Posters 1.2k Views 2 Watching
  • 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
    Mikeeeeee
    wrote on last edited by
    #1

    Hi!
    I have the code running. In certain parts of the code, I need to update the widget. But the widget is updated only when all the code is completed. I tried to output a part of the code to a separate thread and wait for it to finish, but while the thread is waiting for the end of the flow, the widget is not redrawn.

    jsulmJ 1 Reply Last reply
    0
    • M Mikeeeeee

      Hi!
      I have the code running. In certain parts of the code, I need to update the widget. But the widget is updated only when all the code is completed. I tried to output a part of the code to a separate thread and wait for it to finish, but while the thread is waiting for the end of the flow, the widget is not redrawn.

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

      @Mikeeeeee said in QWidget is not updated at the right time:

      but while the thread is waiting for the end of the flow, the widget is not redrawn

      Of course not - you're blocking the event loop.
      You will need to provide more information and code if you want to get a meaningful answer.

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

      M 1 Reply Last reply
      1
      • jsulmJ jsulm

        @Mikeeeeee said in QWidget is not updated at the right time:

        but while the thread is waiting for the end of the flow, the widget is not redrawn

        Of course not - you're blocking the event loop.
        You will need to provide more information and code if you want to get a meaningful answer.

        M Offline
        M Offline
        Mikeeeeee
        wrote on last edited by
        #3

        @jsulm it is my code

        self.parent.waitServer.showWindow()  # need draw this window
        self.parent.updateWindowAtStart()
        self.parent.showWindow()
        self.parent.waitServer.hideWindow()
        

        this toonot works:

        elf.parent.waitServer.showWindow()
         thread = QThreadPool()
         thread.start(self.parent.updateWindowAtStart())
        thtred = Thread(target=self.parent.updateWindowAtStart)
        thtred.start()
        QCoreApplication.processEvents()
        thtred.join()
        self.parent.updateWindowAtStart()
        self.parent.showWindow()
         self.parent.waitServer.hideWindow()
        
        jsulmJ 1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Mikeeeeee said in QWidget is not updated at the right time:

          thtred.join()

          You're blocking the event loop again.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1
          • kshegunovK Offline
            kshegunovK Offline
            kshegunov
            Moderators
            wrote on last edited by kshegunov
            #5

            I don't believe python allows preemptive multitasking to begin with, so I am not really convinced this can ever work.

            (And that is leaving aside the question of touching GUI stuff from other threads, which you may or may not be doing, can't tell).

            Read and abide by the Qt Code of Conduct

            1 Reply Last reply
            2
            • M Mikeeeeee

              @jsulm it is my code

              self.parent.waitServer.showWindow()  # need draw this window
              self.parent.updateWindowAtStart()
              self.parent.showWindow()
              self.parent.waitServer.hideWindow()
              

              this toonot works:

              elf.parent.waitServer.showWindow()
               thread = QThreadPool()
               thread.start(self.parent.updateWindowAtStart())
              thtred = Thread(target=self.parent.updateWindowAtStart)
              thtred.start()
              QCoreApplication.processEvents()
              thtred.join()
              self.parent.updateWindowAtStart()
              self.parent.showWindow()
               self.parent.waitServer.hideWindow()
              
              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @Mikeeeeee As @SGaist told you you are blocking the event loop. Please take time to learn event driven/asynchronous programming!
              The way you should do your task:

              • Start your thread
              • Emit signals from that thread every time you need to update UI and pass needed information as signal parameters
              • In UI thread connect a slot to the above signal and update UI in that slot
              • Do NOT wait for the thread (remove thtred.join())
              • No need for QCoreApplication.processEvents() with this approach

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

              1 Reply Last reply
              2

              • Login

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