最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Qt實(shí)現(xiàn)簡(jiǎn)易時(shí)鐘

 更新時(shí)間:2020年07月12日 10:19:28   作者:PlanetRT  
這篇文章主要為大家詳細(xì)介紹了Qt實(shí)現(xiàn)簡(jiǎn)易時(shí)鐘,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Qt實(shí)現(xiàn)簡(jiǎn)易時(shí)鐘展示的具體代碼,供大家參考,具體內(nèi)容如下

一、效果展示

簡(jiǎn)單實(shí)現(xiàn)時(shí)鐘(圓盤+QLCDNumber),大小刻度,數(shù)字等。

二、實(shí)現(xiàn)

.pro

QT  += core gui
 
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
 
CONFIG += c++11
 
# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
 
# You can also make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
 
SOURCES += \
 main.cpp \
 mainwindow.cpp
 
HEADERS += \
 mainwindow.h
 
FORMS += \
 mainwindow.ui
 
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
 
RESOURCES += \
 image.qrc

.h

#ifndef MAINWINDOW_H
#define MAINWINDOW_H
 
#include <QMainWindow>
#include <QDateTime>
 
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE
 
class MainWindow : public QMainWindow
{
 Q_OBJECT
 
public:
 MainWindow(QWidget *parent = nullptr);
 ~MainWindow();
 void paintEvent(QPaintEvent *event);
 bool showColon = false;
public slots:
 void countTime();
 
private:
 Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H

.cpp

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include<QPainter>
#include<QTimer>
#include<QTime>
#include<QString>
 
MainWindow::MainWindow(QWidget *parent)
 : QMainWindow(parent)
 , ui(new Ui::MainWindow)
{
 ui->setupUi(this);
 
 QTimer *timer = new QTimer(this);
 connect(timer, SIGNAL(timeout()), this, SLOT(update()));
 connect(timer, SIGNAL(timeout()), this, SLOT(countTime()));
 timer->start(1000);
 countTime();
 
 setWindowTitle(tr("Clock_by_Xr"));
 setFixedSize(800, 400);
 
}
 
MainWindow::~MainWindow()
{
 delete ui;
}
 
void MainWindow::paintEvent(QPaintEvent *event){
 static QPoint hourHand[3] = {
  QPoint(5, 3),
  QPoint(-5, 3),
  QPoint(0, -30)
 };
 static QPoint minuteHand[3] = {
  QPoint(4, 6),
  QPoint(-4, 6),
  QPoint(0, -45)
 };
 static QPoint secondHand[3] = {
  QPoint(2, 10),
  QPoint(-2, 10),
  QPoint(0, -60)
 };
 
 
 //顏色
 QColor hourColor(0, 185, 211, 238);
 QColor minuteColor(0, 96, 123, 139);
 QColor secondColor(0, 176, 226, 255);
 
 int side = qMin(width(), height());
 QTime time = QTime::currentTime();
 
 QPainter painter(this);
 painter.setRenderHint(QPainter::Antialiasing);
 //表盤
 QBrush brush1(QColor(164,211,238));
 QPen pen1(QColor(164,211,238));
 painter.setBrush(brush1);
 painter.setPen(pen1);
 painter.drawEllipse(QPoint(200,200),200/3*2,200/3*2);
 
 QBrush brush2(QColor(245,245,245));
 QPen pen2(QColor(245,245,245));
 painter.setBrush(brush2);
 painter.setPen(pen2);
 painter.drawEllipse(QPoint(200,200),194/3*2,194/3*2);
 
 QBrush brush3(QColor(250,250,250));
 QPen pen3(QColor(250,250,250));
 painter.setBrush(brush3);
 painter.setPen(pen3);
 painter.drawEllipse(QPoint(200,200),183/3*2,183/3*2);
 
 QBrush brush4(QColor(255,255,255));
 QPen pen4(QColor(255,255,255));
 painter.setBrush(brush4);
 painter.setPen(pen4);
 painter.drawEllipse(QPoint(200,200),175/3*2,175/3*2);
 
 painter.setRenderHint(QPainter::Antialiasing);
 painter.translate(width()/4, height()/2);
 painter.scale(side/200.0, side/200.0);
 
 painter.setPen(Qt::NoPen);
 painter.setBrush(hourColor);
 
 painter.save();
 painter.rotate(30.0 * ((time.hour() + time.minute() / 60.0)));
 painter.drawConvexPolygon(hourHand, 3);
 painter.restore();
 
 //刻度
 painter.setPen(hourColor);
 for (int i = 0; i < 12; ++i) {
 
  painter.rotate(30.0);
  painter.drawLine(66,0,72,0);
  painter.drawText(-15, -65, 30, 30,Qt::AlignHCenter,QString::number(i+1));
 }
 
 //分鐘
 painter.setPen(Qt::NoPen);
 painter.setBrush(minuteColor);
 
 painter.save();
 painter.rotate(6.0 * (time.minute() + time.second() / 60.0));
 painter.drawConvexPolygon(minuteHand, 3);
 painter.restore();
 
 painter.setPen(minuteColor);
 for (int j = 0; j < 60; ++j) {
  if ((j % 5) != 0)
   painter.drawLine(68, 0, 72, 0);
  painter.rotate(6.0);
 }
 
 //秒鐘
 painter.setPen(Qt::NoPen);
 painter.setBrush(secondColor);
 
 painter.save();
 painter.rotate(6.0 * time.second());
 painter.drawConvexPolygon(secondHand, 3);
 painter.restore();
 
 painter.end();
}
 
void MainWindow::countTime(){
 QTime t = QTime::currentTime();
 QString text=t.toString("hh:mm:ss");
 if(showColon){
  text[2] = ':';
  text[5] = ':';
  showColon = false;
 }
 else{
  text[2] = ' ';
  text[5] = ' ';
  showColon = true;
 }
 ui->lcdNumber->display(text);
 ui->lcdNumber_2->display(text);
}

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • C語(yǔ)言 CRITICAL_SECTION用法案例詳解

