×
Namespaces

Variants
Actions
(Difference between revisions)

Archived:Creating a Digital Clock QWidget

From Nokia Developer Wiki
Jump to: navigation, search
hamishwillee (Talk | contribs)
m (Added category Category:Symbian. (Preparing for ontology change))
hamishwillee (Talk | contribs)
m (Remove platform specifier categories (only need specifier for Qt if there is some platform specific behaviour))
Line 1: Line 1:
[[Category:Qt for Symbian]][[Category:Code Examples]]
+
[[Category:Qt]]
 
__NOTOC__
 
__NOTOC__
 
__NOEDITSECTION__
 
__NOEDITSECTION__
Line 6: Line 6:
 
|platform=S60 3rd Edition FP1, S60 3rd Edition FP2, S60 5th Edition  
 
|platform=S60 3rd Edition FP1, S60 3rd Edition FP2, S60 5th Edition  
 
|devices= Emulator
 
|devices= Emulator
|category=Qt for Symbian
+
|category=Qt
 
|subcategory=Application
 
|subcategory=Application
 
|creationdate=17 February 2009
 
|creationdate=17 February 2009
Line 19: Line 19:
 
==Preconditions==
 
==Preconditions==
  
* Download and Install latest version [[Qt for Symbian - Installation packages]] which has links on how to install the latest version
+
* Install the [[Nokia Qt SDK]]
 
+
  
 
== Source File ==
 
== Source File ==
Line 93: Line 92:
  
 
== Screenshot==
 
== Screenshot==
[[Image:Digitalclocklarge.jpg]] [[Category:Qt]] [[Category:Symbian]]
+
[[Image:Digitalclocklarge.jpg]] [[Category:Code Examples]]

Revision as of 13:32, 4 April 2011


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: (17 Feb 2009)
Last edited: hamishwillee (04 Apr 2011)


Overview

This code snippet demonstrates how to create a simple digital clock widget in Qt for S60.

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

92 page views in the last 30 days.
×