void ShapedClock::paintEvent(QPaintEvent *event) { //int nSide = qMin(width(), height()); //QPainter painter1(this); //QPixmap pixmap( "D:\\ParkSolution\\Document\\Info.PNG" ); //painter1.drawPixmap( width() / 2 - nSide / 2, height() / 2 - nSide / 2, 33, 33, pixmap ); return; static const QPoint hourHand[3] = { QPoint(7, 8), QPoint(-7, 8), QPoint(0, -40) }; static const QPoint minuteHand[3] = { QPoint(7, 8), QPoint(-7, 8), QPoint(0, -70) }; QColor hourColor(127, 0, 127); QColor minuteColor(0, 127, 127, 191); int side = qMin(width(), height()); QTime time = QTime::currentTime(); QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing); painter.translate(width() / 2, 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.drawLine(88, 0, 96, 0); 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(minuteHand, 3); painter.restore(); painter.setPen(minuteColor); for (int j = 0; j < 60; ++j) { if ((j % 5) != 0) painter.drawLine(92, 0, 96, 0); painter.rotate(6.0); } }
void WorldTimeClock::paintEvent(QPaintEvent *) { static const QPoint hourHand[3] = { QPoint(7, 8), QPoint(-7, 8), QPoint(0, -40) }; static const QPoint minuteHand[3] = { QPoint(7, 8), QPoint(-7, 8), QPoint(0, -70) }; QColor hourColor(127, 0, 127); QColor minuteColor(0, 127, 127, 191); int side = qMin(width(), height()); QTime time = QTime::currentTime(); time = time.addSecs(timeZoneOffset); QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing); painter.translate(width() / 2, 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.drawLine(88, 0, 96, 0); 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(minuteHand, 3); painter.restore(); painter.setPen(minuteColor); for (int j = 0; j < 60; ++j) { if ((j % 5) != 0) painter.drawLine(92, 0, 96, 0); painter.rotate(6.0); } emit updated(time); }
void Compass::paintEvent(QPaintEvent *) { static const QPoint minuteHand[3] = { QPoint(7, 8), QPoint(-7, 8), QPoint(0, -70) }; QColor minuteColor(Qt::black); int side = qMin(width(), height()); //Initializing painter QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing); QStyleOption opt; opt.init(this); QPainter p(this); style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this); //Moving painter to the middle of the square painter.translate(width() / 2, height() / 2); //Scaling the canvas so that there are 100 "points" in each direction? painter.scale(side / 200.0, side / 200.0); //Initializing painter painter.setPen(Qt::NoPen); painter.setBrush(minuteColor); painter.save(); //Paint hand painter.rotate(heading); painter.drawConvexPolygon(minuteHand, 3); painter.restore(); //Paint minute markings painter.setPen(minuteColor); for (int j = 0; j < 60; ++j) { painter.drawLine(92, 0, 96, 0); painter.rotate(6.0); } static const QPoint north = QPoint(-4.5,-75); //static const QPoint east = QPoint(85,5); //static const QPoint south = QPoint(-4.5,95); //static const QPoint west = QPoint(-96,5); QFont font=painter.font(); font.setPointSize(16); //font.setWeight(QFont::DemiBold); painter.setFont(font); painter.drawText(north, "N"); //painter.drawText(east, "E"); //painter.drawText(south, "S"); //painter.drawText(west, "W"); }
void AnalogClock::paintEvent(QPaintEvent *event) { (void)event; // we need not `event` static const QPoint hourHand[3] = { QPoint(7, 8), QPoint(-7, 8), QPoint(0, -40) }; static const QPoint minuteHand[3] = { QPoint(7, 8), QPoint(-7, 8), QPoint(0, -70) }; static const QPoint secondHand[3] = { QPoint(3, 8), QPoint(-3, 8), QPoint(0, -75), }; QColor hourColor(127, 0, 127); QColor minuteColor(0, 127, 127, 190); QColor secondColor(0, 100, 255, 180); int side = qMin(width(), height()); QTime time = QTime::currentTime(); // setup painter QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing); painter.translate(width() / 2, height() / 2); painter.scale(side / 200.0, side / 200.0); // draw clock hour degree painter.setPen(hourColor); for (int i = -1; i < 12; i++) { painter.drawLine(88, 0, 96, 0); painter.rotate(30.0); } // draw clock second degree painter.setPen(minuteColor); for(int j = 0; j < 60; ++j) { if ((j % 5) != 0) painter.drawLine(92, 0, 96, 0); painter.rotate(6.0); } // draw hour hand float rotateDegree = 30.0 * ((time.hour() + time.minute() / 60.0)); drawClockHand(painter, rotateDegree, hourHand, 3, hourColor); // draw minute hand rotateDegree = 6.0 * (time.minute() + time.second() / 60.0); drawClockHand(painter, rotateDegree, minuteHand, 3, minuteColor); // draw second hand rotateDegree = 6.0 * time.second(); drawClockHand(painter, rotateDegree, secondHand, 3, secondColor); }
//! [8] //! [9] void AnalogClock::paintEvent(QPaintEvent *) //! [8] //! [10] { static const QPoint hourHand[3] = { QPoint(7, 8), QPoint(-7, 8), QPoint(0, -40) }; static const QPoint minuteHand[3] = { QPoint(7, 8), QPoint(-7, 8), QPoint(0, -70) }; QColor hourColor(127, 0, 127); QColor minuteColor(0, 127, 127, 191); int side = qMin(width(), height()); //! [10] //! [11] QPainter painter(this); //! [11] //! [12] painter.setRenderHint(QPainter::Antialiasing); //! [12] //! [13] painter.translate(width() / 2, height() / 2); //! [13] //! [14] painter.scale(side / 200.0, side / 200.0); //! [9] //! [14] //! [15] painter.setPen(Qt::NoPen); //! [15] //! [16] painter.setBrush(hourColor); //! [16] //! [17] //! [18] painter.save(); //! [17] //! [19] painter.rotate(30.0 * ((time().hour() + time().minute() / 60.0))); painter.drawConvexPolygon(hourHand, 3); painter.restore(); //! [18] //! [19] //! [20] painter.setPen(hourColor); //! [20] //! [21] for (int i = 0; i < 12; ++i) { painter.drawLine(88, 0, 96, 0); painter.rotate(30.0); } //! [21] //! [22] painter.setPen(Qt::NoPen); //! [22] //! [23] painter.setBrush(minuteColor); //! [24] painter.save(); painter.rotate(6.0 * (time().minute() + time().second() / 60.0)); painter.drawConvexPolygon(minuteHand, 3); painter.restore(); //! [23] //! [24] //! [25] painter.setPen(minuteColor); //! [25] //! [26] //! [27] for (int j = 0; j < 60; ++j) { if ((j % 5) != 0) painter.drawLine(92, 0, 96, 0); painter.rotate(6.0); } //! [27] }
void MyClock::paintEvent(QPaintEvent *) { static const QPoint hourHand[8] = { QPoint (-5, 0), QPoint (-5, 30), QPoint (-10, 30), QPoint (0, 40), QPoint (10, 30), QPoint (5, 30), QPoint (5, 0), QPoint (- 5, 0) }; static const QPoint minuteHand[8] = { QPoint (-3, 0), QPoint (-3, 50), QPoint (-6, 50), QPoint (0, 60), QPoint (6, 50), QPoint (3, 50), QPoint (3, 0), QPoint (- 3, 0) }; static const QPoint secondHand[8] = { QPoint (-1, 0), QPoint (-1, 50), QPoint (-2, 60), QPoint (0, 70), QPoint (2, 60), QPoint (1, 50), QPoint (1, 0), QPoint (-1, 0) }; QColor hourColor(255, 50, 50); QColor minuteColor(50, 255, 50); QColor secondColor(50, 50, 255); int side = qMin(width(), height()); *time = QTime::currentTime(); //time->addSecs(3600); QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing); painter.translate(width() / 2, height() / 2); painter.scale(side / 200.0, side / 200.0); painter.setPen(Qt::SolidLine); painter.setBrush(hourColor); painter.save(); painter.rotate(30.0 * ((time->hour() + time->minute() / 60.0)) + 180.0); painter.drawConvexPolygon(hourHand, 8); painter.restore(); painter.setPen(hourColor); for (int i = 0; i < 12; ++i) { painter.drawLine(88, 0, 96, 0); painter.rotate(30.0); } painter.setPen(Qt::SolidLine); painter.setBrush(minuteColor); painter.save(); painter.rotate(6.0 * (time->minute() + time->second() / 60.0) + 180.0); painter.drawConvexPolygon(minuteHand, 8); painter.restore(); painter.setPen(minuteColor); for (int j = 0; j < 60; ++j) { if ((j % 5) != 0) painter.drawLine(92, 0, 96, 0); painter.rotate(6.0); } painter.setPen(Qt::SolidLine); painter.setBrush(secondColor); painter.save(); painter.rotate(6.0 * time->second() + 180.0); painter.drawConvexPolygon(secondHand, 8); painter.restore(); }