当前位置: 首页 > news >正文

qt代码练习

计时器练习

namespace Ui {
class third;
}class third : public QWidget
{Q_OBJECTpublic:explicit third(QWidget *parent = nullptr);~third();QLabel *labth1= new QLabel(this);QTextEdit *txtth1= new QTextEdit("闹钟",this);QLineEdit *leth1 = new QLineEdit(this);QPushButton *btnth1 = new QPushButton("开启",this);QPushButton *btnth2 = new QPushButton("关闭",this);QTimer *timeth = new QTimer(this);private:Ui::third *ui;int tid1;int tid2;void timerEvent(QTimerEvent *e);void timerout(QTimerEvent *eo);QTextToSpeech *speecher;signals:void back();void nowtime();
//    void outtime();
//    void spk();
public slots:void thjump_slot();
//    void out_time();
//    void my_spk();//定时器开关信号void btn_open();void btn_close();
};

cpp部分

third::third(QWidget *parent) :QWidget(parent),ui(new Ui::third)
{ui->setupUi(this);this->setFixedSize(800,500);this->setWindowTitle("Irenaの小屋");this->setWindowIcon(QIcon(":/icon/kirin1.png"));this->setStyleSheet("background-color:white;");this->setWindowOpacity(0.95);//labth1labth1->resize(150,60);labth1->move(100,30);labth1->setAlignment(Qt::AlignCenter);QFont size20;size20.setPointSize(20);labth1->setFont(size20);timerEvent(0);startTimer(1000);labth1->show();//labth2txtth1->resize(150,60);txtth1->move(200,150);//按钮——开启btnth1->move(350,80);btnth1->resize(50,30);btnth1->setIcon(QIcon(":/icon/king2.png"));btnth2->move(420,80);btnth2->resize(50,30);btnth2->setIcon(QIcon(":/icon/king2.png"));connect(btnth1,&QPushButton::clicked,this,&third::btn_open);connect(btnth2,&QPushButton::clicked,this,&third::btn_close);connect(timeth,SIGNAL(outtime()),this,SLOT(out_time()));//行编辑leth1->resize(140,30);leth1->move(330,45);speecher = new QTextToSpeech(this);}//菜单栏跳转
void third::thjump_slot()
{this->show();
}//定时器开启
void third::btn_open()
{btnth1->setEnabled(false);tid2 = startTimer(500);
}void third::btn_close()
{btnth1->setEnabled(false);leth1->clear();this->killTimer(tid2);}
void third::timerEvent(QTimerEvent *e)
{Q_UNUSED(e);labth1->setText(QTime::currentTime().toString("hh:mm:ss"));}void third::timerout(QTimerEvent *eo)
{if(eo->timerId() == tid2){if(leth1->text() == labth1->text() ){speecher->say(txtth1->toPlainText());}}
}

思维导图

 

http://www.lryc.cn/news/104170.html

相关文章:

  • PoseiSwap:首个基于模块化设施构建的订单簿 DEX
  • Linux NameSpace 虚拟化 资源隔离
  • 【Android Framework系列】第9章 AMS之Hook实现登录页跳转
  • 哪些行业需要连接云专线?
  • 【Mysql】group语句删除重复数据只保留一条
  • Git详解和命令大全
  • 北漂Java程序员入职五个月的收获总结
  • Android系统的进程管理(创建->优先级->回收)
  • C#界面美化小技巧
  • ‘vite‘ 不是内部或外部命令,也不是可运行的程序 或批处理文件。
  • Linux下查阅帮助文档必学命令 man
  • uniapp scroll-view显示滚动条
  • 15、PHP神奇的数组索引替代
  • 同为科技(TOWE)带热插拔功能机柜PDU插座的应用
  • GR5526 128BIT UUID改16BIT UUID
  • 【Android】使用 CameraX 实现基础拍照功能
  • 刷题笔记 day2
  • 回归预测 | MATLAB实现SO-CNN-LSTM蛇群算法优化卷积长短期记忆神经网络多输入单输出回归预测
  • 使用UltraISO制作麒麟v10系统盘
  • 【RabbitMQ】之消息的可靠性方案
  • 性能测试/负载测试/压力测试之间的区别
  • Mybatis ,Mybatis-plus列表多字段排序,包含sql以及warpper
  • sonarqube PHP编码规范检查
  • Kylin 麒麟 Qt软件 QtCreator 中文输入法问题
  • 租赁固定资产管理
  • 【Kubernetes】Kubernetes的概念
  • 抖音短视频seo源码矩阵系统开发
  • npm install pnpm -g报错解决!
  • vue2、vue3生命周期详解以及对比
  • JSON动态生成表格