当前位置:编程学习 > wap >>

qt5闹钟设计小问题

在网上下载的小程序,运行之后感觉定时功能不能用,对话框直接下降了,不知道是不是槽的设置有问题,哪位能不能帮我看下我程序中的问题呀?跪谢

private slots:
    void clockChange(); //更新时间
    void dialogUp();  //闹钟到了,提示框显示
    void mini();      //最小化到托盘
    void down();      //隐藏
    void comToCur();  //比较所显示时间和标准时间

void Alarm::init()
{
    //主界面设置

    setWindowTitle(tr("Alarm Clock"));
    setWindowIcon(QIcon(":/new/prefix1/icons/1.ico"));
    setFixedSize(QSize(300,80));

    //电子钟显示
    lcd=new QLCDNumber;
    lcd->setFixedSize(QSize(150,50));
    lcd->setDigitCount(10);
    lcd->setMode(QLCDNumber::Dec);
    lcd->setSegmentStyle(QLCDNumber::Filled);
    lcd->display(QTime::currentTime().toString("hh:mm:ss"));

    //闹钟界面显示
    label=new QLabel;
    label->setText(tr("闹钟"));
    timeEdit=new QTimeEdit;
    timeEdit->setDisplayFormat("hh:mm:ss");

    button=new QPushButton;
    button->setText("确定");

    //托盘设计

    trayIcon=new QSystemTrayIcon;
    trayIcon->setIcon(QIcon(":/new/prefix1/icons/1.ico"));
    trayIcon->show();
    setWindowIcon(QIcon(":/new/prefix1/icons/1.ico"));

    restoreAction=new QAction(this);
    restoreAction->setText(tr("显示"));

    quitAction=new QAction(this);
    quitAction->setText(tr("退出"));

    trayMenu=new QMenu;
    trayMenu->addAction(restoreAction);
    trayMenu->addAction(quitAction);
    trayIcon->setContextMenu(trayMenu);

    setWindowFlags(Qt::WindowStaysOnTopHint);

    //定时器的初始化
    timer =new QTimer;
    uptimer=new QTimer;
    downtimer=new QTimer;
    itimer=new QTimer;

}
//  ****************
//  connect 信号与槽
//  ****************

void Alarm::con()
{


    connect(timer,SIGNAL(timeout()),this,SLOT(clockChange()));
    timer->start(1000);

    connect(uptimer,SIGNAL(timeout()),this,SLOT(dialogUp()));
    uptimer->start(20);


    connect(button,SIGNAL(clicked()),this,SLOT(down()));

     connect(downtimer,SIGNAL(timeout()),this,SLOT(down()));
     downtimer->start(20);

    connect(itimer,SIGNAL(timeout()),this,SLOT(comToCur()));
    itimer->start(2000);


    connect(restoreAction,SIGNAL(triggered(bool)),uptimer,SIGNAL(timeout()));

    connect(this,SIGNAL(isCurrentTime()),uptimer,SIGNAL(timeout()));

    connect(quitAction,SIGNAL(triggered(bool)),this,SLOT(close()));
}


//  **************
//  显示变化的时间
//  **************
void Alarm::clockChange()
{
    lcd->display(QTime::currentTime().toString("hh:mm:ss"));
}

//  **************************
//  闹钟到了,提示框慢慢升起来
//  **************************
void Alarm::dialogUp()
{
    show();
    uptimer->start(2000);

    if(y>=rect.bottom()-height()-50)
    {
        y-=2;
    }
    else
    {
        uptimer->stop();
    }
      setGeometry(x,y,width(),height());
}

//  *************************
//  确定后,下降,然后隐藏起来
//  *************************

void Alarm::down()
{
    downtimer->start(2000);
    if(y<rect.bottom())
    {
       y+=height()+20;
    }
    else
    {
        downtimer->stop();
    }
   setGeometry(x,y,width(),height());
}

//  ************
//  最小化到托盘
//  ************

void Alarm::mini()

{
    hide();
}

//  ***********
//  close Event
//  ***********
void Alarm::closeEvent()
{
    QMessageBox::information(0,"quit","Are you sure exit the Application");

}

//  ****************************
//  对比现在时间,与所设置的时间
//  ****************************
void Alarm::comToCur()
{
    if (QTime::currentTime()>=timeEdit->time())
    {
        QApplication::beep();//响铃
        emit isCurrentTime();
    }
}
补充:移动开发 ,  Qt
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,