欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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)文章

  • Qt界面美化之自定義qss樣式表的詳細(xì)步驟

    Qt界面美化之自定義qss樣式表的詳細(xì)步驟

    很多人應(yīng)該和我一樣,想做界面才接觸的Qt,結(jié)果就是做不出來(lái)華麗的界面,下面這篇文章主要給大家介紹了關(guān)于Qt界面美化之自定義qss樣式表的詳細(xì)步驟,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2023-03-03
  • C++命令行解析包gflags的使用教程

    C++命令行解析包gflags的使用教程

    這篇文章主要給大家介紹了關(guān)于C++命令行解析包gflags的使用教程,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-11-11
  • C++實(shí)現(xiàn)圖的遍歷算法(DFS,BFS)的示例代碼

    C++實(shí)現(xiàn)圖的遍歷算法(DFS,BFS)的示例代碼

    本文給大家?guī)?lái)的是圖遍歷的算法,DFS(深度優(yōu)先遍歷),BFS(廣度優(yōu)先遍歷)。這兩個(gè)算法是比較重要和常用的算法,但是在圖中的實(shí)現(xiàn)只是最基本的操作,快跟隨小編一起學(xué)習(xí)一下吧
    2022-07-07
  • C到C++的升級(jí)關(guān)系及區(qū)別實(shí)例探究

    C到C++的升級(jí)關(guān)系及區(qū)別實(shí)例探究

    這篇文章主要為大家介紹了C到C++的升級(jí)關(guān)系及區(qū)別實(shí)例探究,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2024-01-01
  • C語(yǔ)言版三子棋小游戲

    C語(yǔ)言版三子棋小游戲

    這篇文章主要為大家詳細(xì)介紹了C語(yǔ)言版三子棋小游戲,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-07-07
  • VS中scanf為何會(huì)報(bào)錯(cuò)詳解

    VS中scanf為何會(huì)報(bào)錯(cuò)詳解

    在我們剛使用vs時(shí),在使用scanf函數(shù)時(shí)常會(huì)遇到報(bào)錯(cuò)提醒,下面這篇文章主要給大家介紹了關(guān)于VS中scanf為何會(huì)報(bào)錯(cuò)的相關(guān)資料,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2023-02-02
  • Cocos2d-x UI開發(fā)之CCControlButton控件類實(shí)例

    Cocos2d-x UI開發(fā)之CCControlButton控件類實(shí)例

    這篇文章主要介紹了Cocos2d-x UI開發(fā)之CCControlButton控件類實(shí)例,本文代碼中包含大量注釋來(lái)講解CCControlButton控件類的使用,需要的朋友可以參考下
    2014-09-09
  • C語(yǔ)言實(shí)現(xiàn)三子棋小游戲的示例代碼

    C語(yǔ)言實(shí)現(xiàn)三子棋小游戲的示例代碼

    這篇文章主要介紹了如何通過(guò)C語(yǔ)言實(shí)現(xiàn)三子棋小游戲,三子棋小游戲的實(shí)現(xiàn)主要依賴于循環(huán)語(yǔ)句、函數(shù)和數(shù)組,感興趣的小伙伴可以嘗試一下
    2022-10-10
  • linux c 獲得當(dāng)前進(jìn)程的進(jìn)程名和執(zhí)行路徑(示例)

    linux c 獲得當(dāng)前進(jìn)程的進(jìn)程名和執(zhí)行路徑(示例)

    如何得到當(dāng)前進(jìn)程的進(jìn)程名和執(zhí)行路徑。寫了個(gè)程序分享一下
    2013-07-07
  • C語(yǔ)言編寫一個(gè)鏈表

    C語(yǔ)言編寫一個(gè)鏈表

    這篇文章主要為大家詳細(xì)介紹了C語(yǔ)言編寫一個(gè)鏈表,文中安裝步驟介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-05-05

最新評(píng)論