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

QT6 源(79):阅读与注释表盘 QDial 的源码,其是基类QAbstractSlider 的子类,及其刻度线的属性举例

(1)源代码来自于头文件 qdial . h

#ifndef QDIAL_H
#define QDIAL_H#include <QtWidgets/qtwidgetsglobal.h>#include <QtWidgets/qabstractslider.h>QT_REQUIRE_CONFIG(dial);QT_BEGIN_NAMESPACEclass QDialPrivate;
class QStyleOptionSlider;/*
The QDial class provides a rounded range control
(like a speedometer or potentiometer) QDial类提供了一个圆角范围控件(类似于速度表或电位计).当用户需要在程序可定义范围内控制一个值,且该范围可以循环
(例如,从0到359度测量角度)或对话框布局需要方形控件时,应使用QDial。由于 QDial 继承自 QAbstractSlider,因此该刻度盘的行为与滑块类似。
当wrap()为false(默认设置)时,滑块和刻度盘之间没有真正的区别。
它们共享相同的信号、槽和成员函数。您选择使用哪个取决于用户的期望和应用程序的类型。当滑块移动时,刻度盘最初会连续发出valueChanged()信号;
you can make it emit the signal less often by disabling the tracking property.
The sliderMoved() signal is emitted continuously even when tracking is disabled.当鼠标按钮按下和释放时,旋钮还会发出sliderPressed()和sliderReleased()信号。
请注意,旋钮的值可以在不发出这些信号的情况下改变,因为键盘和轮子也可以用来改变值。与滑块不同,QDial尝试绘制“良好”数量的刻痕,而不是每行一个刻痕。
如果可能,绘制的刻痕数量是每行一个,
但如果没有足够的像素绘制每个刻痕,ODial将跳过刻痕,尝试绘制一组均匀的刻痕
(例如,每两个或三个刻痕绘制一个)。
与滑块一样,刻度盘使 QAbstractSlider的setValue() 函数作为槽可用。刻度盘的键盘界面相当简单:左/上键和右/下键通过定义的singleStep调整刻度盘值,
Page Up和Page Down通过定义的pageStep调整,Home和End键将值设置为定义的最低和最高值。
如果您使用鼠标滚轮来调整刻度盘,
则增量值由滚轮 ScrollLines的较小值乘以 singleStep和 pageStep确定。*/class Q_WIDGETS_EXPORT QDial: public QAbstractSlider
{Q_OBJECT//This property holds whether the notches are shown。//If the property is true, a series of notches are drawn around the dial to//indicate the range of values available; otherwise no notches are shown.//By default, this property is disabled.Q_PROPERTY(bool  notchesVisible READ notchesVisible WRITE setNotchesVisible)//notch 槽口,凹口,凹痕;(用来计数的木签上的)刻痕;等;//This property holds the target number of pixels between notches。//The notch target is the number of pixels QDial attempts to put between each//notch. The actual size may differ from the target size.//The default notch target is 3.7 pixels.//此属性包含凹槽之间的目标像素数。//凹口目标是指 QDial在每个凹口之间尝试放置的像素数。实际大小可能与目标大小不同。//默认的缺口目标值为3.7像素。Q_PROPERTY(qreal notchTarget READ notchTarget WRITE setNotchTarget)Q_PROPERTY(int   notchSize   READ notchSize) //本属性在 UI 界面不可见。本属性是只读的//This property holds the current notch size。//The notch size is in range control units, not pixels, and is calculated to//be a multiple of singleStep() that results in//an on-screen notch size near notchTarget().//此属性保存当前凹口大小。//凹口大小是以控制单位(而不是像素)计算的,并计算为singleStep()的倍数,//从而产生接近 notchTarget()的屏幕凹口大小。//This property holds whether wrapping is enabled。//If true, wrapping is enabled; otherwise some space is inserted at the//bottom of the dial to separate the ends of the range of valid values.//If enabled, the arrow can be oriented at any angle on the dial.//If disabled, the arrow will be restricted to the upper part of the dial;//if it is rotated into the space at the bottom of the dial,//it will be clamped to the closest end of the valid range of values.//By default this property is false.Q_PROPERTY(bool  wrapping READ wrapping WRITE setWrapping)private:Q_DECLARE_PRIVATE(QDial)Q_DISABLE_COPY(QDial)public://Constructs a dial.//The parent argument is sent to the QAbstractSlider constructor.explicit QDial(QWidget * parent = nullptr);~QDial();//Q_PROPERTY(bool  notchesVisible READ notchesVisible WRITE setNotchesVisible)bool       notchesVisible() const;
public Q_SLOTS:void    setNotchesVisible(bool visible);public://Q_PROPERTY(qreal notchTarget READ notchTarget WRITE setNotchTarget)qreal      notchTarget() const;void    setNotchTarget(double target);//Q_PROPERTY(int   notchSize   READ notchSize) //本属性在 UI 界面不可见。本属性是只读的int        notchSize() const;//Q_PROPERTY(bool  wrapping READ wrapping WRITE setWrapping)bool       wrapping() const;
public Q_SLOTS:void    setWrapping(bool on);public:QSize        sizeHint() const override;QSize minimumSizeHint() const override;public Q_SLOTS://void setNotchesVisible(bool visible);//void setWrapping(bool on);protected:bool             event(QEvent *e) override;void       resizeEvent(QResizeEvent *re) override;void        paintEvent(QPaintEvent *pe) override;void   mousePressEvent(QMouseEvent *me) override;void mouseReleaseEvent(QMouseEvent *me) override;void    mouseMoveEvent(QMouseEvent *me) override;virtual void initStyleOption(QStyleOptionSlider * option) const;void sliderChange(SliderChange change) override;
/*  //这是重写父类的普通成员函数
class QAbstractSlider : public QWidget
{enum SliderChange {SliderRangeChange      ,SliderOrientationChange,SliderStepsChange      ,SliderValueChange};
};
*/}; //完结 class QDial: public QAbstractSliderQT_END_NAMESPACE#endif // QDIAL_H

