×
Namespaces

Variants
Actions
(Difference between revisions)

Archived:Creating a Digital Clock QWidget

From Nokia Developer Wiki
Jump to: navigation, search
jimgilmour1 (Talk | contribs)
m (remove reference to qts60 sdk temple)
mind_freak (Talk | contribs)
Line 46: Line 46:
 
     setWindowTitle(tr("Digital Clock"));
 
     setWindowTitle(tr("Digital Clock"));
 
     resize(300, 120);
 
     resize(300, 120);
 +
}
 +
Digital::~Digital()
 +
{
 +
      if(timer)
 +
      {
 +
              delete timer;
 +
      }
 
}
 
}
  

Revision as of 14:42, 27 July 2009


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: mind_freak (27 Jul 2009)


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()
{
if(timer)
{
delete timer;
}
}
 
 
 
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

123 page views in the last 30 days.
×