Anirudh Vemula
Anirudh Vemula

Reputation: 5

How to update a QTableWidgetItem in a QTableWidget with time?

I am planning to make a countdown timer for passes. A file is given from which i read time given as string and then subtract it from the system time to get the time remaining. This value is to be shown in a QTableWidget as a QTableWidgetItem.

How can you update that cell in the table with time?

Upvotes: 0

Views: 1766

Answers (3)

Luke Robinson
Luke Robinson

Reputation: 21

If you're looking to update the cell every second you could use a QTimer and connect the timeout() signal to your method then Set the timer to 1 second long. This will call your method every second.

I doubt this is the best way to go about this but it's all I've got :)

It should look something like this:

QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(yourFunction()));
timer->start(1000)

Upvotes: 1

Aleksandar
Aleksandar

Reputation: 3661

If you want to write hours:minutes, you could compare new result with previous result and if there is a change in time to use QtGui.QApplication.processEvents() which will refresh GUI therefore your time in qtablewidget cell. This might be slow for hours:minutes:seconds

Upvotes: 0

Use the QTableWidgetItem::setText(...) method after converting your time to a string.

Upvotes: 0

Related Questions