'QTimer format converting
I have this code:
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtCore import Qt, QTimer
import sys
class Ui_Timer15(object):
def setupUi(self, Timer):
Timer.setObjectName("Timer")
Timer.resize(321, 121)
self.count = 5400
self.start = False
self.centralwidget = QtWidgets.QWidget(Timer)
self.centralwidget.setObjectName("centralwidget")
self.pushButton_4 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_4.setGeometry(QtCore.QRect(10, 80, 141, 31))
self.pushButton_4.setObjectName("pushButton_4")
self.pushButton_4.clicked.connect(self.start_action)
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(10, 10, 301, 61))
self.label.setStyleSheet("border : 3px solid black")
self.label.setAlignment(Qt.AlignCenter)
self.label.setObjectName("label")
self.pushButton_5 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_5.setGeometry(QtCore.QRect(170, 80, 141, 31))
self.pushButton_5.setObjectName("pushButton_5")
self.pushButton_5.clicked.connect(self.pause_action)
Timer.setCentralWidget(self.centralwidget)
self.retranslateUi(Timer)
QtCore.QMetaObject.connectSlotsByName(Timer)
timer = QTimer(self.label)
timer.timeout.connect(self.showTime)
timer.start(1000)
def showTime(self):
# checking if flag is true
if self.start:
# incrementing the counter
self.count -= 1
# timer is completed
if self.count == 0:
# making flag false
self.start = False
# setting text to the label
self.label.setText("Completed")
if self.start:
# getting text from count
text = str(self.count)
# showing text
self.label.setText(text)
def start_action(self):
# making flag true
self.start = True
# count = 0
if self.count == 0:
self.start = False
def pause_action(self):
# making flag false
self.start = False
def retranslateUi(self, Timer):
_translate = QtCore.QCoreApplication.translate
Timer.setWindowTitle(_translate("Timer", "MainWindow"))
self.pushButton_4.setText(_translate("Timer", "Start"))
self.pushButton_5.setText(_translate("Timer", "Pause"))
self.label.setText(_translate("Timer", "0"))
When I start the timer, i see:

How I can convert this into hh:mm:ss ? I tried a lot of things but it doesn`t worked....
It looks like your post is mostly code; please add some more details. It looks like your post is mostly code; please add some more details. It looks like your post is mostly code; please add some more details.
Solution 1:[1]
Use QTime:
t = QTime(0, 0, 0).addSecs(self.count)
text = t.toString("hh:mm:ss")
self.label.setText(text)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
