如何在 PyQt4 的 QDateTimeEdit 中设置今天的日期和具体时间?
How can I set today is date and specific time of the day in QDateTimeEdit in PyQt4?
这是我写的代码:
dt = dt or self.cal.selectedDate()
date_time_str = str(dt.toString(QtCore.Qt.DefaultLocaleShortDate)) + " 10:00:00"
now = QtCore.QDateTime.fromString(date_time_str, 'yyyy/M/d hh:mm:ss')
self.mydateTimeEdit.setDateTime(now)
self.mydateTimeEdit.setCalendarPopup(True)
但是这个日期时间设置为
1/1/00 12:00AM 在 myDateTimeEdit UI.
当我想要将今天的日期设置为 10:00 AM
不需要转换为字符串,传递一个具有所需时间的 QTime 就足够了:
dt = dt or self.cal.selectedDate()
now = QtCore.QDateTime(dt, QtCore.QTime(10, 0, 0))
self.mydateTimeEdit.setDateTime(now)
self.mydateTimeEdit.setCalendarPopup(True)
这是我写的代码:
dt = dt or self.cal.selectedDate()
date_time_str = str(dt.toString(QtCore.Qt.DefaultLocaleShortDate)) + " 10:00:00"
now = QtCore.QDateTime.fromString(date_time_str, 'yyyy/M/d hh:mm:ss')
self.mydateTimeEdit.setDateTime(now)
self.mydateTimeEdit.setCalendarPopup(True)
但是这个日期时间设置为
1/1/00 12:00AM 在 myDateTimeEdit UI.
当我想要将今天的日期设置为 10:00 AM
不需要转换为字符串,传递一个具有所需时间的 QTime 就足够了:
dt = dt or self.cal.selectedDate()
now = QtCore.QDateTime(dt, QtCore.QTime(10, 0, 0))
self.mydateTimeEdit.setDateTime(now)
self.mydateTimeEdit.setCalendarPopup(True)