📄 aclock.cpp
字号:
/****************************************************************************** $Id: qt/examples/aclock/aclock.cpp 2.3.7 edited 2001-01-26 $**** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.**** This file is part of an example program for Qt. This example** program may be used, distributed and modified without limitation.*******************************************************************************/#include "aclock.h"#include <qtimer.h>#include <qpainter.h>#include <qbitmap.h>#include <iostream.h>//// Constructs an analog clock widget that uses an internal QTimer.//AnalogClock::AnalogClock( QWidget *parent, const char *name ) : QWidget( parent, name, Qt::WStyle_Customize | Qt::WStyle_NoBorder){ temp=-25; step = 1; demo = 1; setMinimumSize( 121, 286 ); setMaximumSize( 121, 286 ); QTimer *internalTimer = new QTimer( this ); // create internal timer connect( internalTimer, SIGNAL(timeout()), SLOT(timeout()) ); internalTimer->start( 50 ); // emit signal every 5 seconds //QPainter paint(this); //QPixmap *pm; //pm = new QPixmap("thermometer2.png"); //paint.drawPixmap(0,0, *pm,0,0, -1, -1); //bitBlt( this, 0, 0, *QPixmap("thermometer2.png") ); setBackgroundPixmap( QPixmap("thermometer2.png") ); //背景有问题}//// The QTimer::timeout() signal is received by this slot.//void AnalogClock::timeout(){ if(demo){ if(temp>40 || temp <-30) step=-step; temp+=step; } update();}void AnalogClock::paintEvent( QPaintEvent * ){ QPainter paint( this ); paint.setBrush( red ); paint.setPen( red ); drawClock( &paint );}// If the clock is transparent, we use updateMask()// instead of paintEvent()void AnalogClock::drawClock( QPainter *paint ){ paint->save(); //paint->setWindow( 0,0, 1000,5000 ); //QPixmap *pm; //pm = new QPixmap("thermometer2.png"); float height=192*((temp+30)/70.0); paint->save(); //paint->drawPixmap(0,0, *pm,0,0, -1, -1); paint->drawRect ( 58, 215, 6, (-(int)height) ) ; paint->restore(); ///////////////////////////////////////////////////标尺的作用,勿删 /*int y1=0; int y2=0; paint->setPen(blue); for ( int i=0; i<10; i++ ) { paint->drawLine( 450,y1, 750,y1) ; y1+=500; } for ( int i=0; i<50; i++ ) { paint->drawLine( 450,y2, 550,y2) ; y2+=100; } paint->setPen( yellow) ; paint->drawLine( 450,220, 750,220) ; paint->drawLine( 450,4280, 750,4280) ;*/////////////////////////////////////////////////////}//end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -