×
Namespaces

Variants
Actions

Archived:Creating a Digital Clock QWidget

From Nokia Developer Wiki
Jump to: navigation, search

Archived.pngArchived: 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.

Article Metadata
Tested with
Devices(s): Emulator
Compatibility
Platform(s): S60 3rd Edition FP1, S60 3rd Edition FP2, S60 5th Edition
Symbian
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

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

Screenshot

Digitalclocklarge.jpg

This page was last modified on 11 October 2012, at 04:14.
207 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×