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 }
  • 相关阅读:
    css变量
    es6的this指向
    Java面试题(包装类)
    moment笔记
    Class
    CSS斜切角
    Element.getBoundingClientRect()
    Do not mutate vuex store state outside mutation handlers.
    antd不想写那么多option怎么办
    解析URL参数
  • 原文地址:https://www.cnblogs.com/xiaochi/p/8763402.html
Copyright © 2011-2022 走看看