6.0.0-rc4Source

QAbstractSlider Class

The QAbstractSlider class is the base of the widgets that pick an integer value from a range. More…

Header#include <QAbstractSlider>
CMaketarget_link_libraries(app PRIVATE Nt::Widgets)
ModuleNt Widgets C++ Classes
InheritsQWidget
Inherited byQDial, QScrollBar, QSlider

List of all members, including inherited members

Public Types

Public Functions

QAbstractSlider(QWidget *parent = nullptr)
~QAbstractSlider()
Qt::Orientationorientation() const
intminimum() const
voidsetMinimum(int minimum)
intmaximum() const
voidsetMaximum(int maximum)
voidsetRange(int minimum, int maximum)
intsingleStep() const
voidsetSingleStep(int step)
intpageStep() const
voidsetPageStep(int step)
boolhasTracking() const
voidsetTracking(bool enable)
boolisSliderDown() const
voidsetSliderDown(bool down)
intsliderPosition() const
voidsetSliderPosition(int position)
boolinvertedControls() const
voidsetInvertedControls(bool invert)
intvalue() const
voidtriggerAction(SliderAction action)

Public Slots

voidsetValue(int value)
voidsetOrientation(Qt::Orientation orientation)

Signals

voidvalueChanged(int value)
voidsliderPressed()
voidsliderMoved(int value)
voidsliderReleased()
voidrangeChanged(int min, int max)
voidactionTriggered(int action)

Protected Types

Protected Functions

virtual voidsliderChange(SliderChange change)

Reimplemented Protected Functions

voidkeyPressEvent(QKeyEvent *event)
voidwheelEvent(QWheelEvent *event)
voidchangeEvent(QEvent *event)

Detailed Description

QAbstractSlider holds what QSlider, QScrollBar and QDial have in common: a range from minimum() to maximum(), a value(), a sliderPosition() that the user drags, and the steps that the keys and the mouse wheel move by. A subclass draws the slider and turns the mouse into setSliderDown() and setSliderPosition() calls.

While the user drags the slider, sliderPosition() follows the mouse and sliderMoved() is emitted. With tracking on, the default, the value follows the position at once; with it off, the value changes when the slider is released:

QSlider *slider = new QSlider(Qt::Horizontal, window);
slider->setTracking(false);
connect(slider, &QAbstractSlider::valueChanged, [](int value) { apply(value); });

triggerAction() moves the slider the way the keys do, and emits actionTriggered() before the value changes.

See also QSlider, QScrollBar and QDial.

Differences from Qt

There is no invertedAppearance and no setRepeatAction(). The keys and the wheel move by the steps of the slider; the wheel does not take QApplication::wheelScrollLines() into account and moves by three single steps, at most one page, a notch.

Member Type Documentation

enum QAbstractSlider::SliderAction

The ways triggerAction() moves the slider.

ConstantDescription
QAbstractSlider::SliderNoActionNothing.
QAbstractSlider::SliderSingleStepAddUp by singleStep().
QAbstractSlider::SliderSingleStepSubDown by singleStep().
QAbstractSlider::SliderPageStepAddUp by pageStep().
QAbstractSlider::SliderPageStepSubDown by pageStep().
QAbstractSlider::SliderToMinimumTo minimum().
QAbstractSlider::SliderToMaximumTo maximum().
QAbstractSlider::SliderMoveTo sliderPosition(): the value takes the position of the slider.

[protected] enum QAbstractSlider::SliderChange

What changed when sliderChange() is called.

ConstantDescription
QAbstractSlider::SliderRangeChangeThe minimum or the maximum.
QAbstractSlider::SliderOrientationChangeThe orientation.
QAbstractSlider::SliderStepsChangeThe single or the page step.
QAbstractSlider::SliderValueChangeThe value.

Member Function Documentation

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

Constructs a slider with the given parent. The range is 0 to 99, and the slider is horizontal.

[override] QAbstractSlider::~QAbstractSlider()

Destroys the slider.

[signal] void QAbstractSlider::actionTriggered(int action)

This signal is emitted when triggerAction() runs action, a SliderAction. The slider position has already moved; the value has not changed yet.

[override, protected] void QAbstractSlider::changeEvent(QEvent *event)

Reimplements QWidget::changeEvent().

bool QAbstractSlider::hasTracking() const

Returns whether the value follows the slider while it is dragged. The default is true.

See also setTracking().

bool QAbstractSlider::invertedControls() const

Returns whether the keys and the mouse wheel move the slider the other way. The default is false.

