QtGui.QCalendarWidget
A 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的更多相关文章
- Qt4升级Qt5注意问题
Qt4升级Qt5注意问题 Qt4过渡到Qt5的项目一开始就受阻,记录一下遇到的下面的问题 --->编译遇到类似错误: error: QCalendarWidget: No such file o ...
- PyQt4日历部件QXalendarWidget
QCalendarWidget类提供了以月为单位地日历部件.该部件允许用户以一种简单而直接的方式选择日期. #!/usr/bin/python # -*- coding: utf-8 -*- impo ...
- ZetCode PyQt4 tutorial widgets I
#!/usr/bin/python # -*- coding: utf-8 -*- """ ZetCode PyQt4 tutorial In this example, ...
- PyQt4 进度条和日历 代码
# -*- coding: utf-8 -*- """ ------------------------------------------------- File Na ...
- 读Pyqt4教程,带你入门Pyqt4 _008
QCalendarWidget QCalendarWidget 提供基于月份的日历窗口组件,它允许用户简单并且直观的选择日期. #!/usr/bin/python # -*- coding: utf- ...
- GUI学习之三十—QCalendarWidget学习总结
今天学习的是最后一个展示控件——QCalendarWidget 一.描述 QCalendarWidget提供了一个基于每月的日历控件,允许用户选择一个日期,还可以看一下里面的图示: QCalendar ...
- PySide中QtGui.QFrame的用法
最近一位同事的出现让我重新正视PySide中designer这个工具的强大之处,通过QtGui.QObject.setGeometry(QtCore.QRect())这个最简单直接的方法可以完成很多复 ...
- 【PyQt5-Qt Designer】日历(QCalendarWidget)
日历(QCalendarWidget)+爬虫API调用+自定义发送信号(传入2个参数) 总体介绍 QCalendarWidget类提供了一个基日历小部件,允许用户选择一个日期. 该小部件使用当前的月份 ...
- QT5中无法包含Qtgui头文件的问题。
今天新学QT是,从一个ppt中边看边抄边学.前几页还能理解,但到了用纯源码写空白QT工程时,便遇到了一个问题.头文件里包含 #include <QtGui> 但是编译时总是出现下面图一中 ...
随机推荐
- 我的OI生涯 第五章
我的OI生涯 第五章 千古诗才,蓬莱文章建安骨 一身傲骨,青莲居士谪仙人 李白追月逆江河 包黑斩龙顺民心 豪气压群雄,能使力士脱靴,贵妃捧砚; 仙才媲众美,不让参军俊逸,开府清新 我辈此中惟饮酒 先生 ...
- 课堂实验-Bag
这次的课堂实验比较简单,但尴尬的是竟然没有做出来,自己的代码能力下降了不少.IDEA的Junit测试出了问题.所以这次实验是和结对伙伴结对编程写的. public class Bag<T> ...
- JDK源码(1.7) -- java.util.Deque<E>
java.util.Deque<E> 源码分析(JDK1.7) -------------------------------------------------------------- ...
- poj 3468 A Simple Problem with Integers 线段树区间加,区间查询和
A Simple Problem with Integers Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://poj.org/problem?i ...
- Unity Pivot/Center与Local/Global总结
Untiy左上角有两个按钮 Pivot/Center 和 Local/Global 它们叫做 变换Gizmo工具 Pivot/Center:现实游戏对象的轴心参考点.Center为以所有选中物体所 ...
- unix/linux中如何在vi编辑器中方便的跳转到首行和末行?
1.跳转到首行,:0/:1 2.跳转到末行,shift +g/G/:$
- XPath教程
XPath 简介 XPath 是一门在 XML 文档中查找信息的语言.XPath 可用来在 XML 文档中对元素和属性进行遍历. XPath 是 W3C XSLT 标准的主要元素,并且 XQuery ...
- SDRAM interface slashes pin count
Many designs need deep buffering but don't require ultrahigh-memory bandwidth. Examples include imag ...
- 解决/dev/fb0无法打开的问题
最近要在Linux做基于frame Buffer的图形显示,不论我在独立分区的Linux FC6系统中,还是在装有Red hat9的VPC中,都无法打开/dev/fb0.从网上找了很多资料,都没能解决 ...
- ARMv7处理器各个模式之间是怎样切换的?模式切换时上下文的保存哪些是硬件在做?哪些是操作系统在做?
1.ARM处理器各个模式之间是怎样切换的? 答:除用户模式外的其它6种模式称为特权模式,这些模式中,程序能够訪问全部系统资源,也能够随意进行处理器模式的切换.处理器模式能够通过软件控制进行切换(直接设 ...