Namespaces
Variants
Actions
Revision as of 04:17, 11 October 2012 by hamishwillee (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

How to use QLCDNumber in Qt

Jump to: navigation, search
Article Metadata

Code Example
Source file: Media:Lcdnumber.zip

Tested with
Devices(s): Emulator (S60 5th edition)

Compatibility
Platform(s): Qt

Article
Keywords: QLCDNumber,QSpinBox
Created: james1980 (03 Jan 2008)
Last edited: hamishwillee (11 Oct 2012)

Contents

Introduction

This article shows the use of LCD number to display some number. For example it can be use to display a score while designing a game.

Various Functions

  • This line create a object of the LCDNumber.
QLCDNumber* number = new QLCDNumber(this);

Lcd.JPG

  • To specify the segment display style of the LCD number. Qt support the three different filled style i.e. Filled,Outline and Flat.
number->setSegmentStyle(QLCDNumber::Filled);

Lcdsegmentstyle.JPG

  • To specify the number of LCD digits that would be display.This function specify the mode of the LCD. Various supported modes are Hex,Dec,Bin and Oct.
number->setMode(QLCDNumber::Hex);

Lcdhex.JPG

Related Link

  • Check this digital clock example that shows the use of the QLCDNumber.


Source Code

Header file

#ifndef LCDNUMBER_H
#define LCDNUMBER_H
 
#include <QWidget>
#include <QLCDNumber>
#include <QSpinBox>
#include <QVBoxLayout>
 
class lcdnumber : public QWidget
{
Q_OBJECT
 
public:
lcdnumber(QWidget *parent = 0);
~lcdnumber();
private:
QVBoxLayout* layout;
QLCDNumber* number;
QSpinBox* spin;
 
};
 
#endif // LCDNUMBER_H

Source file

#include "lcdnumber.h"
 
lcdnumber::lcdnumber(QWidget *parent)
: QWidget(parent)
{
 
setWindowTitle(("LCD Number"));
layout = new QVBoxLayout(this);
number = new QLCDNumber(this);
spin = new QSpinBox(this);
spin->setMaximum(9);
spin->setMinimum(0);
 
connect(spin, SIGNAL(valueChanged(int)), number, SLOT(display(int)));
layout->addWidget(spin,Qt::AlignCenter);
 
layout->addWidget(number,Qt::AlignCenter);
showMaximized();
}
 
lcdnumber::~lcdnumber()
{
 
}

Screenshot

Lcd.JPG

362 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved