QAbstractScrollArea Class
The QAbstractScrollArea class is the base class of widgets that scroll their contents. More…
| Header | #include <QAbstractScrollArea> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::Widgets) |
| Module | Nt Widgets C++ Classes |
| Inherits | QFrame |
| Inherited by | QAbstractItemView, QMdiArea, QPlainTextEdit, QScrollArea |
List of all members, including inherited members
Public Functions
| QAbstractScrollArea(QWidget *parent = nullptr) | |
| ~QAbstractScrollArea() | |
| QWidget * | viewport() const |
| QScrollBar * | horizontalScrollBar() const |
| QScrollBar * | verticalScrollBar() const |
| Qt::ScrollBarPolicy | horizontalScrollBarPolicy() const |
| void | setHorizontalScrollBarPolicy(Qt::ScrollBarPolicy policy) |
| Qt::ScrollBarPolicy | verticalScrollBarPolicy() const |
| void | setVerticalScrollBarPolicy(Qt::ScrollBarPolicy policy) |
| QMargins | viewportMargins() const |
| void | setViewportMargins(int left, int top, int right, int bottom) |
| void | setViewportMargins(const QMargins &margins) |
Reimplemented Public Functions
| QSize | sizeHint() const |
| QSize | minimumSizeHint() const |
Protected Functions
| virtual bool | viewportEvent(QEvent *event) |
| virtual QSize | viewportSizeHint() const |
| virtual void | scrollContentsBy(int dx, int dy) |
Reimplemented Protected Functions
| bool | event(QEvent *event) |
| void | paintEvent(QPaintEvent *event) |
| void | wheelEvent(QWheelEvent *event) |
| void | keyPressEvent(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
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.
QAbstractScrollArea::~QAbstractScrollArea()
Destroys the scroll area.
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().
void QAbstractScrollArea::keyPressEvent(QKeyEvent *event)
Reimplements QFrame::keyPressEvent().
Scrolls with the arrow keys, Page Up, Page Down, Home and End.
QSize QAbstractScrollArea::minimumSizeHint() const
Reimplements QFrame::minimumSizeHint().
void QAbstractScrollArea::paintEvent(QPaintEvent *event)
Reimplements QFrame::paintEvent().
The default draws nothing: a subclass draws the contents on viewport().
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.
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.
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().
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().
void QAbstractScrollArea::wheelEvent(QWheelEvent *event)
Reimplements QFrame::wheelEvent().
Scrolls the vertical scroll bar by the wheel, and the horizontal one by a sideways wheel.