(1)源代码来自于头文件 qdial . h :
#ifndef QDIAL_H
#define QDIAL_H
#include <QtWidgets/qtwidgetsglobal.h>
#include <QtWidgets/qabstractslider.h>
QT_REQUIRE_CONFIG(dial);
QT_BEGIN_NAMESPACE
class 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 QAbstractSlider
QT_END_NAMESPACE
#endif // QDIAL_H
(2)
(3)
谢谢