QLCDNumber Class

QLCDNumber 显示类似LCD样式的数字. 更多...

头文件: #include <QLCDNumber>
qmake: QT += widgets
基类: QFrame

公有类型

enum Mode { Hex, Dec, Oct, Bin }
enum SegmentStyle { Outline, Filled, Flat }

属性

公有函数

QLCDNumber(QWidget *parent = Q_NULLPTR)
QLCDNumber(uint numDigits, QWidget *parent = Q_NULLPTR)
~QLCDNumber()
bool checkOverflow(double num) const
bool checkOverflow(int num) const
int digitCount() const
int intValue() const
Mode mode() const
SegmentStyle segmentStyle() const
void setDigitCount(int numDigits)
void setMode(Mode)
void setSegmentStyle(SegmentStyle)
bool smallDecimalPoint() const
double value() const

重新实现的公有函数

virtual QSize sizeHint() const

公有槽函数

void display(const QString &s)
void display(int num)
void display(double num)
void setBinMode()
void setDecMode()
void setHexMode()
void setOctMode()
void setSmallDecimalPoint(bool)
  • 19 个公有槽函数继承自 QWidget
  • 1 个公有槽函数继承自 QObject

信号

void overflow()

重新实现的受保护函数

virtual bool event(QEvent *e)
virtual void paintEvent(QPaintEvent *)
  • 4 个受保护的函数继承自 QFrame
  • 35 个受保护的函数继承自 QWidget
  • 9 个受保护的函数继承自 QObject
  • 1 个受保护的函数继承自 QPaintDevice

其他继承的成员

  • 1 个公有变量继承自 QObject
  • 5 个静态公有成员继承自 QWidget
  • 10 个静态公有成员继承自 QObject
  • 4 个受保护的函数继承自 QFrame
  • 35 个受保护的函数继承自 QWidget
  • 9 个受保护的函数继承自 QObject
  • 1 个受保护的函数继承自 QPaintDevice
  • 1 个受保护的槽函数继承自 QWidget
  • 2 个受保护的变量继承自 QObject
  • 1 protected type inherited from QPaintDevice

详细描述

QLCDNumber 显示类似LCD样式的数字.

QLCDNumber 可以显示任意大小的数字. 它能显示十进制, 十六进制, 八进制, 二进制数字. 你可以使用槽函数 display() 连接任意数字源, 这个函数有不同参数类型的重载实现.

你可以调用 setMode() 设置不同进制, 调用 setSmallDecimalPoint()设置小数点精度.

QLCDNumber 在数字超出范围时发送信号 overflow(). 调用 setDigitCount()设置数字范围, 但是调用 setSmallDecimalPoint() 也会影响数字范围. 如果显示数字设置为十六进制, 八进制或二进制, QLCDNumber显示相等的整数值.

QLCDNumber支持的数字及符号是: 0/O, 1, 2, 3, 4, 5/S, 6, 7, 8, 9/g, 减号, 小数点, A, B, C, D, E, F, h, H, L, o, P, r, u, U, Y, 冒号, 度 (在字符串中为单引号) 和空格. QLCDNumber 使用空格代替非法字符.

虽然你可以调用value()获取数字, 但是无法获取 QLCDNumber 对象内容. 如果你想获取文本, 我们建议你连接槽函数 display() 时, 你可以连接一个其他槽函数存储值.

顺便说一句, QLCDNumber 是Qt最古老的部分, 它的根源可以追溯到 Sinclair Spectrum上的 BASIC 程序.

Screenshot of a Windows style LCD number widget Screenshot of a Windows Vista style LCD number widget Screenshot of a Macintosh style LCD number widget Screenshot of a Fusion style LCD number widget
LCD number widgets shown in various widget styles (from left to right): Windows, Windows Vista, Macintosh, Fusion.

参见 QLabel, QFrame, Digital Clock Example, and Tetrix Example.

成员类型

enum QLCDNumber::Mode

This type determines how numbers are shown.

ConstantValueDescription
QLCDNumber::Hex0Hexadecimal
QLCDNumber::Dec1Decimal
QLCDNumber::Oct2Octal
QLCDNumber::Bin3Binary

If the display is set to hexadecimal, octal or binary, the integer equivalent of the value is displayed.

enum QLCDNumber::SegmentStyle

This type determines the visual appearance of the QLCDNumber widget.

ConstantValueDescription
QLCDNumber::Outline0gives raised segments filled with the background color.
QLCDNumber::Filled1gives raised segments filled with the windowText color.
QLCDNumber::Flat2gives flat segments filled with the windowText color.

属性

digitCount : int

This property holds the current number of digits displayed

Corresponds to the current number of digits. If QLCDNumber::smallDecimalPoint is false, the decimal point occupies one digit position.

By default, this property contains a value of 5.

This property was introduced in Qt 4.6.

访问函数:

int digitCount() const
void setDigitCount(int numDigits)

参见 smallDecimalPoint.

intValue : int

This property holds the displayed value rounded to the nearest integer

This property corresponds to the nearest integer to the current value displayed by the LCDNumber. This is the value used for hexadecimal, octal and binary modes.

If the displayed value is not a number, the property has a value of 0.

By default, this property contains a value of 0.

访问函数:

int intValue() const
void display(const QString &s)
void display(int num)
void display(double num)

