QScrollBar Class
The QScrollBar class provides a bar that scrolls the contents of a widget. More…
| Header | #include <QScrollBar> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::Widgets) |
| Module | Nt Widgets C++ Classes |
| Inherits | QAbstractSlider |
List of all members, including inherited members
Public Functions
| QScrollBar(QWidget *parent = nullptr) | |
| QScrollBar(Qt::Orientation orientation, QWidget *parent = nullptr) | |
| ~QScrollBar() |
Reimplemented Public Functions
| QSize | sizeHint() const |
| QSize | minimumSizeHint() const |
Reimplemented Protected Functions
| void | paintEvent(QPaintEvent *event) |
| void | mousePressEvent(QMouseEvent *event) |
| void | mouseMoveEvent(QMouseEvent *event) |
| void | mouseReleaseEvent(QMouseEvent *event) |
| void | wheelEvent(QWheelEvent *event) |
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.

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
QScrollBar::QScrollBar(QWidget *parent = nullptr)
Constructs a vertical scroll bar with the given parent.
QScrollBar::QScrollBar(Qt::Orientation orientation, QWidget *parent = nullptr)
Constructs a scroll bar with the given orientation and parent.
QScrollBar::~QScrollBar()
Destroys the scroll bar.
QSize QScrollBar::minimumSizeHint() const
Reimplements QAbstractSlider::minimumSizeHint().
void QScrollBar::mouseMoveEvent(QMouseEvent *event)
Reimplements QAbstractSlider::mouseMoveEvent().
void QScrollBar::mousePressEvent(QMouseEvent *event)
Reimplements QAbstractSlider::mousePressEvent().
void QScrollBar::mouseReleaseEvent(QMouseEvent *event)
Reimplements QAbstractSlider::mouseReleaseEvent().
void QScrollBar::paintEvent(QPaintEvent *event)
Reimplements QAbstractSlider::paintEvent().
QSize QScrollBar::sizeHint() const
Reimplements QAbstractSlider::sizeHint().
void QScrollBar::wheelEvent(QWheelEvent *event)
Reimplements QAbstractSlider::wheelEvent().