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. java 线程 wait join sleep yield notify notifyall synchronized

    韩梦飞沙  韩亚飞  313134555@qq.com  yue31313  han_meng_fei_sha 休息方法 : 在指定时间内 让该线程 暂停, 不会释放 锁标志. 等待方法: 让 该 线 ...

  2. padding Oracle attack(填充Oracle攻击)

    最近学习到一种老式的漏洞,一种基于填充字节的漏洞.就想记录下来,早在2010年的blackhat大会上,就介绍了padding Oracle漏洞,并公布了ASP.NET存在该漏洞.2011年又被评选为 ...

  3. poj 1984 并查集

    题目意思是一个图中,只有上下左右四个方向的边.给出这样的一些边, 求任意指定的2个节点之间的距离. 就是看不懂,怎么破 /* POJ 1984 并查集 */ #include <stdio.h& ...

  4. C++ -- STL泛型编程(一)之vector

    STL提供三种组件:容器,迭代器,算法,它们都支持泛型程序设计标准容器有两类:顺序容器和关联容器. 顺序容器(vector,list,deque,string等)是一系列元素的有序组合. 关联容器(s ...

  5. HDU 5640 King's Cake GCD

    King's Cake 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5640 Description It is the king's birthd ...

  6. myBatis 切换数据源(spring事务)理解

    1. mybatis (SqlSessionTemplate)的动态代理 a) sqlSession的结构 b)SqlSession 结构 public class SqlSessionTemplat ...

  7. .NET 中字符文本中的字符太多 错误处理

    错误截图   问题描述    在ASP.NET中使用多层引号,要引起注意,引号使用不当会引起“字符文本中字段太多”编译错误!今天我就遇到了这个错误,整理于此!     “字符文本中字段太多”错误提示过 ...

  8. HDU 4667 Building Fence(2013多校7 1002题 计算几何,凸包,圆和三角形)

    Building Fence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)To ...

  9. Virtual Treeview - Paint cycles and stages

    The most complex process in Virtual Treeview is without doubts its painting. Read here what stages V ...

  10. 如何屏蔽PHP浏览器头信息X-Powered-By

    将 php.ini 中,将 “expose_php = On” 改为 “expose_php = Off”