QCalendarWidget的使用

void QCalendarWidget::activated ( const QDate & date )   [signal]

This signal is emitted whenever the user presses the Return or Enter key or double-clicks a date in the calendar widget.

void QCalendarWidget::clicked ( const QDate & date )   [signal]

This signal is emitted when a mouse button is clicked. The date the mouse was clicked on is specified by date. The signal is only emitted when clicked on a valid date, e.g., dates are not outside the minimumDate() and maximumDate(). If the selection mode is NoSelection, this signal will not be emitted.

通过文档我们可以看出来,是区分单击和双击的。

并且如果采用clicked信号,要注意设置sectionMode。

查了下文档,出了NoSelection就是SingleSelection,直接设为SingleSelection。

我现在假设实现:点击一个Button,然后弹出一个自带的calendar空间,然后选中一个,然后返回,在QLineEdit中输出。

构造函数如下:

ui.setupUi(this);
ui.calendarWidget->setMinimumDate(QDate(2006, 6, 19));

ui.calendarWidget->hide();
connect(ui.pushButton,SIGNAL(clicked()),ui.calendarWidget,SLOT(show()));
ui.calendarWidget->setSelectionMode(QCalendarWidget::SingleSelection);
connect(ui.calendarWidget,SIGNAL(clicked(const QDate &)),this,SLOT(setdate()));

原本的日历控件是隐藏的,点击后了就显示,然后选中,由setdate()函数负责在lineEdit里显示日期。

setdate()槽函数如下:

QDate date=ui.calendarWidget->selectedDate();
QString dtstr=date.toString("yyyy-MM-dd");
ui.lineEdit->setText(dtstr);
ui.calendarWidget->hide();


转自:http://www.cnblogs.com/quhongyue/p/3166421.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值