2012-07-16 32 views
1

就死在我的这部分程序..它似乎我不能找到如何做到这一点像样的 例子..PyQT4更改qDateTimeEdit时间值?

我有一个QDateTimeEdit对象 我已经显示其值设置为正是我现在的系统时间使用

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

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

现在我的问题是.. 我想设置12:00: 00 AM11:59:59 PM

我该怎么办?

感谢任何人愿意花时间在我的问题上。

回答

6

基本上有三种不同的对象,你可以在PyQt的使用:

  • QDATE

  • QTIME

  • QDateTime

的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) 
+0

非常感谢dex19dt!这个样本真的很好,对我的水平的人更好。 – Katherina 2012-07-17 01:50:39