Qt学习之日历(QCalendarWidget)

2018-03-27  本文已影响0人  阮明晨

1、QCalendarWidget calendar1 = new  QCalendarWidget(this);

2、获取系统时间:QDateTime now = QDateTime::currentDateTime();

再获取一个时间:QDateTime begin = new.addSecs(-2678400);//增加的是秒数

时间差

目的是起始时间和截止时间产生时间差。

3、QDateTime转换QDate

QDateTime now = QDateTime::currentDateTime();

QDate tmpdate;

tmpdate = now.date();

QDate转换QString:QString _tmpdate; _tmpdate = tmpdate.toString();

最后把字符串放入label中 textLabel = setText(_tmpdate);完成时间显示在界面中。

4、如何获取日历中你所选中的时间并且显示到当前界面中

首先connect(calendar1 ,SIGNAL(clicked(QDate)),this,SLOT(on_calendar1_clicked(QDate)));

接着完成槽函数:

void *******::on_calendar1_clicked(QDate Val)

{

    date1 = calaendar1->selectedDate();

    QString str;

    str = date1.toString("yyyy年MM月dd日");

    _textLabel->setText(str);

}

                 .                           

上一篇 下一篇

猜你喜欢

热点阅读