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

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)

谢谢

http://www.xdnf.cn/news/5295.html

相关文章:

  • Windows报错:OSError: [WinError 1455] 页面文件太小,无法完成操作的问题
  • Redis能保证数据不丢失吗之RDB
  • 【Web】使用Vue3开发鸿蒙的HelloWorld!
  • 模拟太阳系(C#编写的maui跨平台项目源码)
  • Autoware message_filters::Synchronizer链接错误问题
  • Axure疑难杂症:统计分析页面引入Echarts示例动态效果
  • 目录粘滞位的使用
  • JDBC链接数据库
  • 【typenum】 0 配置文件(Cargo.toml)
  • 【MySQL】事务(重点)
  • 酒店洗护用品那些事儿:品牌选择及扬州卓韵用品介绍
  • 6. 存储池配置与CephFS创建 ceph version 14.2.22
  • muduo源码解析
  • 【第33节 数据库基础概念】
  • 游戏引擎学习第269天:清理菜单绘制
  • [模型选择与调优]机器学习-part4
  • PyTorch API 6 - 编译、fft、fx、函数转换、调试、符号追踪
  • HTTP 请求中 Content-Type 头部
  • 使用谱聚类将相似度矩阵分为2类
  • 2025年RAG技术有哪些创新点?
  • 海市蜃楼的形成原理
  • M0的基础篇之PWM学习
  • adb命令查询不到设备?
  • 第二个简单的SpringBoot和Vue前后端全栈的todoapp案例
  • 告别“感觉良好”:深入RAG评估,从方法、工具到指标的全方位指南
  • Telnetlib三种异常处理方案
  • ROM详解
  • Nvidia Isaac Sim组装机器人和添加传感器,创建关节树Articulation
  • 基于 RAG 的 Agent(LangChain实现)
  • 中小型工厂数字化转型:传统工艺的“生死劫”?