QLCDNumber 类

QLCDNumber 小部件显示带有类似 LCD 数字的数字。 更多...

头: #include <QLCDNumber>
CMake: find_package(Qt6 REQUIRED COMPONENTS Widgets)
target_link_libraries(mytarget PRIVATE Qt6::Widgets)
qmake: QT += widgets
继承: QFrame

公共类型

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

特性

公共函数

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

重实现公共函数

virtual QSize sizeHint () const override

公共槽

void display (const QString & s )
void display (int num )
void display (double num )
void setBinMode ()
void setDecMode ()
void setHexMode ()
void setOctMode ()
void setSmallDecimalPoint (bool)

信号

void overflow ()

重实现保护函数

virtual bool event (QEvent * e ) override
virtual void paintEvent (QPaintEvent *) override

详细描述

It can display a number in just about any size. It can display decimal, hexadecimal, octal or binary numbers. It is easy to connect to data sources using the display () slot, which is overloaded to take any of five argument types.

There are also slots to change the base with setMode () and the decimal point with setSmallDecimalPoint ().

QLCDNumber emits the overflow () signal when it is asked to display something beyond its range. The range is set by setDigitCount (),但 setSmallDecimalPoint () also influences it. If the display is set to hexadecimal, octal or binary, the integer equivalent of the value is displayed.

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.

It is not possible to retrieve the contents of a QLCDNumber object, although you can retrieve the numeric value with value (). If you really need the text, we recommend that you connect the signals that feed the display () slot to another slot as well and store the value there.

Incidentally, QLCDNumber is the very oldest part of Qt, tracing its roots back to a BASIC program on the Sinclair Spectrum .

另请参阅 QLabel , QFrame , 数字时钟范例 ,和 俄罗斯方块范例 .

成员类型文档编制

enum QLCDNumber:: Mode

This type determines how numbers are shown.

常量 描述
QLCDNumber::Hex 0 Hexadecimal
QLCDNumber::Dec 1 Decimal
QLCDNumber::Oct 2 Octal
QLCDNumber::Bin 3 Binary

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 小部件。

常量 描述
QLCDNumber::Outline 0 gives raised segments filled with the background color.
QLCDNumber::Filled 1 gives raised segments filled with the windowText color.
QLCDNumber::Flat 2 gives 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.

访问函数:

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.

默认情况下,此特性包含 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.

访问函数:

QLCDNumber::Mode mode () const
void setMode (QLCDNumber::Mode)

另请参阅 smallDecimalPoint (), setHexMode (), setDecMode (), setOctMode (),和 setBinMode ().

segmentStyle : SegmentStyle

This property holds the style of the LCDNumber

Style 结果
Outline Produces raised segments filled with the background color
Filled (this is the default). Produces raised segments filled with the foreground color.
Flat Produces flat segments filled with the foreground color.

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

访问函数:

QLCDNumber::SegmentStyle segmentStyle () const
void setSegmentStyle (QLCDNumber::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.

默认情况下,此特性包含 0 值。

访问函数:

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

成员函数文档编制

[explicit] QLCDNumber:: QLCDNumber ( QWidget * parent = 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 () 被设为 Outline .

The parent 自变量会被传递给 QFrame 构造函数。

另请参阅 setDigitCount () 和 setSmallDecimalPoint ().

[explicit] QLCDNumber:: QLCDNumber ( uint numDigits , QWidget * parent = 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 () 被设为 Filled .

The parent 自变量会被传递给 QFrame 构造函数。

另请参阅 setDigitCount () 和 setSmallDecimalPoint ().

[虚拟] QLCDNumber:: ~QLCDNumber ()

Destroys the LCD number.

bool QLCDNumber:: checkOverflow ( double num ) const

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

另请参阅 display (), digitCount (),和 smallDecimalPoint ().

bool QLCDNumber:: checkOverflow ( int num ) const

这是重载函数。

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

另请参阅 display (), digitCount (),和 smallDecimalPoint ().

int QLCDNumber:: digitCount () const

Returns the current number of digits.

注意: 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 () 和 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.

注意: setter 函数对于特性 intValue . Setter function for property value .

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

这是重载函数。

Displays the number num .

注意: setter 函数对于特性 intValue . Setter function for property value .

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

这是重载函数。

Displays the number num .

注意: setter 函数对于特性 intValue . Setter function for property value .

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

重实现: QFrame::event (QEvent *e).

[signal] void QLCDNumber:: overflow ()

此信号被发射每当 QLCDNumber is asked to display a too-large number or a too-long string.

It is never emitted by setDigitCount ().

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

重实现: QFrame::paintEvent (QPaintEvent *).

[slot] void QLCDNumber:: setBinMode ()

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

另请参阅 setMode (), setHexMode (), setDecMode (), setOctMode (),和 mode ().

[slot] void QLCDNumber:: setDecMode ()

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

另请参阅 setMode (), setHexMode (), setOctMode (), setBinMode (),和 mode ().

void QLCDNumber:: setDigitCount ( int numDigits )

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

注意: setter 函数对于特性 digitCount .

另请参阅 digitCount ().

[slot] void QLCDNumber:: setHexMode ()

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

另请参阅 setMode (), setDecMode (), setOctMode (), setBinMode (),和 mode ().

[slot] void QLCDNumber:: setOctMode ()

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

另请参阅 setMode (), setHexMode (), setDecMode (), setBinMode (),和 mode ().

[override virtual] QSize QLCDNumber:: sizeHint () const

重实现: QFrame::sizeHint() const .