![]() |
Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
|
The QScrollArea class provides a scrolling view onto another widget. More...
#include <qscrollarea.h>
Public Member Functions | |
QScrollArea (QWidget *parent=nullptr) | |
Constructs an empty scroll area with the given parent. | |
~QScrollArea () | |
Destroys the scroll area and its child widget. | |
QWidget * | widget () const |
Returns the scroll area's widget, or \nullptr if there is none. | |
void | setWidget (QWidget *widget) |
Sets the scroll area's widget. | |
QWidget * | takeWidget () |
Removes the scroll area's widget, and passes ownership of the widget to the caller. | |
bool | widgetResizable () const |
void | setWidgetResizable (bool resizable) |
QSize | sizeHint () const override |
\reimp | |
bool | focusNextPrevChild (bool next) override |
\reimp | |
Qt::Alignment | alignment () const |
void | setAlignment (Qt::Alignment) |
void | ensureVisible (int x, int y, int xmargin=50, int ymargin=50) |
Scrolls the contents of the scroll area so that the point (x, y) is visible inside the region of the viewport with margins specified in pixels by xmargin and ymargin. | |
void | ensureWidgetVisible (QWidget *childWidget, int xmargin=50, int ymargin=50) |
Protected Member Functions | |
QScrollArea (QScrollAreaPrivate &dd, QWidget *parent=nullptr) | |
bool | event (QEvent *) override |
\reimp | |
bool | eventFilter (QObject *, QEvent *) override |
\reimp | |
void | resizeEvent (QResizeEvent *) override |
\reimp | |
void | scrollContentsBy (int dx, int dy) override |
\reimp | |
QSize | viewportSizeHint () const override |
\reimp |
Properties | |
bool | widgetResizable |
whether the scroll area should resize the view widget | |
Qt::Alignment | alignment |
the alignment of the scroll area's widget |
The QScrollArea class provides a scrolling view onto another widget.
\inmodule QtWidgets
A scroll area is used to display the contents of a child widget within a frame. If the widget exceeds the size of the frame, the view can provide scroll bars so that the entire area of the child widget can be viewed. The child widget must be specified with setWidget(). For example:
The code above creates a scroll area (shown in the images below) containing an image label. When scaling the image, the scroll area can provide the necessary scroll bars:
\table \row
\endtable
The scroll bars appearance depends on the currently set \l {Qt::ScrollBarPolicy}{scroll bar policies}. You can control the appearance of the scroll bars using the inherited functionality from QAbstractScrollArea.
For example, you can set the QAbstractScrollArea::horizontalScrollBarPolicy and QAbstractScrollArea::verticalScrollBarPolicy properties. Or if you want the scroll bars to adjust dynamically when the contents of the scroll area changes, you can use the \l {QAbstractScrollArea::horizontalScrollBar()}{horizontalScrollBar()} and \l {QAbstractScrollArea::verticalScrollBar()}{verticalScrollBar()} functions (which enable you to access the scroll bars) and set the scroll bars' values whenever the scroll area's contents change, using the QScrollBar::setValue() function.
You can retrieve the child widget using the widget() function. The view can be made to be resizable with the setWidgetResizable() function. The alignment of the widget can be specified with setAlignment().
Two convenience functions ensureVisible() and ensureWidgetVisible() ensure a certain region of the contents is visible inside the viewport, by scrolling the contents if necessary.
Definition at line 17 of file qscrollarea.h.
|
explicit |
Constructs an empty scroll area with the given parent.
Definition at line 108 of file qscrollarea.cpp.
QScrollArea::~QScrollArea | ( | ) |
Destroys the scroll area and its child widget.
Definition at line 132 of file qscrollarea.cpp.
|
protected |
Definition at line 116 of file qscrollarea.cpp.
Qt::Alignment QScrollArea::alignment | ( | ) | const |
Definition at line 509 of file qscrollarea.cpp.
void QScrollArea::ensureVisible | ( | int | x, |
int | y, | ||
int | xmargin = 50, | ||
int | ymargin = 50 ) |
Scrolls the contents of the scroll area so that the point (x, y) is visible inside the region of the viewport with margins specified in pixels by xmargin and ymargin.
If the specified point cannot be reached, the contents are scrolled to the nearest valid position. The default value for both margins is 50 pixels.
Definition at line 417 of file qscrollarea.cpp.
Scrolls the contents of the scroll area so that the childWidget of QScrollArea::widget() is visible inside the viewport with margins specified in pixels by xmargin and ymargin. If the specified point cannot be reached, the contents are scrolled to the nearest valid position. The default value for both margins is 50 pixels.
Definition at line 447 of file qscrollarea.cpp.
|
overrideprotected |
\reimp
Definition at line 274 of file qscrollarea.cpp.
\reimp
Definition at line 295 of file qscrollarea.cpp.
|
override |
\reimp
Definition at line 401 of file qscrollarea.cpp.
|
overrideprotected |
\reimp
Definition at line 314 of file qscrollarea.cpp.
|
overrideprotected |
\reimp
Definition at line 324 of file qscrollarea.cpp.
void QScrollArea::setAlignment | ( | Qt::Alignment | alignment | ) |
Definition at line 501 of file qscrollarea.cpp.
Sets the scroll area's widget.
The widget becomes a child of the scroll area, and will be destroyed when the scroll area is deleted or when a new widget is set.
The widget's \l{QWidget::setAutoFillBackground()}{autoFillBackground} property will be set to {true}.
If the scroll area is visible when the widget is added, you must \l{QWidget::}{show()} it explicitly.
Note that You must add the layout of widget before you call this function; if you add it later, the widget will not be visible - regardless of when you \l{QWidget::}{show()} the scroll area. In this case, you can also not \l{QWidget::}{show()} the widget later.
Definition at line 232 of file qscrollarea.cpp.
void QScrollArea::setWidgetResizable | ( | bool | resizable | ) |
Definition at line 353 of file qscrollarea.cpp.
|
override |
\reimp
Definition at line 364 of file qscrollarea.cpp.
QWidget * QScrollArea::takeWidget | ( | ) |
Removes the scroll area's widget, and passes ownership of the widget to the caller.
Definition at line 261 of file qscrollarea.cpp.
|
overrideprotected |
\reimp
Definition at line 387 of file qscrollarea.cpp.
QWidget * QScrollArea::widget | ( | ) | const |
Returns the scroll area's widget, or \nullptr if there is none.
Definition at line 203 of file qscrollarea.cpp.
bool QScrollArea::widgetResizable | ( | ) | const |
Definition at line 347 of file qscrollarea.cpp.
|
readwrite |
the alignment of the scroll area's widget
A valid alignment is a combination of the following flags: \list
Qt::AlignLeft
Qt::AlignHCenter
Qt::AlignRight
Qt::AlignTop
Qt::AlignVCenter
Qt::AlignBottom
\endlist By default, the widget stays rooted to the top-left corner of the scroll area. Definition at line 21 of file qscrollarea.h.
|
readwrite |
whether the scroll area should resize the view widget
If this property is set to false (the default), the scroll area honors the size of its widget. Regardless of this property, you can programmatically resize the widget using widget()->resize(), and the scroll area will automatically adjust itself to the new size.
If this property is set to true, the scroll area will automatically resize the widget in order to avoid scroll bars where they can be avoided, or to take advantage of extra space.
Definition at line 20 of file qscrollarea.h.