6.0.0-rc4Source

QScrollBar Class

The QScrollBar class provides a bar that scrolls the contents of a widget. More…

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

List of all members, including inherited members

Public Functions

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

Reimplemented Public Functions

Reimplemented Protected Functions

Detailed Description

The length of the handle of a scroll bar says how much of the contents is in view: it is pageStep() out of the range plus pageStep(). The user drags the handle, clicks next to it to move by a page, or turns the mouse wheel over the bar. A QAbstractScrollArea has two scroll bars, and a QScrollBar on its own can be used to scroll anything:

QScrollBar *bar = new QScrollBar(Qt::Horizontal, window);
bar->setRange(0, 200);
bar->setPageStep(50);
connect(bar, &QScrollBar::valueChanged, [](int value) { qDebug() << value; });

A vertical scroll bar has its smallest value at the top, a horizontal one at the left.

Scroll bars with the handle at the start, the middle and the end, a short handle for much to scroll, a disabled one, and a vertical one.

QScrollBar in the light color scheme

See also QSlider and QAbstractScrollArea.

Differences from Qt

There are no arrow buttons at the ends, no context menu and no invertedAppearance. A click next to the handle moves by one page and does not repeat while the button is held. A scroll bar does not take the keyboard focus.

Member Function Documentation

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

Constructs a vertical scroll bar with the given parent.

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

Constructs a scroll bar with the given orientation and parent.

[override] QScrollBar::~QScrollBar()

Destroys the scroll bar.

[override] QSize QScrollBar::minimumSizeHint() const

Reimplements QAbstractSlider::minimumSizeHint().

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

Reimplements QAbstractSlider::mouseMoveEvent().

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

Reimplements QAbstractSlider::mousePressEvent().

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

Reimplements QAbstractSlider::mouseReleaseEvent().

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

Reimplements QAbstractSlider::paintEvent().

[override] QSize QScrollBar::sizeHint() const

Reimplements QAbstractSlider::sizeHint().

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

Reimplements QAbstractSlider::wheelEvent().