登录界面

second.h
#ifndef SECOND_H
#define SECOND_H#include <QWidget>namespace Ui {
class Second;
}class Second : public QWidget
{Q_OBJECTpublic:explicit Second(QWidget *parent = nullptr);~Second();
public slots:void mySlot();
private:Ui::Second *ui;
};#endif // SECOND_H
widget.h
#ifndef WIDGET_H
#define WIDGET_H#include <QWidget>
#include <QMessageBox>
QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACEclass Widget : public QWidget
{Q_OBJECTpublic:Widget(QWidget *parent = nullptr);~Widget();private slots:void on_pushButton_clicked();void on_closeButton_clicked();void on_shrinkButton_clicked();void on_cancelButton_clicked();signals:void jumpToSecondWindow();
private:Ui::Widget *ui;
};
#endif // WIDGET_H
main.cpp
#include "widget.h"
#include "second.h"
#include <QApplication>int main(int argc, char *argv[])
{QApplication a(argc, argv);Widget w;w.show();Second s;QObject::connect(&w, &Widget::jumpToSecondWindow, &s, &Second::mySlot);return a.exec();
}
second.cpp
#include "second.h"
#include "ui_second.h"Second::Second(QWidget *parent) :QWidget(parent),ui(new Ui::Second)
{ui->setupUi(this);
}Second::~Second()
{delete ui;
}void Second::mySlot()
{show();
}
widget.cpp
#include "widget.h"
#include "ui_widget.h"Widget::Widget(QWidget *parent): QWidget(parent), ui(new Ui::Widget)
{ui->setupUi(this);setWindowFlag(Qt::FramelessWindowHint);// 去掉空白setAttribute(Qt::WA_TranslucentBackground);
}Widget::~Widget()
{delete ui;
}void Widget::on_pushButton_clicked()
{if(ui->actLineEdit->text() == "admin" && ui->pwdLineEdit->text() == "123456"){// int ret = QMessageBox::information(this, "Login Success", "登录成功!");QMessageBox msg;msg.setIcon(QMessageBox::Information);msg.setStandardButtons(QMessageBox::Ok);msg.setText("登录成功");msg.setInformativeText("!!!!!!!!!");int ret = msg.exec();if(ret == QMessageBox::Ok){close();emit jumpToSecondWindow();}}else{int ret = QMessageBox::critical(this, "Login Error", "账号或密码错误!", QMessageBox::Yes | QMessageBox::No);if(ret == QMessageBox::Yes){// 清空账号和密码输入行ui->actLineEdit->clear();ui->pwdLineEdit->clear();}else{close();}}
}void Widget::on_closeButton_clicked()
{close();
}void Widget::on_shrinkButton_clicked()
{showMinimized();
}void Widget::on_cancelButton_clicked()
{QMessageBox msg(QMessageBox::Question, "退出确认", "您是否确定要退出登录?", QMessageBox::Yes | QMessageBox::No, this);int ret = msg.exec();if(ret == QMessageBox::Yes){close();}
}
闹钟

widget.h
#ifndef WIDGET_H
#define WIDGET_H#include <QWidget>
#include <QTime>
#include <QTextToSpeech>
QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACEclass Widget : public QWidget
{Q_OBJECTpublic:Widget(QWidget *parent = nullptr);~Widget();void timerEvent(QTimerEvent *e);QString showTime();private slots:void on_pushButton_clicked();private:Ui::Widget *ui;QTextToSpeech * speecher;QString time;
};
#endif // WIDGET_H
widget.cpp
#include "widget.h"
#include "ui_widget.h"Widget::Widget(QWidget *parent): QWidget(parent), ui(new Ui::Widget), speecher(new QTextToSpeech(this))
{ui->setupUi(this);showTime();startTimer(1000);ui->hourLineEdit->setPlaceholderText("时");ui->minuteLineEdit->setPlaceholderText("分");ui->secondLineEdit->setPlaceholderText("秒");
}Widget::~Widget()
{delete ui;
}void Widget::timerEvent(QTimerEvent *e)
{QString currentTime = showTime();if (currentTime == time){QString hintMsg = "这个年纪你怎么,睡得着啊!!!!!";ui->hintLabel->setText(hintMsg);int *count = new int(0);connect(speecher, &QTextToSpeech::stateChanged, this, [=]()mutable{if (speecher->state() == QTextToSpeech::Ready){(*count)++;if (*count == 5){ui->hintLabel->clear();delete count;return;}speecher->say(hintMsg);}});speecher->say(hintMsg); // 开始第一次读}
}QString Widget::showTime()
{QTime currentTime = QTime::currentTime();// 将QTime时间格式转换为QString类QString t = currentTime.toString("hh:mm:ss");ui->timeLabel->setText(t);return t;
}void Widget::on_pushButton_clicked()
{time = ui->hourLineEdit->text()+":"+ui->minuteLineEdit->text()+":"+ui->secondLineEdit->text();ui->timeListLabel->setText(ui->timeListLabel->text()+time+";");
}
