闲来无事实现个备忘录,到点提醒

直接看代码吧。反正贼简单。

#include "widget.h"
#include <QHBoxLayout>
#include <QMessageBox>
#include <windows.h>
#include <qdebug.h>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
{
    QFont textFont;
    textFont.setPointSize(12);
    textFont.setFamily("Microsoft YaHei");
    QWidget *topWgt=new QWidget(this);
    m_pOkBtn=new QPushButton(tr("OK"),this);
    m_pToolsEdit=new QTextEdit(this);
    m_pTimeEdit=new QDateTimeEdit(this);
    QDateTime dateTime=QDateTime::currentDateTime();
    m_pTimeEdit->setDateTime(dateTime);

    m_pOkBtn->setFont(textFont);
    m_pToolsEdit->setFont(textFont);
    m_pTimeEdit->setFont(textFont);

    QHBoxLayout *topLayout=new QHBoxLayout(this);
    topLayout->addWidget(m_pTimeEdit);
    topLayout->addWidget(m_pOkBtn);
    topLayout->setMargin(0);
    topLayout->setSpacing(10);
    topWgt->setLayout(topLayout);

    QVBoxLayout *mainLayout=new QVBoxLayout(this);
    mainLayout->addWidget(topWgt);
    mainLayout->addWidget(m_pToolsEdit);
    mainLayout->setMargin(10);
    mainLayout->setSpacing(5);
    this->setLayout(mainLayout);

    this->resize(200,300);

    connect(m_pOkBtn,&QPushButton::clicked,this,&Widget::onOkClicked);
}

Widget::~Widget()
{
}

void Widget::onOkClicked()
{
    this->showMinimized();
    QString strText=m_pToolsEdit->toPlainText();
    if(strText!="")
    {
        QDateTime setTime=m_pTimeEdit->dateTime();
        QDateTime currentTime=QDateTime::currentDateTime();
        int setTime_t=setTime.toTime_t();
        int currentTime_t=currentTime.toTime_t();
        if(setTime_t-currentTime_t>0)
        {
            while (true) {
                QDateTime thisTime=QDateTime::currentDateTime();
                int thisTime_t=thisTime.toTime_t();
                if(thisTime_t==setTime_t)
                {
                    QMessageBox::warning(this, tr("Memorandum"),
                                                    "Don't forget\n"+strText,
                                                    QMessageBox::Ok);
                    break;
                }

                Sleep(1000);

            }
        }
        else
        {
            QMessageBox::warning(this, tr("Memorandum"),
                                            "Setting Time Cannot Lessthan CurrentTime!!",
                                            QMessageBox::Ok);
        }
    }
    else {
        QMessageBox::warning(this, tr("Memorandum"),
                                        "Infomation is NULL!!",
                                        QMessageBox::Ok);
    }


}


就是简单的定时功能。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

加油小杜(接qt定制功能,单模块开发等)

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值