当前位置: 首页 > news >正文

QT6 源(90):阅读与注释 LCD显示类 QLCDNumber ,源代码以及属性测试。该类继承于容器框架 QFrame

(1)本类所在的类继承关系如下

在这里插入图片描述

(2)segmentStyle 属性,后俩属性的区别很小 :

在这里插入图片描述
++

在这里插入图片描述

(3) smallDecimalPoint 属性

在这里插入图片描述

(4) 本 LCD 不仅可以展示数字,也可以展示内容是数字的文本,还可以带温度的度数标识

在这里插入图片描述

(5) 关于溢出信号的测试

在这里插入图片描述

(6)本源代码来自于头文件 qlcdnumber . h

#ifndef QLCDNUMBER_H
#define QLCDNUMBER_H#include <QtWidgets/qtwidgetsglobal.h>
#include <QtWidgets/qframe.h>QT_BEGIN_NAMESPACE // 说明本类定义于 QT的全局命名空间里QT_REQUIRE_CONFIG(lcdnumber);class QLCDNumberPrivate;/*
The QLCDNumber widget displays a number with LCD-like digits.它可以显示几乎任何大小的数字。它可以显示小数、十六进制、八进制或二进制数字。
使用display()槽可以轻松连接到数据源,该槽被重载以接受五种参数类型中的任何一种。
还有用于使用 setMode()更改基数和 setSmallDecimalPoint()更改小数点的位置。
当QLCDNumber被要求显示超出其范围的内容时,它会发出overflow()信号。
范围由setDigitcount()设置,但setSmallDecimalPoint()也会影响它。
如果显示设置为十六进制八进制或二进制,则显示值的整数等效值。可以显示这些数字和其他符号:0/O、1、2、3、4、5/S、6、7、8、9/g、减号、小数点、
A、B、C、D、EF、h、H、L、0、P、r、u、U、Y、冒号、度数符号(在字符串中指定为单引号)和空格。
QLCDNumber将空格替换为非法字符。
无法检索 QLCDNumber对象的内容,但您可以使用 value()检索数值。
如果您确实需要文本,我们建议您将传递到display()槽的信号也连接到另一个槽,并在那里存储值。
顺便说一下,QLCDNumber是Qt中最古老的部分,它的根源可以追溯到Sinclair Spectrum上的一个BASIC程序。*/class Q_WIDGETS_EXPORT QLCDNumber : public QFrame // LCD number widget
{Q_OBJECT //插入此宏,以使用 Qt的元对象系统//此属性保存显示值,将其四舍五入到最接近的整数。//此属性对应于LCDNumber显示的当前值的最近整数。这是十六进制、八进制和二进制模式使用的值。//如果显示值不是数字,则该属性的值为0。   默认情况下,此属性包含值为 0。Q_PROPERTY(int    intValue   READ intValue   WRITE display)  //±整数Q_PROPERTY(Mode   mode       READ mode       WRITE setMode)  //整数的进制 2 8 10 16//此属性保存当前显示模式(数字进制)。//对应当前的显示模式,这是Bin、Oct、Dec(默认)和Hex模式之一。//Dec模式可以显示浮点数,其他模式显示整数等效值。//此属性保存显示值。此属性对应于LCDNumber显示的当前值。//如果显示值不是数字,则该属性的值为0。 默认情况下,此属性包含值为 0。Q_PROPERTY(double value      READ    value   WRITE display)  //浮点数Q_PROPERTY(bool   smallDecimalPoint // 此属性为 true 就是表示把小数点小一点来显示。READ   smallDecimalPoint WRITE setSmallDecimalPoint) //默认为 false//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.//Returns the current number of digits. 若显示小数点,则小数点始终占据其中的一位Q_PROPERTY(int   digitCount  READ digitCount WRITE setDigitCount) //显示总位数Q_PROPERTY(SegmentStyle segmentStyle READ segmentStyle WRITE setSegmentStyle)//This property holds the style of the LCDNumber。//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.//                                ---- 生成填充前景色的平面片段。private:Q_DISABLE_COPY(QLCDNumber)Q_DECLARE_PRIVATE(QLCDNumber)public://构造一个LCD数字,设置数字位数为5,基数为十进制,小数点模式为“小”,框架样式为凸起框。//segmentStyle()被设置为Outline。父类参数传递给 QFrame 构造函数。explicit QLCDNumber(QWidget * parent = nullptr);explicit 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() is set to Filled.//The parent argument is passed to the QFrame constructor.~QLCDNumber();enum Mode         { Hex, Dec, Oct, Bin };Q_ENUM(Mode)enum SegmentStyle { Outline, Filled, Flat };Q_ENUM(SegmentStyle)//Q_PROPERTY(int    intValue   READ intValue   WRITE display)  //±整数int     intValue()  const; //这是个读函数
public Q_SLOTS:void    display(int  num); //这是个写函数public :
//Q_PROPERTY(Mode     mode       READ  mode    WRITE setMode)  //整数的进制 2 8 10 16Mode     mode() const;void  setMode(Mode);  //此函数并不是槽函数
public Q_SLOTS:void  setHexMode();   //这些不带形参的才是槽函数void  setDecMode();void  setOctMode();void  setBinMode();public :
//Q_PROPERTY(double   value      READ  value   WRITE display)  //浮点数double   value() const;
public Q_SLOTS:void     display(double num);public :
//Q_PROPERTY(bool    smallDecimalPoint // 此属性为 true 就是表示把小数点小一点来显示。
//           READ    smallDecimalPoint WRITE setSmallDecimalPoint) //默认为 falsebool    smallDecimalPoint() const;
public Q_SLOTS:void setSmallDecimalPoint(bool);public :
//Q_PROPERTY(int     digitCount  READ digitCount WRITE setDigitCount) //显示总位数int     digitCount() const;void setDigitCount(int nDigits);//Q_PROPERTY(SegmentStyle    segmentStyle READ segmentStyle WRITE setSegmentStyle)SegmentStyle    segmentStyle() const;void setSegmentStyle(SegmentStyle);bool checkOverflow(int    num) const;bool checkOverflow(double num) const;//Returns true if num is too big to be displayed in its entirety;//otherwise returns false.QSize sizeHint() const override;public Q_SLOTS://void display(int    num);//void display(double num);void   display(const QString & str);//显示由字符串str表示的数字。 此版本的函数忽路mode()和smallDecimalPoint()//可以显示这些数字和其他符号:0/O、1、2、3、4、5/S、6、7、8、9/g、减号、小数点、A、B、C//D、E、F、h、H、L、0、P、r、y、U、Y、冒号、度数符号(在字符串中指定为单引号)//和空格QLCDNumber将空格替换为非法字符。//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.//以下是另一些槽函数://void setSmallDecimalPoint(bool);//void setHexMode();//void setDecMode();//void setOctMode();//void setBinMode();Q_SIGNALS:void overflow();//This signal is emitted whenever the QLCDNumber is asked to display a//too-large number or a too-long string.protected:bool      event(QEvent      * e) override;void paintEvent(QPaintEvent *  ) override;}; //完结 class QLCDNumber : public QFrameQT_END_NAMESPACE#endif // QLCDNUMBER_H

(7)

谢谢

相关文章:

  • 用tinyb210实现srsran小基站
  • C/C++复习-- C语言初始基础
  • 物联网之使用Vertx实现MQTT-Server最佳实践【响应式】
  • Spring事务管理实现机制
  • Halcon检测项目
  • 深入浅出之STL源码分析3_类模版实例化与特化
  • Shell 脚本编程1(常用命令+概述)
  • 金丝猴食品:智能中枢AI-COP构建全链路数智化运营体系
  • C++ 异常捕获 try 和 __try的区别笔记
  • Python环境搭建指南
  • 慈缘基金会“蝴蝶飞”助西藏女孩白玛卓嘎“折翼重生”
  • 基于STM32的居家环境监测报警Proteus仿真+程序设计+设计报告+讲解视频
  • smbd:快速拉取服務端SMB共享文件脚本工具
  • SAM详解3.2(关于2和3的题)
  • 黑马k8s(二)
  • 子串简写(JAVA)一维前缀和, 蓝桥杯
  • 学习黑客5 分钟深入浅出理解cron [特殊字符]
  • 基于阿伦尼斯模型的电池寿命预测:原理、应用与挑战
  • 【智能指针】
  • SD06_前后端分离项目部署流程(采用Nginx)
  • 菲律宾举行中期选举
  • 中方发布会:中美经贸高层会谈氛围是坦诚的、深入的、具有建设性的
  • 水豚出逃40天至今未归,江苏扬州一动物园发悬赏公告
  • 洲际酒店:今年第一季度全球酒店平均客房收入同比增长3.3%
  • 一季度全国消协组织为消费者挽回经济损失23723万元
  • AI智能体,是不是可以慢一点? | ToB产业观察