• 大小: 4.22MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-10-28
  • 语言: 其他
  • 标签: 钟表  

资源简介

qt制作的虚拟钟表

资源截图

代码片段和文件信息

#include “analogclock.h“
#include “ui_analogclock.h“
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
analogclock::analogclock(QWidget *parent) :
    QWidget(parent)
    //ui(new Ui::analogclock)
{

    QTimer *timer=new QTimer(this);
    connect(timerSIGNAL(timeout())thisSLOT(update()));
    timer->start(1000);

    resize(240240);

    QFont font;
    font.setPointSize(10);//字体大小设置为10
    setFont(font);
   // ui->setupUi(this);

   // sound->play();
   setWindowtitle(tr(“colok “));
   QPixmap pix;
  setMask(pix.mask());

}

analogclock::~analogclock()
{
    //delete ui;
}

void analogclock::paintEvent(QPaintEvent *)
{

    static const QPoint hourHand[3]={
        QPoint(78)
        QPoint(-78)
        QPoint(0-40)
    };//时
    static const QPoint minuteHand[3]={
        QPoint(78)
        QPoint(-78)
        QPoint(0-70)
    };//分
    static const QPoint secondHand[3]={
        QPoint(78)
        QPoint(-78)
        QPoint(0-95)
    };//秒

     QColor hourColor(646464);
     QColor minuteColor(6464127191);
     QColor secondColor(2313035250);
     QPainter painter(this);
     int side=qMin(width()height());
     painter.drawPixmap(00width()height()QPixmap(“/6.jpg“));//调用图片做背景并且设置大小
     painter.setRenderHint(QPainter::Antialiasing);
     painter.translate(width()/2height()/2);
     painter.scale(side/200.0side/200.0);
     painter.setPen(Qt::NoPen);//画图的时候设置无边界


    int r;
    int cxcy;
    cy=height()/2;
    cx=width()/2;
    r=cy>cx?cx:cy-20;
    QPoint point;
    QTime time=QTime::currentTime();
    QPalette palette;
    painter.setRenderHint(QPainter::Antialiasing);
    painter.setBrush(QColor(000));
    painter.save();
    painter.rotate(30.0 * ((time.hour()+time.minute()/60.0)));
    painter.drawConvexPolygon(hourHand3);
    painter.restore();
    painter.setPen(hourColor);
    for(int i=0;i<12;++i)
    {
    painter.drawEllipse(-4-981010);
    painter.drawLine(880960);
    painter.rotate(30.0);
    }//时针

    painter.setPen(Qt::NoPen);
    painter.setBrush(minuteColor);
    painter.save();
    painter.rotate(6.0 * ((time.minute()+time.second()/60.0)));
    painter.drawConvexPolygon(minuteHand3);
    painter.restore();
    painter.setPen(minuteColor);

    for(int j=0;j<60;++j)
    {
        if((j%5)!=0)
        painter.drawEllipse(-1-9444);
        painter.rotate(6.0);

    }//分针

    for(int i=1;i<=12;i++)
    {
        point.setX(sin((float)i/12*(2*3.14))*(r)*0.76-4);
        point.setY(-(cos((float)i/12*(2*3.14))*(r)*0.76)+4);
        painter.drawText(pointQString::number(i));
     }//写12个数字
    palette.setColor(QPalette::BackgroundQColor(000000255));
    setPalette(palette);


    painter.setPen(Qt::

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2014-06-18 15:53  colock2\
     文件      674633  2012-03-30 16:32  colock2\6.jpg
     文件        3614  2014-06-18 12:46  colock2\analogclock.cpp
     文件         420  2014-04-17 10:08  colock2\analogclock.h
     文件         333  2014-04-17 10:05  colock2\colock2.pro
     文件       14480  2014-06-18 15:53  colock2\colock2.pro.user
     目录           0  2014-06-18 12:46  colock2\debug\
     文件      452792  2014-06-18 12:46  colock2\debug\analogclock.o
     文件      150845  2014-04-17 11:25  colock2\debug\analogclock.obj
     文件     1030683  2014-06-18 12:46  colock2\debug\colock2.exe
     文件      694812  2014-04-17 11:25  colock2\debug\colock2.ilk
     文件         878  2014-04-17 11:25  colock2\debug\colock2.intermediate.manifest
     文件     2132992  2014-04-17 11:25  colock2\debug\colock2.pdb
     文件      118039  2014-06-09 17:18  colock2\debug\main.o
     文件       39823  2014-04-17 11:25  colock2\debug\main.obj
     文件        2449  2014-04-17 11:25  colock2\debug\moc_analogclock.cpp
     文件      132373  2014-06-09 17:19  colock2\debug\moc_analogclock.o
     文件       41718  2014-04-17 11:25  colock2\debug\moc_analogclock.obj
     文件     3994116  2014-04-16 09:13  colock2\debug\qrc_image.cpp
     文件      781817  2014-04-16 09:13  colock2\debug\qrc_image.o
     文件         301  2014-04-17 09:34  colock2\image.qrc
     文件         511  2014-04-17 09:27  colock2\main.cpp
     文件        6891  2014-06-09 17:18  colock2\Makefile
     文件        6110  2014-06-09 17:18  colock2\Makefile.Debug
     文件        6183  2014-06-09 17:18  colock2\Makefile.Release
     目录           0  2014-04-16 09:12  colock2\release\
     文件        1475  2014-04-16 09:13  colock2\ui_analogclock.h
     文件     1822720  2014-04-17 11:25  colock2\vc90.pdb

评论

共有 条评论