    C語(yǔ)言 CRITICAL_SECTION用法案例詳解

    這篇文章主要介紹了C語(yǔ)言 CRITICAL_SECTION用法案例詳解,本篇文章通過(guò)簡(jiǎn)要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下
    2021-08-08
  • 使用kendynet構(gòu)建異步redis訪問(wèn)服務(wù)

    使用kendynet構(gòu)建異步redis訪問(wèn)服務(wù)

    這篇文章主要介紹了在kendynet上寫的一個(gè)簡(jiǎn)單的redis異步訪問(wèn)接口,大家參考使用吧
    2014-01-01
  • 基于Matlab制作一個(gè)不良圖片檢測(cè)系統(tǒng)

    基于Matlab制作一個(gè)不良圖片檢測(cè)系統(tǒng)

    這篇文章主要為大家詳細(xì)介紹了如何基于Matlab制作一個(gè)不良圖片檢測(cè)系統(tǒng),文中的示例代碼講解詳細(xì),感興趣的可以跟隨小編一起了解一下
    2022-07-07
  • C++消息隊(duì)列(定義,結(jié)構(gòu),如何創(chuàng)建,發(fā)送與接收)

    C++消息隊(duì)列(定義,結(jié)構(gòu),如何創(chuàng)建,發(fā)送與接收)

    這篇文章主要介紹了C++消息隊(duì)列(定義,結(jié)構(gòu),如何創(chuàng)建,發(fā)送與接收),消息隊(duì)列是一種先進(jìn)先出的隊(duì)列型數(shù)據(jù)結(jié)構(gòu),實(shí)際上是系統(tǒng)內(nèi)核中的一個(gè)內(nèi)部鏈表
    2022-08-08
  • C語(yǔ)言自研定時(shí)器計(jì)劃任務(wù)語(yǔ)法詳解

    C語(yǔ)言自研定時(shí)器計(jì)劃任務(wù)語(yǔ)法詳解

    市面主流定時(shí)器計(jì)劃任務(wù)語(yǔ)法: cron ,但是使用起來(lái)非常難受,設(shè)計(jì)的比較非人性話語(yǔ)法,我想一般人都沒(méi)幾個(gè)記住的,所以本文將自研定時(shí)器計(jì)劃任務(wù)語(yǔ)法,需要的可以參考一下
    2022-09-09
  • C語(yǔ)言完美實(shí)現(xiàn)動(dòng)態(tài)數(shù)組代碼分享

    C語(yǔ)言完美實(shí)現(xiàn)動(dòng)態(tài)數(shù)組代碼分享

    本文給大家分享的是一則使用C語(yǔ)言實(shí)現(xiàn)動(dòng)態(tài)數(shù)組的代碼,完美解決內(nèi)存溢出以及內(nèi)存回收問(wèn)題,有需要的小伙伴可以參考下。
    2016-02-02
  • 詳解C語(yǔ)言中的字符串拼接(堆與棧)

    詳解C語(yǔ)言中的字符串拼接(堆與棧)

    這篇文章主要介紹了C語(yǔ)言中字符串拼接(堆與棧)的相關(guān)資料,文中通過(guò)一段示例代碼詳細(xì)介紹了關(guān)于C語(yǔ)言中的字符串拼接問(wèn)題,有需要的朋友可以參考借鑒,下面來(lái)一起看看吧。
    2017-01-01
  • C++優(yōu)先隊(duì)列的使用小結(jié)

    C++優(yōu)先隊(duì)列的使用小結(jié)

    普通的隊(duì)列是一種先進(jìn)先出的數(shù)據(jù)結(jié)構(gòu),元素在隊(duì)列尾追加,而從隊(duì)列頭刪除,在優(yōu)先隊(duì)列中,元素被賦予優(yōu)先級(jí),本文主要介紹了C++優(yōu)先隊(duì)列的使用,感興趣的可以了解一下
    2023-11-11
  • C++中l(wèi)ist容器的實(shí)現(xiàn)

    C++中l(wèi)ist容器的實(shí)現(xiàn)

    本文主要介紹了C++中l(wèi)ist容器的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2023-03-03
  • Qt 使用 canon edsdk 實(shí)現(xiàn)實(shí)時(shí)預(yù)覽的示例代碼

    Qt 使用 canon edsdk 實(shí)現(xiàn)實(shí)時(shí)預(yù)覽的示例代碼

    這篇文章主要介紹了Qt 使用 canon edsdk 實(shí)現(xiàn)實(shí)時(shí)預(yù)覽的示例代碼,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-11-11

最新評(píng)論

个旧市| 姚安县| 临武县| 团风县| 清流县| 富锦市| 南宁市| 东光县| 富顺县| 三河市| 南漳县| 合作市| 霍林郭勒市| 乃东县| 石景山区| 香格里拉县| 库伦旗| 集贤县| 辰溪县| 蓬溪县| 中山市| 井研县| 眉山市| 钟山县| 博罗县| 六盘水市| 凤翔县| 青铜峡市| 汉沽区| 鞍山市| 通辽市| 鄂伦春自治旗| 江门市| 竹溪县| 新干县| 湖南省| 安丘市| 柳林县| 屏东县| 九龙县| 缙云县|