<html><body><div style="color:#000; background-color:#fff; font-family:times new roman, new york, times, serif;font-size:12pt"><div>Hi can somebody please help me?</div><div>I am trying to control the hours, minutes and seconds of a QTimeEdit independently by using 3 QScrollBars.</div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: times new roman,new york,times,serif; background-color: transparent; font-style: normal;">Here's what I've got so far. It works but the setTime command always resets the elements that I don't want to affect. Is there something like setMinutes, setHours or setSeconds ?</div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: times new roman,new york,times,serif; background-color: transparent; font-style: normal;">I've also thought about using a QLCDNumber widget instead of the QTimeEdit but I'm not sure if that would work.<br></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: times
new roman,new york,times,serif; background-color: transparent; font-style: normal;">Thanks for any help.</div><div><br></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: times new roman,new york,times,serif; background-color: transparent; font-style: normal;">from PyQt4 import QtCore, QtGui<br><br>class Help(QtGui.QMainWindow):<br> def __init__(self):<br> super(Help, self).__init__()<br><br> #QTimeEdit<br> self.TimeEdit = QtGui.QTimeEdit()<br><br> #Hours ScrollBar<br> self.HourScrollBar = QtGui.QScrollBar(QtCore.Qt.Horizontal)<br> self.HourScrollBar.setMinimum(0)<br> self.HourScrollBar.setMaximum(23)<br>
self.HourScrollBar.setFocusPolicy(QtCore.Qt.StrongFocus)<br><br> #Minutes ScrollBar<br> self.MinScrollBar = QtGui.QScrollBar(QtCore.Qt.Horizontal)<br> self.MinScrollBar.setMinimum(0)<br> self.MinScrollBar.setMaximum(59)<br> self.MinScrollBar.setFocusPolicy(QtCore.Qt.StrongFocus)<br><br> #Seconds ScrollBar<br> self.SecScrollBar = QtGui.QScrollBar(QtCore.Qt.Horizontal)<br> self.SecScrollBar.setMinimum(0)<br> self.SecScrollBar.setMaximum(59)<br> self.SecScrollBar.setFocusPolicy(QtCore.Qt.StrongFocus)<br><br> #ScrollBar connections<br>
self.HourScrollBar.valueChanged.connect(self.HourChanged)<br> self.MinScrollBar.valueChanged.connect(self.MinChanged)<br> self.SecScrollBar.valueChanged.connect(self.SecChanged)<br><br> #Main layout and widget<br> MainWidget = QtGui.QWidget()<br> MainLayout = QtGui.QVBoxLayout()<br> MainLayout.addWidget(self.TimeEdit)<br> MainLayout.addWidget(self.HourScrollBar)<br> MainLayout.addWidget(self.MinScrollBar)<br> MainLayout.addWidget(self.SecScrollBar)<br> MainWidget.setLayout(MainLayout)<br>
self.setCentralWidget(MainWidget)<br><br> def HourChanged(self):<br> self.TimeEdit.setTime(QtCore.QTime.fromString(str(self.HourScrollBar.value()), "h"))<br><br> def MinChanged(self):<br> self.TimeEdit.setTime(QtCore.QTime.fromString(str(self.MinScrollBar.value()), "m"))<br><br> def SecChanged(self):<br> self.TimeEdit.setTime(QtCore.QTime.fromString(str(self.SecScrollBar.value()), "s"))<br><br>if __name__ == '__main__':<br> import sys<br> app = QtGui.QApplication(sys.argv)<br> w = Help()<br> w.show()<br> sys.exit(app.exec_())<br></div></div></body></html>