QT 基础学习

#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);

    }
}











评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值