xyliner.blogg.se

Analog timer clock
Analog timer clock










analog timer clock
  1. ANALOG TIMER CLOCK MANUAL
  2. ANALOG TIMER CLOCK CODE

ANALOG TIMER CLOCK MANUAL

Letting the painter handle transformations is often easier than performing manual calculations just to draw the contents of a custom widget. The painter takes care of all the transformations made during the paint event, and ensures that everything is drawn correctly.

ANALOG TIMER CLOCK CODE

To make our code simpler, we will draw a fixed size clock face that will be positioned and scaled so that it lies in the center of the widget. We use a scale factor that let's us use x and y coordinates between -100 and 100, and that ensures that these lie within the length of the widget's shortest side. The translation moves the origin to the center of the widget, and the scale operation ensures that the following drawing operations are scaled to fit within the widget. This makes drawing of diagonal lines much smoother. We call QPainter::setRenderHint() with QPainter::Antialiasing to turn on antialiasing. Painters can be used to draw on any QPaintDevice, but they are usually used with widgets, so we pass the widget instance to the painter's constructor. The contents of custom widgets are drawn with a QPainter. It is also useful to determine the current time before we start drawing. We also determine the length of the widget's shortest side so that we can fit the clock face inside the widget. The minute hand's color has an alpha component of 191, meaning that it's 75% opaque. Since we connected the timer's timeout() signal to this slot, it will be called at least once every five seconds.īefore we set up the painter and draw the clock, we first define two lists of QPoints and two QColors that will be used for the hour and minute hands.

analog timer clock

This happens when the widget is first shown, and when it is covered then exposed, but it is also executed when the widget's update() slot is called. The paintEvent() function is called whenever the widget's contents need to be updated. Void AnalogClock ::paintEvent( QPaintEvent *)












Analog timer clock