我的QTimeEdit显示HH:mm。MiniuteSection有15个步骤。我的QTimeEdit增量很好。但是当我想减少分钟的时候,我只能把时间从xx:45改成xx:30,再改成xx:15和xx-1:45。如你所见,xx:00的时间被跳过了。没有办法使它从xx:15减到xx:00再减到xx-1:45。有人知道怎么解决这个问题吗?你知道吗
class FiveteenMinuteTimeEdit(QtWidgets.QTimeEdit):
def stepBy(self, steps):
if self.currentSection() == self.MinuteSection:
QtWidgets.QTimeEdit.stepBy(self, steps*15)
t = self.time()
if t.minute() == 59 and steps >0:
time = QtCore.QTime()
time.setHMS(t.hour()+1,0,0)
self.setTime(time)
if t.minute() == 0 and steps <0:
time = QtCore.QTime()
time.setHMS(t.hour()-1,45,0)
self.setTime(time)
else:
QtWidgets.QTimeEdit.stepBy(self, steps)
您只需添加
60 * 15 * step
秒,而且为了更好地实现,当显示的时间处于覆盖stepEnabled()方法的适当限制时,必须启用向上和向下箭头。你知道吗更新:
以下代码允许从00:00更改为23:45以及从00:00更改为23:00。你知道吗
相关问题 更多 >
编程相关推荐