How to use QLCDNumber in Qt
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);
- 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);
- 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);
Related Link
- Check this digital clock example that shows the use of the QLCDNumber.
- Read more about 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()
{
}


This article shows use of QLCDNumber.this article is very useful to those who want to make game.at that time using this article you can display number.
This article Sows that QLCDNumber display the number in decimal digit,binary digit and hexadecimal digit.Hear the example of hexadecimal number is shown in figure.it convert 42 into hexadecimal 2A.
This article can also be useful for to make converter and also to make a calculator this article can useful when you want to change digit or display the digit in which formate you want to be.
--nayan_trivedi