PyQT4更改qDateTimeEdit时间值? [英] PyQT4 change qDateTimeEdit time value?

查看:858
本文介绍了PyQT4更改qDateTimeEdit时间值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

被困在我的程序的这一部分..似乎我找不到一个体面的
的例子如何做到这一点..

got stuck on this part of my program.. and it seems i cant find a decent example of how to do this..

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

i got a QDateTimeEdit object i already set its displaying value to what my current system time is using

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

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

现在我的问题是..
i想设置 12:00:00 AM to 11:59:59 PM

Now my problem is.. i want to set 12:00:00 AM to 11:59:59 PM

我该怎么办?

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

thanks to anyone willing to spend time on my question.

推荐答案

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

There are basically three different objects you can use in PyQt:


  • QDate

  • QDate

QTime

QDateTime

QDateTime

QDateTime接受其他两种类型。因此,您可以使用QDate实例定义QDateTime对象的日期,并且可以使用QTime来完成此操作。

The QDateTime accepts the other two types. So you can define the date of a QDateTime Object using a QDate instance and the same can be done with QTime.

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

Obviously, if you're trying to change the time you need to use a QTime object.

以下是一些示例:

#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)

这篇关于PyQT4更改qDateTimeEdit时间值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