PyQT4是否更改qDateTimeEdit时间值?

2024-06-16 10:45:13 发布

您现在位置:Python中文网/ 问答频道 /正文

被困在我的节目里。。我好像找不到像样的 如何做到这一点的例子。。

我有一个QDateTimeEdit对象 我已经将其显示值设置为当前系统时间使用的值

self.ui.dateTimeEdit.setDate(QDate.currentDate())

例如,其输出为7/16/2012 12:00:00 AM

现在我的问题是。。 我想将12:00:00 AM设置为11:59:59 PM

我该怎么做?

多亏有人愿意花时间回答我的问题。


Tags: 对象selfui系统时间am节目例子
1条回答
网友
1楼 · 发布于 2024-06-16 10:45:13

PyQt中基本上可以使用三种不同的对象:

  • q日期

  • q时间

  • Q日期时间

QDateTime接受其他两种类型。因此,可以使用QDate实例定义QDateTime对象的日期,QTime也可以这样做。

显然,如果您试图更改需要使用QTime对象的时间。

下面是一些例子:

#create a QDateTimeEdit object
myDTE = QtGui.QDateTimeEdit()

#get current date and time
now = QtCore.QDateTime.currentDateTime()

#set current date and time to the object
myDTE.setDateTime(now)

#set date only
today = QtCore.QDate.currentDate()
myDTE.setDate(today)

#set time only
this_moment = QtCore.QTime.currentTime()
myDTE.setTime(this_moment)

#set an arbitrary date
some_date = QtCore.QDate(2011,4,22) #Year, Month, Day
myDTE.setDate(some_date)

#set an arbitrary time
some_time = QtCore.QTime(16,33,15) #Hours, Minutes, Seconds (Only H and M required)
myDTE.setTime(some_time)

#set an arbitrary date and time
someDT = QtCore.QDateTime(2011,4,22,16,33,15)
myDTE.setDateTime(someDT)

相关问题 更多 >