6.0.0-rc4Source

QAbstractScrollArea Class

The QAbstractScrollArea class is the base class of widgets that scroll their contents. More…

Header#include <QAbstractScrollArea>
CMaketarget_link_libraries(app PRIVATE Nt::Widgets)
ModuleNt Widgets C++ Classes
InheritsQFrame
Inherited byQAbstractItemView, QMdiArea, QPlainTextEdit, QScrollArea

List of all members, including inherited members

Public Functions

Reimplemented Public Functions

Protected Functions

virtual boolviewportEvent(QEvent *event)
virtual QSizeviewportSizeHint() const
virtual voidscrollContentsBy(int dx, int dy)

Reimplemented Protected Functions

boolevent(QEvent *event)
voidpaintEvent(QPaintEvent *event)
voidwheelEvent(QWheelEvent *event)
voidkeyPressEvent(QKeyEvent *event)

Detailed Description

A scroll area has a frame, a viewport and two scroll bars. The viewport is a child widget that shows part of the contents: a subclass draws in it from paintEvent() by painting on viewport(), and gets the mouse events of the viewport in mousePressEvent() and the other handlers, with positions in the viewport. The scroll bars are shown when they have something to scroll (see Qt::ScrollBarPolicy). A subclass sets their range and page step when the viewport or the contents change, usually in resizeEvent(), which it gets for the viewport:

void Plot::resizeEvent(QResizeEvent *)
{
    horizontalScrollBar()->setRange(0, m_width - viewport()->width());
    horizontalScrollBar()->setPageStep(viewport()->width());
}

void Plot::scrollContentsBy(int dx, int dy)
{
    viewport()->update();
}

See also QScrollArea and QScrollBar.

Member Function Documentation

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

Constructs a scroll area with the given parent. It has a sunken, styled frame and shows its scroll bars as needed.

[override] QAbstractScrollArea::~QAbstractScrollArea()

Destroys the scroll area.

[override, protected] bool QAbstractScrollArea::event(QEvent *event)

Reimplements QFrame::event().

QScrollBar * QAbstractScrollArea::horizontalScrollBar() const

Returns the scroll bar at the bottom of the area.

See also verticalScrollBar() and horizontalScrollBarPolicy().

Qt::ScrollBarPolicy QAbstractScrollArea::horizontalScrollBarPolicy() const

Returns when the horizontal scroll bar is shown, Qt::ScrollBarAsNeeded by default.

See also setHorizontalScrollBarPolicy().

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

Reimplements QFrame::keyPressEvent().

Scrolls with the arrow keys, Page Up, Page Down, Home and End.

[override] QSize QAbstractScrollArea::minimumSizeHint() const

Reimplements QFrame::minimumSizeHint().

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

Reimplements QFrame::paintEvent().

The default draws nothing: a subclass draws the contents on viewport().

[virtual, protected] void QAbstractScrollArea::scrollContentsBy(int dx, int dy)

Called when a scroll bar moves, with the number of pixels that the contents moved by: dx to the right and dy down, so that they are negative when the bar scrolls forward. A subclass moves what it shows. The default repaints the viewport.

void QAbstractScrollArea::setHorizontalScrollBarPolicy(Qt::ScrollBarPolicy policy)

Sets when the horizontal scroll bar is shown to policy.

See also horizontalScrollBarPolicy().

void QAbstractScrollArea::setVerticalScrollBarPolicy(Qt::ScrollBarPolicy policy)

Sets when the vertical scroll bar is shown to policy.

See also verticalScrollBarPolicy().

void QAbstractScrollArea::setViewportMargins(int left, int top, int right, int bottom)

Sets the space inside the frame that the viewport leaves free, to left, top, right and bottom pixels. A subclass puts widgets in it, as a table puts its headers.

See also viewportMargins().

void QAbstractScrollArea::setViewportMargins(const QMargins &margins)

This is an overloaded function.

Sets the space that the viewport leaves free to margins.

[override] QSize QAbstractScrollArea::sizeHint() const

Reimplements QFrame::sizeHint().

QScrollBar * QAbstractScrollArea::verticalScrollBar() const

Returns the scroll bar at the right of the area.

See also horizontalScrollBar() and verticalScrollBarPolicy().

Qt::ScrollBarPolicy QAbstractScrollArea::verticalScrollBarPolicy() const

Returns when the vertical scroll bar is shown, Qt::ScrollBarAsNeeded by default.

See also setVerticalScrollBarPolicy().

QWidget * QAbstractScrollArea::viewport() const

Returns the widget that shows the contents. It is what a subclass paints on.

[virtual, protected] bool QAbstractScrollArea::viewportEvent(QEvent *event)

Handles event of the viewport: a paint, resize, mouse, wheel or tool tip event. The default sends them to the handlers of the area, which is why a subclass receives them as if the area were the viewport. A subclass can override it to see them first. Returns true if the event was handled.

QMargins QAbstractScrollArea::viewportMargins() const

Returns the space between the frame and the viewport that the viewport does not use.

See also setViewportMargins().

[virtual, protected] QSize QAbstractScrollArea::viewportSizeHint() const

Returns the size of the viewport that the area is made for, which sizeHint() adds the frame and the margins to. A subclass returns the size of its contents here; the default is an invalid size, which stands for 256 by 192.

See also sizeHint().

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

Reimplements QFrame::wheelEvent().

Scrolls the vertical scroll bar by the wheel, and the horizontal one by a sideways wheel.