6.0.0-rc4Source

QSlider Class

The QSlider class provides a slider that picks a value from a range. More…

Header#include <QSlider>
CMaketarget_link_libraries(app PRIVATE Nt::Widgets)
ModuleNt Widgets C++ Classes
InheritsQAbstractSlider

List of all members, including inherited members

Public Functions

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

Reimplemented Public Functions

Reimplemented Protected Functions

Detailed Description

The user drags the handle, clicks next to it to move by a page, turns the mouse wheel over the slider, or uses the keys when the slider has the focus. Connect to valueChanged():

QSlider *volume = new QSlider(Qt::Horizontal, window);
volume->setRange(0, 100);
connect(volume, &QSlider::valueChanged, [](int value) { qDebug() << value; });

A horizontal slider has its smallest value at the left, a vertical one at the bottom.

Sliders at different values, one with the keyboard focus, one disabled, and a vertical one.

QSlider in the light color scheme

The range, the value and the steps come from QAbstractSlider.

See also QProgressBar and QSpinBox.

Differences from Qt

There are no tick marks (setTickPosition(), setTickInterval()) and no invertedAppearance. A click next to the handle moves by one page and does not repeat while the button is held.

Member Function Documentation

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

Constructs a horizontal slider with the given parent.

[explicit] QSlider::QSlider(Qt::Orientation orientation, QWidget *parent = nullptr)

Constructs a slider with the given orientation and parent.

[override] QSlider::~QSlider()

Destroys the slider.

[override] QSize QSlider::minimumSizeHint() const

Reimplements QAbstractSlider::minimumSizeHint().

[override, protected] void QSlider::mouseMoveEvent(QMouseEvent *event)

Reimplements QAbstractSlider::mouseMoveEvent().

[override, protected] void QSlider::mousePressEvent(QMouseEvent *event)

Reimplements QAbstractSlider::mousePressEvent().

[override, protected] void QSlider::mouseReleaseEvent(QMouseEvent *event)

Reimplements QAbstractSlider::mouseReleaseEvent().

[override, protected] void QSlider::paintEvent(QPaintEvent *event)

Reimplements QAbstractSlider::paintEvent().

[override] QSize QSlider::sizeHint() const

Reimplements QAbstractSlider::sizeHint().