See also setInvertedControls().

bool QAbstractSlider::isSliderDown() const

Returns whether the slider is held down, by the user or by setSliderDown().

See also setSliderDown().

[override, protected] void QAbstractSlider::keyPressEvent(QKeyEvent *event)

Reimplements QWidget::keyPressEvent().

The arrow keys move by singleStep(), Page Up and Page Down by pageStep(), and Home and End go to the ends.

int QAbstractSlider::maximum() const

Returns the largest value, 99 by default.

See also setMaximum() and setRange().

int QAbstractSlider::minimum() const

Returns the smallest value, 0 by default.

See also setMinimum() and setRange().

Qt::Orientation QAbstractSlider::orientation() const

Returns the direction the slider moves in, Qt::Horizontal by default.

See also setOrientation().

int QAbstractSlider::pageStep() const

Returns how much Page Up and Page Down change the value by, 10 by default.

See also setPageStep() and singleStep().

[signal] void QAbstractSlider::rangeChanged(int min, int max)

This signal is emitted when the range changes to min and max.

void QAbstractSlider::setInvertedControls(bool invert)

Sets whether the keys and the mouse wheel move the slider the other way to invert.

See also invertedControls().

void QAbstractSlider::setMaximum(int maximum)

Sets the largest value to maximum. The smallest value falls to the same if it was larger.

See also maximum().

void QAbstractSlider::setMinimum(int minimum)

Sets the smallest value to minimum. The largest value grows to the same if it was smaller.

See also minimum().

[slot] void QAbstractSlider::setOrientation(Qt::Orientation orientation)

Sets the direction the slider moves in to orientation. The size policy is transposed with it: a slider expands along its direction.

See also orientation().

void QAbstractSlider::setPageStep(int step)

Sets the step of the page keys to step, at least 1.

See also pageStep().

void QAbstractSlider::setRange(int minimum, int maximum)

Sets the range of the slider to minimum to maximum. If maximum is less than minimum, it is made equal. Emits rangeChanged() if the range changes, and the value is then brought into the range.

See also minimum() and maximum().

void QAbstractSlider::setSingleStep(int step)

Sets the step of the arrow keys to step, at least 1.

See also singleStep().

void QAbstractSlider::setSliderDown(bool down)

Sets whether the slider is held down to down, emitting sliderPressed() or sliderReleased() if that changes. When the slider is let up, the value takes its position. Subclasses call it when the user presses and releases the slider.

See also isSliderDown().

void QAbstractSlider::setSliderPosition(int position)

Moves the slider to position, brought into the range. Emits sliderMoved() if the slider is down, and changes the value too if tracking is on.

See also sliderPosition().

void QAbstractSlider::setTracking(bool enable)

Sets whether the value follows the slider while it is dragged to enable. Without tracking, the value changes when the slider is released.

See also hasTracking().

[slot] void QAbstractSlider::setValue(int value)

Sets the value to value, brought into the range, and moves the slider there. Emits valueChanged() if the value changes.

See also value().

int QAbstractSlider::singleStep() const

Returns how much the arrow keys change the value by, 1 by default.

See also setSingleStep() and pageStep().

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

Is called when the range, the orientation, the steps or the value change; change tells which. The default implementation repaints the slider.

[signal] void QAbstractSlider::sliderMoved(int value)

This signal is emitted when the slider is down and its position changes to value: the user drags it.

int QAbstractSlider::sliderPosition() const

Returns the position of the slider. It differs from value() while the slider is dragged with tracking off.

See also setSliderPosition() and value().

[signal] void QAbstractSlider::sliderPressed()

This signal is emitted when the user presses the slider, and when setSliderDown() sets it down.

[signal] void QAbstractSlider::sliderReleased()

This signal is emitted when the user releases the slider, and when setSliderDown() lets it up.

void QAbstractSlider::triggerAction(SliderAction action)

Moves the slider as action says, emits actionTriggered(), and sets the value to the new position.

See also actionTriggered().

int QAbstractSlider::value() const

Returns the value.

See also setValue() and sliderPosition().

[signal] void QAbstractSlider::valueChanged(int value)

This signal is emitted when the value changes to value, whether the user moved the slider or setValue() did. While the slider is dragged it is emitted at every move if tracking is on, otherwise only when the slider is released.

[override, protected] void QAbstractSlider::wheelEvent(QWheelEvent *event)

Reimplements QWidget::wheelEvent().

Turning the wheel away from the user raises the value by three single steps a notch, at most one page.