QtGui.QCalendarWidget provides a monthly based calendar widget. It allows a user to select a date in a simple and intuitive way.

#!/usr/bin/python
# -*- coding: utf-8 -*- """
ZetCode PyQt4 tutorial This example shows a QtGui.QCalendarWidget widget. author: Jan Bodnar
website: zetcode.com
last edited: September 2011
""" import sys
from PyQt4 import QtGui, QtCore class Example(QtGui.QWidget): def __init__(self):
super(Example, self).__init__() self.initUI() def initUI(self): cal = QtGui.QCalendarWidget(self)
cal.setGridVisible(True)
cal.move(20, 20)
cal.clicked[QtCore.QDate].connect(self.showDate) self.lbl = QtGui.QLabel(self)
date = cal.selectedDate()
self.lbl.setText(date.toString())
self.lbl.move(130, 260) self.setGeometry(300, 300, 350, 300)
self.setWindowTitle('Calendar')
self.show() def showDate(self, date): self.lbl.setText(date.toString()) def main(): app = QtGui.QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_()) if __name__ == '__main__':
main()

The example has a calendar widget and a label widget. The currently selected date is displayed in the label widget.

cal = QtGui.QCalendarWidget(self)

We construct a calendar widget.

cal.clicked[QtCore.QDate].connect(self.showDate)

If we select a date from the widget, a clicked[QtCore.QDate] signal is emitted. We connect this signal to the user defined showDate() method.

def showDate(self, date):
self.lbl.setText(date.toString())

We retrieve the selected date by calling the selectedDate() method. Then we transform the date object into string and set it to the label widget.

Figure: QtGui.QCalendarWidget

QtGui.QCalendarWidget的更多相关文章

  1. Qt4升级Qt5注意问题

    Qt4升级Qt5注意问题 Qt4过渡到Qt5的项目一开始就受阻,记录一下遇到的下面的问题 --->编译遇到类似错误: error: QCalendarWidget: No such file o ...

  2. PyQt4日历部件QXalendarWidget

    QCalendarWidget类提供了以月为单位地日历部件.该部件允许用户以一种简单而直接的方式选择日期. #!/usr/bin/python # -*- coding: utf-8 -*- impo ...

  3. ZetCode PyQt4 tutorial widgets I

    #!/usr/bin/python # -*- coding: utf-8 -*- """ ZetCode PyQt4 tutorial In this example, ...

  4. PyQt4 进度条和日历 代码

    # -*- coding: utf-8 -*- """ ------------------------------------------------- File Na ...

  5. 读Pyqt4教程,带你入门Pyqt4 _008

    QCalendarWidget QCalendarWidget 提供基于月份的日历窗口组件,它允许用户简单并且直观的选择日期. #!/usr/bin/python # -*- coding: utf- ...

  6. GUI学习之三十—QCalendarWidget学习总结

    今天学习的是最后一个展示控件——QCalendarWidget 一.描述 QCalendarWidget提供了一个基于每月的日历控件,允许用户选择一个日期,还可以看一下里面的图示: QCalendar ...

  7. PySide中QtGui.QFrame的用法

    最近一位同事的出现让我重新正视PySide中designer这个工具的强大之处,通过QtGui.QObject.setGeometry(QtCore.QRect())这个最简单直接的方法可以完成很多复 ...

  8. 【PyQt5-Qt Designer】日历(QCalendarWidget)

    日历(QCalendarWidget)+爬虫API调用+自定义发送信号(传入2个参数) 总体介绍 QCalendarWidget类提供了一个基日历小部件,允许用户选择一个日期. 该小部件使用当前的月份 ...

  9. QT5中无法包含Qtgui头文件的问题。

    今天新学QT是,从一个ppt中边看边抄边学.前几页还能理解,但到了用纯源码写空白QT工程时,便遇到了一个问题.头文件里包含 #include  <QtGui> 但是编译时总是出现下面图一中 ...

随机推荐

  1. 51nod1819 黑白树V2

    简单的题面 给定一棵以1为根的有根树,点可能是黑色或白色,操作如下. 1. 选定一个点x,将x的子树中所有到x的距离为奇数的点的颜色反转.2. 选定一个点x,将点x的颜色反转.3. 选定一个点x,询问 ...

  2. Mac 配置几个环境变量

    终端    open -t ~/.bash_profile  打开.bash_profile export PATH=${PATH}:/Users/maxinliang/Android/sdk/pla ...

  3. ios开发中object-c中UTF-8 和 GBK 的 NSString 相互转化的方法

    应用都要遇到一个很头疼的问题:文字编码,汉字的 GBK 和 国际通用的 UTF-8 的互相转化稍一不慎, 就会满屏乱码.下面介绍 UTF-8 和 GBK 的 NSString 相互转化的方法   NS ...

  4. ARM 调用约定 calling convention

    int bar( int a, int b, int c, int d, int e, int f, int g ) { ]; array2[ ] = a + b; array2[ ] = b + c ...

  5. sql server datetime类型字段使用isnull返回1900-01-01 00:00:00.000的问题

    若字段定义的类型为datetime,插入为''(空),那么会默认值为1900-01-01 00:00:00.000 解决方法查询的时候过滤下cast(nullif('','') as datetime ...

  6. OpenGl的源程序,运行就提示,"计算机丢失 glut32.dll文件"

    转自:http://www.cppblog.com/longzxr/archive/2009/12/04/102565.html?opt=admin 今天调试OpenGl的源程序,编译通过,但一运行就 ...

  7. 提高软件质量实践——Facebook 篇

    提高软件质量实践——Facebook 篇 Facebook 从 2004 年的哈佛校园的学生项目在短短的 7~8 年的时间中快速增长为拥有 10 亿用户的世界上最大的社交网络,又一次见证了互联网创业成 ...

  8. python -m xxx.py和python xxx.py的区别

    先看下python -m site作用是显示sys.path的值内容,也就是python搜索模块的目录,作用类似于linux下的PATH python -m SimpleHTTPServer 会在sy ...

  9. iOS:CoreData数据库的使用一(创建单个数据库表)

    CoreData数据库框架:mac系统自带的数据库,它是苹果公司对sqlite进行封装而来的,既提供了对数据库的主要操作,也提供了具体的视图关系模型. 需要用到三个对象: 1•Managed Obje ...

  10. 数学图形(1.39)TN constant curve

    这是个类似巴黎铁塔的曲线. #http://www.mathcurve.com/courbes2d/tn/tn.shtml vertices = t = to (PI*0.999) a = s = s ...