欧美大屁股bbbbxxxx,狼人大香伊蕉国产www亚洲,男ji大巴进入女人的视频小说,男人把ji大巴放进女人免费视频,免费情侣作爱视频

歡迎來到入門教程網(wǎng)!

C語言

當前位置:主頁 > 軟件編程 > C語言 >

QTimer與QTime實現(xiàn)電子時鐘

來源:本站原創(chuàng)|時間:2020-01-10|欄目:C語言|點擊: 次

本文實例為大家分享了QTimer與QTime實現(xiàn)電子時鐘的具體代碼,供大家參考,具體內容如下

使用QLCDNumber控件進行顯示

QLCDNumber控件默認只顯示5個字符,可以使用setDigitCount(int size)進行設置顯示個數(shù)

使用Display(QString str) 設置顯示內容

該函數(shù)擁有多個重載,字符 整型 浮點型都可以作為參數(shù) 

效果圖:

 

代碼:頭文件

#include <QLCDNumber>
 
class NumClock : public QLCDNumber
{
  Q_OBJECT
public:
  explicit NumClock(QWidget *parent = nullptr);
  void mousePressEvent(QMouseEvent *event);
  void mouseMoveEvent(QMouseEvent *event);
 
signals:
 
public slots:
  void updateTime();
 
private:
  QTimer * timer;
  QPoint mouseOfPonit; // 鼠標坐標跟窗口左上角坐標的偏移值
  bool showColon;       //是否顯示:
};

cpp文件:

#include "numclock.h"
#include <QTimer>
#include <QTime>
#include <QMouseEvent>
#include <QDebug>
 
NumClock::NumClock(QWidget *parent) : QLCDNumber(parent)
{
  timer = new QTimer(this);
  timer->setTimerType(Qt::PreciseTimer); // 設置精度為較高精度,差距在毫秒內
  timer->start(1000);
  connect(timer, SIGNAL(timeout()), this, SLOT(updateTime()),Qt::QueuedConnection);
 
  setWindowFlag(Qt::FramelessWindowHint); //沒有面板邊框標題欄的窗體
  setWindowOpacity(0.5); //設置窗口的透明度
 
  showColon = true;
 
  this->setDigitCount(8);
  resize(150, 100);
 
  updateTime();
 
 
  setAttribute(Qt::WA_DeleteOnClose);
}
 
void NumClock::mousePressEvent(QMouseEvent *event)
{
  if(event->button() == Qt::LeftButton){
    mouseOfPonit = event->globalPos() - this->pos();
    event->accept();
  }else{
    close();
  }
}
 
void NumClock::mouseMoveEvent(QMouseEvent *event)
{
  if(event->buttons() & Qt::LeftButton){
    move(event->globalPos() - mouseOfPonit);
    event->accept();
  }
}
 
void NumClock::updateTime()
{
  QString timeStr = QTime::currentTime().toString("hh:mm:ss");
  if(showColon){
    timeStr = timeStr.replace(QString(":"), QString(" "));
    qDebug() << timeStr;
    showColon = false;
  }else{
    timeStr = timeStr.replace(QString(" "), QString(":"));
    showColon = true;
    qDebug() << timeStr;
  }
  display(timeStr);
}

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持我們。

上一篇:C++執(zhí)行Linux Bash命令的方法

欄    目:C語言

下一篇:談談vector的特殊性之為什么它不是STL容器

本文標題:QTimer與QTime實現(xiàn)電子時鐘

本文地址:http://mengdiqiu.com.cn/a1/Cyuyan/228.html

網(wǎng)頁制作CMS教程網(wǎng)絡編程軟件編程腳本語言數(shù)據(jù)庫服務器

如果侵犯了您的權利,請與我們聯(lián)系,我們將在24小時內進行處理、任何非本站因素導致的法律后果,本站均不負任何責任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權所有