Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved Refreshing table as the items are set

    General and Desktop
    table connect
    2
    6
    1640
    Loading More Posts
    • 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
      Lobstw last edited by

      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 Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        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 Reply Quote 0
        • L
          Lobstw @SGaist last edited by

          @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 Reply Quote 0
          • SGaist
            SGaist Lifetime Qt Champion last edited by

            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 Reply Quote 0
            • L
              Lobstw @SGaist last edited by Lobstw

              @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 Reply Quote 0
              • SGaist
                SGaist Lifetime Qt Champion last edited by

                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 Reply Quote 0
                • First post
                  Last post