Refreshing table as the items are set
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:
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.
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
@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?
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.
@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.
You don't need multiple timers, just one that's not single shot and that you stop once all rows have been filled