QDial 类

QDial 类提供四舍五入范围控制 (像速度计或电位计)。 更多...

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

特性

公共函数

QDial (QWidget * parent = nullptr)
virtual ~QDial ()
int notchSize () const
qreal notchTarget () const
bool notchesVisible () const
void setNotchTarget (double target )
bool wrapping () const

重实现公共函数

virtual QSize minimumSizeHint () const override
virtual QSize sizeHint () const override

公共槽

void setNotchesVisible (bool visible )
void setWrapping (bool on )

保护函数

virtual void initStyleOption (QStyleOptionSlider * option ) const

重实现保护函数

virtual bool event (QEvent * e ) override
virtual void mouseMoveEvent (QMouseEvent * e ) override
virtual void mousePressEvent (QMouseEvent * e ) override
virtual void mouseReleaseEvent (QMouseEvent * e ) override
virtual void paintEvent (QPaintEvent * pe ) override
virtual void resizeEvent (QResizeEvent * e ) override
virtual void sliderChange (QAbstractSlider::SliderChange change ) override

详细描述

QDial is used when the user needs to control a value within a program-definable range, and the range either wraps around (for example, with angles measured from 0 to 359 degrees) or the dialog layout needs a square widget.

由于 QDial 继承自 QAbstractSlider , the dial behaves in a similar way to a slider 。当 wrapping () is false (the default setting) there is no real difference between a slider and a dial. They both share the same signals, slots and member functions. Which one you use depends on the expectations of your users and on the type of application.

The dial initially emits valueChanged () signals continuously while the slider is being moved; 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.

The dial also emits sliderPressed () 和 sliderReleased () signals when the mouse button is pressed and released. Note that the dial's value can change without these signals being emitted since the keyboard and wheel can also be used to change the value.

Unlike the slider, QDial attempts to draw a "nice" number of notches rather than one per line step. If possible, the number of notches drawn is one per line step, but if there aren't enough pixels to draw every one, QDial will skip notches to try and draw a uniform set (e.g. by drawing every second or third notch).

Like the slider, the dial makes the QAbstractSlider function setValue () available as a slot.

The dial's keyboard interface is fairly simple: The left / up and right / down arrow keys adjust the dial's value by the defined singleStep , Page Up and Page Down by the defined pageStep ,和 Home and End keys set the value to the defined minimum and maximum 值。

If you are using the mouse wheel to adjust the dial, the increment value is determined by the lesser value of wheelScrollLines multiplied by singleStep ,和 pageStep .

另请参阅 QScrollBar , QSpinBox , QSlider ,和 滑块范例 .

特性文档编制

[read-only] notchSize : const int

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 ().

访问函数:

int notchSize () const

另请参阅 notchTarget () 和 singleStep ().

notchTarget : qreal

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.

访问函数:

qreal notchTarget () const
void setNotchTarget (double target )

notchesVisible : bool

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.

访问函数:

bool notchesVisible () const
void setNotchesVisible (bool visible )

wrapping : bool

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.

默认情况下此特性为 false .

访问函数:

bool wrapping () const
void setWrapping (bool on )

成员函数文档编制

[explicit] QDial:: QDial ( QWidget * parent = nullptr)

Constructs a dial.

The parent 自变量被发送给 QAbstractSlider 构造函数。

[虚拟] QDial:: ~QDial ()

Destroys the dial.

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

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

[virtual protected] void QDial:: initStyleOption ( QStyleOptionSlider * option ) const

初始化 option 采用值来自此 QDial 。此方法对子类是有用的,当需要 QStyleOptionSlider ,但不希望自己填充所有信息。

另请参阅 QStyleOption::initFrom ().

[override virtual] QSize QDial:: minimumSizeHint () const

重实现访问函数为特性: QWidget::minimumSizeHint .

[override virtual protected] void QDial:: mouseMoveEvent ( QMouseEvent * e )

重实现: QWidget::mouseMoveEvent (QMouseEvent *event).

[override virtual protected] void QDial:: mousePressEvent ( QMouseEvent * e )

重实现: QWidget::mousePressEvent (QMouseEvent *event).

[override virtual protected] void QDial:: mouseReleaseEvent ( QMouseEvent * e )

重实现: QWidget::mouseReleaseEvent (QMouseEvent *event).

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

重实现: QWidget::paintEvent (QPaintEvent *event).

[override virtual protected] void QDial:: resizeEvent ( QResizeEvent * e )

重实现: QWidget::resizeEvent (QResizeEvent *event).

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

重实现访问函数为特性: QWidget::sizeHint .

[override virtual protected] void QDial:: sliderChange ( QAbstractSlider::SliderChange change )

重实现: QAbstractSlider::sliderChange (QAbstractSlider::SliderChange change).