[2] | 1 | /****************************************************************************
|
---|
| 2 | **
|
---|
[846] | 3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
[561] | 4 | ** All rights reserved.
|
---|
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com)
|
---|
[2] | 6 | **
|
---|
| 7 | ** This file is part of the documentation of the Qt Toolkit.
|
---|
| 8 | **
|
---|
[846] | 9 | ** $QT_BEGIN_LICENSE:FDL$
|
---|
[2] | 10 | ** Commercial Usage
|
---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
[846] | 13 | ** Software or, alternatively, in accordance with the terms contained in a
|
---|
| 14 | ** written agreement between you and Nokia.
|
---|
[2] | 15 | **
|
---|
[846] | 16 | ** GNU Free Documentation License
|
---|
| 17 | ** Alternatively, this file may be used under the terms of the GNU Free
|
---|
| 18 | ** Documentation License version 1.3 as published by the Free Software
|
---|
| 19 | ** Foundation and appearing in the file included in the packaging of this
|
---|
| 20 | ** file.
|
---|
[2] | 21 | **
|
---|
[561] | 22 | ** If you have questions regarding the use of this file, please contact
|
---|
| 23 | ** Nokia at qt-info@nokia.com.
|
---|
[2] | 24 | ** $QT_END_LICENSE$
|
---|
| 25 | **
|
---|
| 26 | ****************************************************************************/
|
---|
| 27 |
|
---|
| 28 | /*!
|
---|
| 29 | \example widgets/digitalclock
|
---|
| 30 | \title Digital Clock Example
|
---|
| 31 |
|
---|
| 32 | The Digital Clock example shows how to use QLCDNumber to display a
|
---|
| 33 | number with LCD-like digits.
|
---|
| 34 |
|
---|
| 35 | \image digitalclock-example.png Screenshot of the Digital Clock example
|
---|
| 36 |
|
---|
| 37 | This example also demonstrates how QTimer can be used to update a widget
|
---|
| 38 | at regular intervals.
|
---|
| 39 |
|
---|
| 40 | \section1 DigitalClock Class Definition
|
---|
| 41 |
|
---|
| 42 | The \c DigitalClock class provides a clock widget showing the time with
|
---|
| 43 | hours and minutes separated by a blinking colon. We subclass QLCDNumber
|
---|
| 44 | and implement a private slot called \c showTime() to update the clock
|
---|
| 45 | display:
|
---|
| 46 |
|
---|
| 47 | \snippet examples/widgets/digitalclock/digitalclock.h 0
|
---|
| 48 |
|
---|
| 49 | \section1 DigitalClock Class Implementation
|
---|
| 50 |
|
---|
| 51 | \snippet examples/widgets/digitalclock/digitalclock.cpp 0
|
---|
| 52 |
|
---|
| 53 | In the constructor, we first change the look of the LCD numbers. The
|
---|
| 54 | QLCDNumber::Filled style produces raised segments filled with the
|
---|
| 55 | foreground color (typically black). We also set up a one-second timer
|
---|
| 56 | to keep track of the current time, and we connect
|
---|
| 57 | its \l{QTimer::timeout()}{timeout()} signal to the private \c showTime() slot
|
---|
| 58 | so that the display is updated every second. Then, we
|
---|
| 59 | call the \c showTime() slot; without this call, there would be a one-second
|
---|
| 60 | delay at startup before the time is shown.
|
---|
| 61 |
|
---|
| 62 | \snippet examples/widgets/digitalclock/digitalclock.cpp 1
|
---|
| 63 | \snippet examples/widgets/digitalclock/digitalclock.cpp 2
|
---|
| 64 |
|
---|
| 65 | The \c showTime() slot is called whenever the clock display needs
|
---|
| 66 | to be updated.
|
---|
| 67 |
|
---|
| 68 | The current time is converted into a string with the format "hh:mm".
|
---|
| 69 | When QTime::second() is a even number, the colon in the string is
|
---|
| 70 | replaced with a space. This makes the colon appear and vanish every
|
---|
| 71 | other second.
|
---|
| 72 |
|
---|
| 73 | Finally, we call QLCDNumber::display() to update the widget.
|
---|
| 74 | */
|
---|