zoukankan      html  css  js  c++  java
  • 27.Qt时钟

    • myclock.h
       1 #ifndef MYCLOCK_H
       2 #define MYCLOCK_H
       3 
       4 #include <QObject>
       5 #include <QLCDNumber>
       6 #include <QWidget>
       7 #include <QMouseEvent>
       8 
       9 class myclock : public QLCDNumber
      10 {
      11     Q_OBJECT
      12 public:
      13     myclock(QWidget* parent=0);
      14     void mousePressEvent(QMouseEvent *event);
      15     void mouseMoveEvent(QMouseEvent *event);
      16 private:
      17     QPoint pos;
      18     bool showcolon;
      19 
      20 private slots:
      21     void showtime();
      22 };
      23 
      24 #endif // MYCLOCK_H
    • myclock.cpp 1 #include "myclock.h"
       2 #include <QTimer>
       3 #include <QTime>
       4 #include <QPalette>
       5 
       6 myclock::myclock(QWidget* parent):QLCDNumber(parent)
       7 {
       8     //设定颜色
       9     QPalette p = palette();
      10     p.setColor(QPalette::Window,Qt::blue);
      11     setPalette(p);
      12 
      13     //隐藏标题,关闭按钮
      14     setWindowFlags(Qt::FramelessWindowHint);
      15     //设置透明度
      16     setWindowOpacity(0.5);
      17 
         //创建事件空间 18 QTimer *timer = new QTimer(this);
      //与事件绑定
      19 connect(timer,SIGNAL(timeout()),this,SLOT(showtime()));
      //多长时间改变一次
      20 timer->start(1000);
      //显示时间
      21 showtime(); 22 resize(300,120); 23 } 24 25 void myclock::mousePressEvent(QMouseEvent *event) 26 { 27 28 } 29 30 void myclock::mouseMoveEvent(QMouseEvent *event) 31 { 32 33 } 34 35 void myclock::showtime() 36 { 37 QTime time = QTime::currentTime();//当前时间 38 QString str = time.toString("hh:mm:ss");//时间 39 this->display(str); 40 }
  • 相关阅读:
    python笔记第十一天 模块补充
    python笔记第十天 模块
    python笔记第九天 装饰器
    python笔记第八天 迭代器与生成器
    python笔记第七天 文件操作
    python笔记第六天 函数和函数的内置方法
    C语言----指针形参(指向指针的指针形参)
    NEON使用方法
    ARM NEON指令集总结
    三维变换矩阵左乘和右乘分析
  • 原文地址:https://www.cnblogs.com/xiaochi/p/8763402.html
Copyright © 2011-2022 走看看