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. Properties Editor 中文编辑器 汉化

    韩梦飞沙  韩亚飞  313134555@qq.com  yue31313  han_meng_fei_sha 在Eclipse的 [Help]-> [ Install New Software ...

  2. 【20181030T1】排列树【树形结构+组合数】

    题面 [正解] 一眼找规律 --**这东西有啥规律啊 哎好像根节点是最小的 好像可以组合数分配子树大小,子树内部-- 可以递归啊! 乱搞一顿就好啦 过了大样例 复杂度\(O(N)\) 切完T2后T3水 ...

  3. 【最小割】BZOJ3894-文理分科

    [题目大意] 给定一个m*n的矩阵,每个格子的人可以学文或者学理,学文和学理各有一个满意度,如果以某人为中心的十字内所有人都学文或者学理还会得到一个额外满意度,求最大满意度之和. [思路] 发现这道题 ...

  4. l1和l2正则化的区别 - 面试错题集

    L0:计算非零个数,用于产生稀疏性,但是在实际研究中很少用,因为L0范数很难优化求解,是一个NP-hard问题,因此更多情况下我们是使用L1范数L1:计算绝对值之和,用以产生稀疏性,因为它是L0范式的 ...

  5. bzoj 2056: gift? 高精度?

    2056: gift? 高精度? Time Limit: 10 Sec  Memory Limit: 1 MB Description   Input 输入的第一行为一个整数t. 接下来t行,每行包含 ...

  6. Codeforces Round #202 (Div. 1) A. Mafia 贪心

    A. Mafia Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/348/problem/A D ...

  7. linux下svn的用法

    转载:http://blog.chinaunix.net/uid-22150747-id-189264.html 1.将文件checkout到本地目录 svn checkout path(path是服 ...

  8. Interactive Messager

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  9. Neo4j 使用cypher语言进行查询

    Neo4j是一个Java开发的图数据库,它将结构化数据存储在网络(从数学角度叫做图)上而不是表中.相对于关系数据库来说,图数据库善于处理大量复杂.互连接.低结构化的数据,这些数据变化迅速,需要频繁的查 ...

  10. zendstudio采用xdebug调试,断点不停的解决

    查看zendstudio里windows->preferences->PHP->PHP Executables,编辑列表项,弹出框的Debugger看看还是不是xdebug.