(2)

在这里插入图片描述

(3)

谢谢

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

相关文章:

  • 深入理解 CSS Flex 布局:代码实例解析
  • 【Hive入门】Hive安全管理与权限控制:基于SQL标准的授权GRANT REVOKE深度解析
  • kotlin 05flow -从 LiveData 迁移到 Kotlin Flow 完整教程
  • 用Python打造自己的专属命令行工具
  • 手写 Vue 源码 === reactive 方法
  • 判断题材持续性
  • Redis的过期设置和策略
  • rocketMq win10安装并注册服务 centos7安装
  • 嵌软笔记名词汇总
  • C++基础知识1:内建数据类型 vs 自定义数据类型
  • 豆包多轮对话优化策略:上下文理解与记忆,意图识别,对话管理
  • 力扣每日一题1128等价多米诺骨牌对的数量
  • C++和Lua混和调用
  • 什么是加油站专用可燃气体磁吸无线检测探测器
  • 小米刷新率 2.4 | 突破屏幕刷新率限制,享受更流畅视觉体验的应用程序
  • 《类和对象(上)》
  • 架构思维:构建高并发读服务_基于流量回放实现读服务的自动化测试回归方案
  • 直方图比较
  • SecureCRT 使用指南:安装、设置与高效操作
  • springboot+mysql+element-plus+vue完整实现汽车租赁系统
  • 文本三剑客试题
  • 【Elasticsearch入门到落地】12、索引库删除判断以及文档增删改查
  • 【Leetcode 每日一题 - 补卡】1128. 等价多米诺骨牌对的数量
  • 【Unity】AssetBundle热更新
  • Java中线程间数据共享:ThreadLocal与ScopedValue
  • 二、【LLaMA-Factory实战】数据工程全流程:从格式规范到高质量数据集构建
  • Qt 显示QRegExp 和 QtXml 不存在问题
  • 线程池配置不合理:系统性能的隐形杀手(深度解析版)
  • Python基本环境搭配
  • 代码随想录第32天:动态规划5(组合、排列、最小方法数)