mode : Mode

This property holds the current display mode (number base)

Corresponds to the current display mode, which is one of Bin, Oct, Dec (the default) and Hex. Dec mode can display floating point values, the other modes display the integer equivalent.

访问函数:

Mode mode() const
void setMode(Mode)

参见 smallDecimalPoint(), setHexMode(), setDecMode(), setOctMode(), and setBinMode().

segmentStyle : SegmentStyle

This property holds the style of the LCDNumber

StyleResult
OutlineProduces raised segments filled with the background color
Filled (this is the default).Produces raised segments filled with the foreground color.
FlatProduces flat segments filled with the foreground color.

Outline and Filled will additionally use QPalette::light() and QPalette::dark() for shadow effects.

访问函数:

SegmentStyle segmentStyle() const
void setSegmentStyle(SegmentStyle)

smallDecimalPoint : bool

This property holds the style of the decimal point

If true the decimal point is drawn between two digit positions. Otherwise it occupies a digit position of its own, i.e. is drawn in a digit position. The default is false.

The inter-digit space is made slightly wider when the decimal point is drawn between the digits.

访问函数:

bool smallDecimalPoint() const
void setSmallDecimalPoint(bool)

参见 mode.

value : double

This property holds the displayed value

This property corresponds to the current value displayed by the LCDNumber.

If the displayed value is not a number, the property has a value of 0.

By default, this property contains a value of 0.

访问函数:

double value() const
void display(const QString &s)
void display(int num)
void display(double num)

成员函数

QLCDNumber::QLCDNumber(QWidget *parent = Q_NULLPTR)

Constructs an LCD number, sets the number of digits to 5, the base to decimal, the decimal point mode to 'small' and the frame style to a raised box. The segmentStyle() is set to Outline.

The parent argument is passed to the QFrame constructor.

参见 setDigitCount() and setSmallDecimalPoint().

QLCDNumber::QLCDNumber(uint numDigits, QWidget *parent = Q_NULLPTR)

Constructs an LCD number, sets the number of digits to numDigits, the base to decimal, the decimal point mode to 'small' and the frame style to a raised box. The segmentStyle() is set to Filled.

The parent argument is passed to the QFrame constructor.

参见 setDigitCount() and setSmallDecimalPoint().

QLCDNumber::~QLCDNumber()

Destroys the LCD number.

bool QLCDNumber::checkOverflow(double num) const

Returns true if num is too big to be displayed in its entirety; otherwise returns false.

参见 display(), digitCount(), and smallDecimalPoint().

bool QLCDNumber::checkOverflow(int num) const

This is an overloaded function.

Returns true if num is too big to be displayed in its entirety; otherwise returns false.

参见 display(), digitCount(), and smallDecimalPoint().

int QLCDNumber::digitCount() const

Returns the current number of digits.

Note: Getter function for property digitCount.

参见 setDigitCount().

[slot] void QLCDNumber::display(const QString &s)

Displays the number represented by the string s.

This version of the function disregards mode() and smallDecimalPoint().

These digits and other symbols can be shown: 0/O, 1, 2, 3, 4, 5/S, 6, 7, 8, 9/g, minus, decimal point, A, B, C, D, E, F, h, H, L, o, P, r, u, U, Y, colon, degree sign (which is specified as single quote in the string) and space. QLCDNumber substitutes spaces for illegal characters.

Note: Setter function for property intValue. Setter function for property value.

[slot] void QLCDNumber::display(int num)

This is an overloaded function.

Displays the number num.

Note: Setter function for property intValue. Setter function for property value.

[slot] void QLCDNumber::display(double num)

This is an overloaded function.

Displays the number num.

Note: Setter function for property intValue. Setter function for property value.

[virtual protected] bool QLCDNumber::event(QEvent *e)

重新实现 QObject::event().

[signal] void QLCDNumber::overflow()

This signal is emitted whenever the QLCDNumber is asked to display a too-large number or a too-long string.

It is never emitted by setDigitCount().

[virtual protected] void QLCDNumber::paintEvent(QPaintEvent *)

重新实现 QWidget::paintEvent().

[slot] void QLCDNumber::setBinMode()

Calls setMode(Bin). Provided for convenience (e.g. for connecting buttons to it).

参见 setMode(), setHexMode(), setDecMode(), setOctMode(), and mode().

[slot] void QLCDNumber::setDecMode()

Calls setMode(Dec). Provided for convenience (e.g. for connecting buttons to it).

参见 setMode(), setHexMode(), setOctMode(), setBinMode(), and mode().

void QLCDNumber::setDigitCount(int numDigits)

Sets the current number of digits to numDigits. Must be in the range 0..99.

Note: Setter function for property digitCount.

参见 digitCount().

[slot] void QLCDNumber::setHexMode()

Calls setMode(Hex). Provided for convenience (e.g. for connecting buttons to it).

参见 setMode(), setDecMode(), setOctMode(), setBinMode(), and mode().

[slot] void QLCDNumber::setOctMode()

Calls setMode(Oct). Provided for convenience (e.g. for connecting buttons to it).

参见 setMode(), setHexMode(), setDecMode(), setBinMode(), and mode().

[virtual] QSize QLCDNumber::sizeHint() const

重新实现 QWidget::sizeHint().