#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
ui->setupUi(this);
//固定窗口大小,并且取消窗头
this->setFixedSize(500,300);
// this->setWindowFlag(Qt::FramelessWindowHint);
//设置窗口的背景颜色为蓝色
//this->setWindowTitle("学习计时器");
this->setStyleSheet("background-color:skyblue");
//创建两个个label 一个lineedit 两个pushbutton
btn1 = new QPushButton("确认",this);
btn2 = new QPushButton("取消",this);
lab1 = new QLabel(this);
edit1 = new QLineEdit(this);
edit2 = new QTextEdit(this);
//移动每个对象
btn1->resize(85,30);
btn1->move(270,85);
btn2->resize(85,30);
btn2->move(395,btn1->y());
lab1->resize(230,100);
lab1->move(10,10);
lab1->setStyleSheet("background-color:white");
QFont t1;
t1.setPointSize(40);
this->lab1->setFont(t1);
edit1->resize(210,60);
edit1->move(btn1->x(),10);
edit1->setStyleSheet("background-color:white");
t1.setPointSize(25);
this->edit1->setFont(t1);
this->edit1->setAlignment(Qt::AlignCenter);
edit2->resize(480,150);
edit2->move(10,120);
edit2->setStyleSheet("background-color:white");
t1.setPointSize(14);
this->edit2->setFont(t1);
//将系统时间写入到lab1
tm1.start(1000);
connect(&tm1,&QTimer::timeout,this,&Widget::timeout_slot);
//点击按钮之后,开启lab1的计数器
connect(&tm2,&QTimer::timeout,this,&Widget::timeout_slot2);
//将btn1绑定到事件
connect(btn1,&QPushButton::clicked,this,&Widget::on_btn1_clicked);
}
Widget::~Widget()
{
delete ui;
}
void Widget::on_btn1_clicked()
{
tm2.start(1000);
btn1->setEnabled(false);
edit1->setEnabled(false);
}
void Widget::on_btn2_clicked()
{
this->close();
}
void Widget::timeout_slot()
{
QTime systime=QTime::currentTime();
QString tm =systime.toString("hh:mm:ss");
this->lab1->setText(tm);
this->lab1->setAlignment(Qt::AlignCenter);
}
void Widget::timeout_slot2()
{
if(lab1->text()==edit1->text())
{
QMessageBox box(QMessageBox::Information, //图标
"提示", //对话框标题
"时间到了", //对话框文本内容
QMessageBox::Ok, //提供的按钮
this);
box.exec();
tm2.stop();
btn1->setEnabled(true);
edit1->setEnabled(true);
}
}
QT 基础学习
最新推荐文章于 2024-10-12 18:12:14 发布