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
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 16 of file qscrollarea.h.
Constructs an empty scroll area with the given parent.
Definition at line 103 of file qscrollarea.cpp.
QScrollArea::~QScrollArea | ( | ) |
Destroys the scroll area and its child widget.
Definition at line 131 of file qscrollarea.cpp.
|
protected |
Definition at line 116 of file qscrollarea.cpp.
Qt::Alignment QScrollArea::alignment | ( | ) | const |
Definition at line 508 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 416 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 446 of file qscrollarea.cpp.
|
overrideprotected |
\reimp
Definition at line 273 of file qscrollarea.cpp.
\reimp
Definition at line 294 of file qscrollarea.cpp.
|
override |
\reimp
Definition at line 400 of file qscrollarea.cpp.
|
overrideprotected |
\reimp
Definition at line 313 of file qscrollarea.cpp.
|
overrideprotected |
\reimp
Definition at line 323 of file qscrollarea.cpp.
void QScrollArea::setAlignment | ( | Qt::Alignment | alignment | ) |
Definition at line 500 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 231 of file qscrollarea.cpp.
void QScrollArea::setWidgetResizable | ( | bool | resizable | ) |
Definition at line 352 of file qscrollarea.cpp.
|
override |
\reimp
Definition at line 363 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 260 of file qscrollarea.cpp.
|
overrideprotected |
\reimp
Definition at line 386 of file qscrollarea.cpp.
QWidget * QScrollArea::widget | ( | ) | const |
Returns the scroll area's widget, or \nullptr if there is none.
Definition at line 202 of file qscrollarea.cpp.
bool QScrollArea::widgetResizable | ( | ) | const |
Definition at line 346 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 20 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 19 of file qscrollarea.h.