QT Implementation clock icon

Source: Internet
Author: User

  1. #include "Clock.h"
  2. Clock::clock (Qwidget *parent)
  3. : Qwidget (parent)
  4. {
  5. Qtimer *timer = new Qtimer (this);
  6. Timer->start (1000);//One second
  7. Connect (timer,signal ()), This,slot (Update ()));
  8. Qfont font;
  9. Font.setpointsize (10);//font size set to 10
  10. SetFont (font);
  11. }
  12. Clock::~clock ()
  13. {
  14. }
  15. void CLOCK::p aintevent (qpaintevent */* Event */)
  16. {
  17. qpainter painter (this);
  18. Painter.setrenderhint (qpainter::antialiasing, true);
  19. int side = Qmin (width (), height ());
  20. Painter.setviewport ((Width ()-side)/2, (height ()-side)/2,
  21. side, side);
  22. Painter.setwindow (0, 0, 200, 200);/* Set (0,0) as the new origin of coordinates */
  23. Draw (&painter);
  24. }
  25. void CLOCK::d raw (Qpainter *painter)
  26. {
  27. Qpen Thickpen (Palette () foreground (), 1.5);//Set tick mark to thick black
  28. Qpen Thinpen (Palette (). foreground (), 0.5);//Set tick mark to gray
  29. Qtime time = Qtime::currenttime ();
  30. Painter->translate (100,100);//re-set the origin of the coordinates.
  31. Painter->setrenderhint (qpainter::antialiasing);//anti-aliasing
  32. Painter->setbrush (qt::red);
  33. Painter->setpen (qt::red);
  34. Painter->save ();//Save coordinate system to prevent the coordinate system from running off
  35. Painter->rotate (6.0*time.second ());//note is 6.0, not 6
  36. Painter->drawconvexpolygon (sed,4);
  37. Painter->restore ();//coordinate system before reset
  38. Painter->setbrush (Qt::blue);
  39. Painter->setpen (Qt::blue);
  40. Painter->save ();
  41. Painter->rotate (6.0* (Time.minute () +time.second ()/60.0);
  42. Painter->drawconvexpolygon (min,4);
  43. Painter->restore ();
  44. Painter->setbrush (Qt::black);
  45. Painter->setpen (Qt::black);
  46. Painter->save ();
  47. Painter->rotate (30.0* (Time.hour () +time.minute ()/60.0);
  48. Painter->drawconvexpolygon (hour,4);
  49. Painter->restore ();
  50. Painter->drawline (0,-98,0,-88);
  51. for (int i=0;i<12;i++)
  52. // {
  53. Painter->rotate (30);//axis rotation 30 degrees
  54. Painter->drawline (0,-98,0,-88);
  55. // }
  56. /* Draw a scale with a number */
  57. for (int i = 1; I <=60; ++i) {
  58. Painter->save ();
  59. Painter->rotate (6*i);//axis rotation 6 degrees
  60. if (i% 5 = = 0) {
  61. Painter->setpen (Thickpen);
  62. Painter->drawline (0,-98, 0,-82);
  63. Painter->drawtext (-20,-82, 40, 40,
  64. Qt::alignhcenter | Qt::aligntop,
  65. Qstring::number (I/5));
  66. } else {
  67. Painter->setpen (Thinpen);
  68. Painter->drawline (0,-98, 0,-88);
  69. }
  70. Painter->rotate (-degreesperminute);
  71. Painter->restore ();
  72. }
  73. }

QT Implementation clock icon

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.