QSlider Class

QSlider 提供一个水平或垂直滑块. 更多...

头文件: #include <QSlider>
qmake: QT += widgets
基类: QAbstractSlider

公有类型

enum TickPosition { NoTicks, TicksBothSides, TicksAbove, TicksBelow, TicksLeft, TicksRight }

属性

公有函数

QSlider(QWidget *parent = Q_NULLPTR)
QSlider(Qt::Orientation orientation, QWidget *parent = Q_NULLPTR)
~QSlider()
void setTickInterval(int ti)
void setTickPosition(TickPosition position)
int tickInterval() const
TickPosition tickPosition() const

重新实现的公有函数

virtual bool event(QEvent *event)
virtual QSize minimumSizeHint() const
virtual QSize sizeHint() const

受保护的函数

void initStyleOption(QStyleOptionSlider *option) const

重新实现的受保护函数

virtual void mouseMoveEvent(QMouseEvent *ev)
virtual void mousePressEvent(QMouseEvent *ev)
virtual void mouseReleaseEvent(QMouseEvent *ev)
virtual void paintEvent(QPaintEvent *ev)

其他继承的成员

详细描述

QSlider 提供一个水平或垂直滑块.

滑动条是控制一个有界值的经典widget. 它允许用户沿水平或垂直槽移动滑块, 并将滑块位置转换为合法范围内的整数值.

QSlider 实现的函数很少; 大部分函数都继承自 QAbstractSlider. 最有用的函数是 setValue() , 直接设置滑块值; triggerAction() 模拟单击的效果(对快捷键有用); setSingleStep(), setPageStep() 设置步长; and setMinimum() 和 setMaximum() 设置滚动条范围.

QSlider 提供了控制刻度线的方法. 你可以调用 setTickPosition() 设置刻度线的位置, 调用setTickInterval() 设置刻度线间隔. 调用 tickPosition() 和 tickInterval() 函数查询当前设置的刻度线位置和间隔.

QSlider 继承一组全面的信号:

SignalDescription
valueChanged()Emitted when the slider's value has changed. The tracking() determines whether this signal is emitted during user interaction.
sliderPressed()Emitted when the user starts to drag the slider.
sliderMoved()Emitted when the user drags the slider.
sliderReleased()Emitted when the user releases the slider.

QSlider 仅提供整数范围. 注意: 尽管 QSlider 处理非常大的数字,但用户很难在非常大的范围内准确地使用滑块.

滑块接受Tab焦点, 并提供鼠标滚轮和键盘操作. 键盘操作定义如下:

  • Left/Right 移动水平滑块一步.
  • Up/Down 移动垂直滑块一步.
  • PageUp 向上移动一页.
  • PageDown 向下移动一页.
  • Home 移动滑块到起点(最小值).
  • End 移动滑块到终点(最大值).
Screenshot of a Macintosh sliderA slider shown in the Macintosh widget style.
Screenshot of a Windows Vista sliderA slider shown in the Windows Vista widget style.
Screenshot of a Fusion sliderA slider shown in the Fusion widget style.

参见 QScrollBar, QSpinBox, QDial, GUI Design Handbook: Slider, Sliders Example.

成员类型

enum QSlider::TickPosition

This enum specifies where the tick marks are to be drawn relative to the slider's groove and the handle the user moves.

ConstantValueDescription
QSlider::NoTicks0Do not draw any tick marks.
QSlider::TicksBothSides3Draw tick marks on both sides of the groove.
QSlider::TicksAbove1Draw tick marks above the (horizontal) slider
QSlider::TicksBelow2Draw tick marks below the (horizontal) slider
QSlider::TicksLeftTicksAboveDraw tick marks to the left of the (vertical) slider
QSlider::TicksRightTicksBelowDraw tick marks to the right of the (vertical) slider

属性

tickInterval : int

This property holds the interval between tickmarks

This is a value interval, not a pixel interval. If it is 0, the slider will choose between singleStep and pageStep.

The default value is 0.

访问函数:

int tickInterval() const
void setTickInterval(int ti)

参见 tickPosition, singleStep, and pageStep.

tickPosition : TickPosition

This property holds the tickmark position for this slider

The valid values are described by the QSlider::TickPosition enum.

The default value is QSlider::NoTicks.

访问函数:

TickPosition tickPosition() const
void setTickPosition(TickPosition position)

参见 tickInterval.

成员函数

QSlider::QSlider(QWidget *parent = Q_NULLPTR)

Constructs a vertical slider with the given parent.

QSlider::QSlider(Qt::Orientation orientation, QWidget *parent = Q_NULLPTR)

Constructs a slider with the given parent. The orientation parameter determines whether the slider is horizontal or vertical; the valid values are Qt::Vertical and Qt::Horizontal.

QSlider::~QSlider()

Destroys this slider.

[virtual] bool QSlider::event(QEvent *event)

重新实现 QObject::event().

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

Initialize option with the values from this QSlider. This method is useful for subclasses when they need a QStyleOptionSlider, but don't want to fill in all the information themselves.

参见 QStyleOption::initFrom().

[virtual] QSize QSlider::minimumSizeHint() const

重新实现 QWidget::minimumSizeHint().

[virtual protected] void QSlider::mouseMoveEvent(QMouseEvent *ev)

重新实现 QWidget::mouseMoveEvent().

[virtual protected] void QSlider::mousePressEvent(QMouseEvent *ev)

重新实现 QWidget::mousePressEvent().

[virtual protected] void QSlider::mouseReleaseEvent(QMouseEvent *ev)

重新实现 QWidget::mouseReleaseEvent().

[virtual protected] void QSlider::paintEvent(QPaintEvent *ev)

重新实现 QWidget::paintEvent().

[virtual] QSize QSlider::sizeHint() const

重新实现 QWidget::sizeHint().