Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Refreshing table as the items are set
Forum Update on Monday, May 27th 2025

Refreshing table as the items are set

Scheduled Pinned Locked Moved Unsolved General and Desktop
tableconnect
6 Posts 2 Posters 2.2k 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.
  • L Offline
    L Offline
    Lobstw
    wrote on last edited by
    #1

    Hello,

    I have an empty table with a button. When that button is pressed, it fills that table.

    The button is linked to a function by:

    my_button.clicked.connect(lambda:my_function())
    

    The function itself does something like:

    def my_function():
        for i in range(5):
            my_table.setItem(i,0,QtWidgets.QTableWidgetItem(i))
    

    The function trivially sets the item at 1,1 to 1 and 2,1 to 2 and 3,1 to 3 and so on.

    However, I'd like the table to show it being set individually. So once an item is set, refresh the table to show the item is there and continue with the function.

    Because, at present, Qt waits for my entire function to complete then shows the changes made to the table.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      One way to do that would be to use a QTimer and update the content of your table one by one each time the timer times out.

      Hope it helps

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

      L 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        One way to do that would be to use a QTimer and update the content of your table one by one each time the timer times out.

        Hope it helps

        L Offline
        L Offline
        Lobstw
        wrote on last edited by
        #3

        @SGaist Hello, thanks for the reply. I've implemented a timer and it runs a function every 5 seconds but I'm not sure I have the right way of updating contents. I only have a table (not sure if it's a model view or whatever) and I use my_table.update() and it seems to have no effect?

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Sorry, I wasn't clearer, I meant that when the timeout occurs, you add one new item to your QTableWidget. That until you have the number of item you want.

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

          L 1 Reply Last reply
          0
          • SGaistS SGaist

            Sorry, I wasn't clearer, I meant that when the timeout occurs, you add one new item to your QTableWidget. That until you have the number of item you want.

            L Offline
            L Offline
            Lobstw
            wrote on last edited by Lobstw
            #5

            @SGaist Thanks again! I understand now and have implemented it.

            I have a final follow-up question that's more about problem solving than Qt!

            My program is like so:

            Button press -> Timer start -> Timer finish ->
            -> Fill data for first row -> Restart timer

            I have to iterate over all of the rows in my table BUT the iteration must happen in the timer. I can't iterate normally as we've seen before it just goes through all of them then displays all the data at the end instead of one by one as desired.

            Any ideas on solving this problem?

            edit: Thought I solved it but I'm getting multiple timers running and not stopping.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              You don't need multiple timers, just one that's not single shot and that you stop once all rows have been filled

              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
              0

              • Login

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