Archived:Creating a Digital Clock QWidget
hamishwillee
(Talk | contribs) m (Text replace - "Category:MeeGo" to "Category:MeeGo Harmattan") |
hamishwillee
(Talk | contribs) m (Text replace - "<code cpp>" to "<code cpp-qt>") |
||
| (2 intermediate revisions by one user not shown) | |||
| Line 1: | Line 1: | ||
| − | [[Category:Qt]] | + | {{Archived|timestamp=20120723122421|user=[[User:Hamishwillee|<br />----]]|[[:Category:Qt Quick|Qt Quick]] should be used for all UI development on mobile devices. The approach described in this article (using C++ for the Qt app UI) is deprecated.}} |
| − | + | [[Category:Qt C++ UI]] | |
| − | + | {{ArticleMetaData <!-- v1.2 --> | |
| − | {{ArticleMetaData | + | |
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
|sourcecode= <!-- Link to example source code (e.g. [[Media:The Code Example ZIP.zip]]) --> | |sourcecode= <!-- Link to example source code (e.g. [[Media:The Code Example ZIP.zip]]) --> | ||
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) --> | |installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) --> | ||
| − | |sdk=<!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Nokia Qt SDK 1.1]) --> | + | |devices= Emulator |
| − | |devicecompatability=<!-- Compatible devices (e.g.: All* (must have GPS) ) --> | + | |sdk= <!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Nokia Qt SDK 1.1]) --> |
| − | |signing=<!-- Empty or one of Self-Signed, DevCert, Manufacturer --> | + | |platform= S60 3rd Edition FP1, S60 3rd Edition FP2, S60 5th Edition |
| − | |capabilities=<!-- Capabilities required (e.g. Location, NetworkServices. --> | + | |devicecompatability= <!-- Compatible devices (e.g.: All* (must have GPS) ) --> |
| − | |author=[[User:James1980]] | + | |dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 --> |
| + | |signing= <!-- Empty or one of Self-Signed, DevCert, Manufacturer --> | ||
| + | |capabilities= <!-- Capabilities required by the article/code example (e.g. Location, NetworkServices. --> | ||
| + | |keywords= QLCDNumber,QTimer,QString | ||
| + | |language= <!-- Language category code for non-English topics - e.g. Lang-Chinese --> | ||
| + | |translated-by= <!-- [[User:XXXX]] --> | ||
| + | |translated-from-title= <!-- Title only --> | ||
| + | |translated-from-id= <!-- Id of translated revision --> | ||
| + | |review-by= <!-- After re-review: [[User:username]] --> | ||
| + | |review-timestamp= <!-- After re-review: YYYYMMDD --> | ||
| + | |update-by= <!-- After significant update: [[User:username]]--> | ||
| + | |update-timestamp= <!-- After significant update: YYYYMMDD --> | ||
| + | |creationdate= 17 February 2009 | ||
| + | |author= [[User:James1980]] | ||
| + | <!-- The following are not in current metadata --> | ||
| + | |subcategory= Application | ||
}} | }} | ||
| Line 23: | Line 29: | ||
==Overview== | ==Overview== | ||
| − | This code snippet demonstrates how to create a simple digital clock widget in [[Qt | + | This code snippet demonstrates how to create a simple digital clock widget in [[Qt overview]]. |
==Preconditions== | ==Preconditions== | ||
| − | * Install the [[ | + | * Install the [[Qt SDK]] |
== Source File == | == Source File == | ||
| − | <code cpp> | + | <code cpp-qt> |
#include <QtGui> | #include <QtGui> | ||
| Line 76: | Line 82: | ||
== Header File == | == Header File == | ||
| − | <code cpp> | + | <code cpp-qt> |
#ifndef DIGITALCLOCK_H | #ifndef DIGITALCLOCK_H | ||
| Line 100: | Line 106: | ||
== Screenshot== | == Screenshot== | ||
| − | [[ | + | [[File:Digitalclocklarge.jpg]] [[Category:Code Snippet]][[Category:MeeGo Harmattan]] [[Category:Symbian]] |
Latest revision as of 04:14, 11 October 2012
Archived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.
Qt Quick should be used for all UI development on mobile devices. The approach described in this article (using C++ for the Qt app UI) is deprecated.
Qt Quick should be used for all UI development on mobile devices. The approach described in this article (using C++ for the Qt app UI) is deprecated.
Article Metadata
Tested with
Devices(s): Emulator
Compatibility
Platform(s): S60 3rd Edition FP1, S60 3rd Edition FP2, S60 5th Edition
Article
Keywords: QLCDNumber,QTimer,QString
Created: james1980
(17 Feb 2009)
Last edited: hamishwillee
(11 Oct 2012)
Contents |
Overview
This code snippet demonstrates how to create a simple digital clock widget in Qt overview.
Preconditions
- Install the Qt SDK
Source File
#include <QtGui>
#include "digitalclock.h"
DigitalClock::DigitalClock(QWidget *parent)
: QLCDNumber(parent)
{
setSegmentStyle(Filled);
setNumDigits(8);
setStyleSheet("* { background-color:rgb(199,147,88);color:rgb(255,255,255); padding: 7px}}");
QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(displayTime()));
timer->start(1000);
displayTime();
setWindowTitle(tr("Digital Clock"));
resize(300, 120);
}
Digital::~Digital()
{
//parent object will destroy timer automatically.
}
void DigitalClock::displayTime()
{
QTime time = QTime::currentTime();
QString text = time.toString("hh:mm:ss");
if ((time.second() % 2) == 0)
{text[2] = ' ';
text[5] = ' ';
}
display(text);
}
Header File
#ifndef DIGITALCLOCK_H
#define DIGITALCLOCK_H
#include <QLCDNumber>
class DigitalClock : public QLCDNumber
{
Q_OBJECT
public:
DigitalClock(QWidget *parent = 0);
private slots:
void displayTime();
};
#endif


