PyQt5-QDateEdit的简单使用操作
使用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的简单使用操作就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。
相关文章
Python pywifi ERROR Open handle fai
这篇文章主要介绍了Python pywifi ERROR Open handle failed问题及解决方案,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教2023-06-06详解Django中views数据查询使用locals()函数进行优化
这篇文章主要介绍了Django中views数据查询使用locals()函数进行优化,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧2020-08-08解决Python找不到ssl模块问题 No module named _ssl的方法
这篇文章主要介绍了解决Python找不到ssl模块问题 No module named _ssl的方法,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧2019-04-04
最新评论