QSlider Class
头文件: | #include <QSlider> |
qmake: | QT += widgets |
基类: | QAbstractSlider |
公有类型
enum | TickPosition { NoTicks, TicksBothSides, TicksAbove, TicksBelow, TicksLeft, TicksRight } |
属性
- tickInterval : int
- tickPosition : TickPosition
- 11 个属性继承自 QAbstractSlider
- 59 个属性继承自 QWidget
- 1 个属性继承自 QObject
公有函数
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 |
- 21 个公有函数继承自 QAbstractSlider
- 214 个公有函数继承自 QWidget
- 32 个公有函数继承自 QObject
- 14 个公有函数继承自 QPaintDevice
受保护的函数
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) |
- 8 个受保护的函数继承自 QAbstractSlider
- 35 个受保护的函数继承自 QWidget
- 9 个受保护的函数继承自 QObject
- 1 个受保护的函数继承自 QPaintDevice
其他继承的成员
- 3 个公有槽函数继承自 QAbstractSlider
- 19 个公有槽函数继承自 QWidget
- 1 个公有槽函数继承自 QObject
- 6 个信号继承自 QAbstractSlider
- 3 个信号继承自 QWidget
- 2 个信号继承自 QObject
- 1 个公有变量继承自 QObject
- 5 个静态公有成员继承自 QWidget
- 10 个静态公有成员继承自 QObject
- 1 个受保护的槽函数继承自 QWidget
- 2 个受保护的变量继承自 QObject
- 1 protected type inherited from QPaintDevice
详细描述
QSlider 提供一个水平或垂直滑块.
滑动条是控制一个有界值的经典widget. 它允许用户沿水平或垂直槽移动滑块, 并将滑块位置转换为合法范围内的整数值.
QSlider 实现的函数很少; 大部分函数都继承自 QAbstractSlider. 最有用的函数是 setValue() , 直接设置滑块值; triggerAction() 模拟单击的效果(对快捷键有用); setSingleStep(), setPageStep() 设置步长; and setMinimum() 和 setMaximum() 设置滚动条范围.
QSlider 提供了控制刻度线的方法. 你可以调用 setTickPosition() 设置刻度线的位置, 调用setTickInterval() 设置刻度线间隔. 调用 tickPosition() 和 tickInterval() 函数查询当前设置的刻度线位置和间隔.
QSlider 继承一组全面的信号:
Signal | Description |
---|---|
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 移动滑块到终点(最大值).
![]() | A slider shown in the Macintosh widget style. |
![]() | A slider shown in the Windows Vista widget style. |
![]() | A 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.
Constant | Value | Description |
---|---|---|
QSlider::NoTicks | 0 | Do not draw any tick marks. |
QSlider::TicksBothSides | 3 | Draw tick marks on both sides of the groove. |
QSlider::TicksAbove | 1 | Draw tick marks above the (horizontal) slider |
QSlider::TicksBelow | 2 | Draw tick marks below the (horizontal) slider |
QSlider::TicksLeft | TicksAbove | Draw tick marks to the left of the (vertical) slider |
QSlider::TicksRight | TicksBelow | Draw 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().