PyQt5 DateEdit用法 PyQt5-QDateEdit的简单使用操作

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

PyQt5 DateEdit用法 PyQt5-QDateEdit的简单使用操作

天道酬勤2016   2021-01-29 我要评论

使用PyQt5开发图形界面,里面使用日期框,这里把这个QDateEdit组件命名为:beginDate

from PyQt5.QtCore import QDate

1.初始化赋值,不设置则默认为2000/1/1,这里默认为当天日期

self.beginDate.setDate(QDate.currentDate())

2.读取选择后的日期

sBeginDate = self.beginDate.date().toString(Qt.ISODate)

print(sBeginDate)

显示日期格式:

yyyy-mm-dd

如:2019-07-30

网上查到的资料很多都是赋值的,没有说明如何读取,这里主要是记录下如何读取,其它的可参考网上的资料。

补充知识:pyqt中QDateTimeEdit/QDateEdit相关使用方法

QDateTimeEdit/QDateEdit

clear (self)
QDate date (self)
QDateTime dateTime (self)
setDate (self, QDate date)
setDateTime (self, QDateTime dateTime)
setTime (self, QTime time)
QTime time (self)

now_day = time.strftime("%Y-%m-%d", time.localtime())
self.dateEdit.setDate(QDate.fromString(now_day, 'yyyy-MM-dd'))

now_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
self.dateTimeEdit.setDateTime(QDateTime.fromString(now_time, 'yyyy-MM-dd hh:mm:ss'))

QDate

QDate currentDate ()
QDate fromString (QString s, QString format)
QString toString (self, QString format)
(int year, int month, int day) getDate (self)
int day (self)
int month (self)
int year (self)

QDateTime

QDateTime currentDateTime ()
QDateTime fromString (QString s, QString format)
QString toString (self, QString format)
QDate date (self)
QTime time (self)

start_time = self.dateTimeEdit.dateTime()
end_time = self.dateTimeEdit_2.dateTime()

以上这篇PyQt5-QDateEdit的简单使用操作就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们