PySide6.QtWidgets.QScrollArea¶
- class QScrollArea¶
- The - QScrollAreaclass provides a scrolling view onto another widget. More…- Synopsis¶- Properties¶- alignmentᅟ- The alignment of the scroll area’s widget
- widgetResizableᅟ- Whether the scroll area should resize the view widget
 - Methods¶- def - __init__()
- def - alignment()
- def - ensureVisible()
- def - setAlignment()
- def - setWidget()
- def - takeWidget()
- def - widget()
 - Note - This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE - Detailed Description¶- Warning - This section contains snippets that were automatically translated from C++ to Python and may contain errors. - 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:- imageLabel = QLabel() image = QImage("happyguy.png") imageLabel.setPixmap(QPixmap.fromImage(image)) scrollArea = QScrollArea() scrollArea.setBackgroundRole(QPalette.Dark) scrollArea.setWidget(imageLabel) - 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:    - The scroll bars appearance depends on the currently set scroll bar policies. You can control the appearance of the scroll bars using the inherited functionality from - QAbstractScrollArea.- For example, you can set the - horizontalScrollBarPolicyand- verticalScrollBarPolicyproperties. Or if you want the scroll bars to adjust dynamically when the contents of the scroll area changes, you can use the- horizontalScrollBar()and- 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- 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.- Size Hints and Layouts¶- When using a scroll area to display the contents of a custom widget, it is important to ensure that the - size hintof the child widget is set to a suitable value. If a standard- QWidgetis used for the child widget, it may be necessary to call- setMinimumSize()to ensure that the contents of the widget are shown correctly within the scroll area.- If a scroll area is used to display the contents of a widget that contains child widgets arranged in a layout, it is important to realize that the size policy of the layout will also determine the size of the widget. This is especially useful to know if you intend to dynamically change the contents of the layout. In such cases, setting the layout’s - size constraintproperty to one which provides constraints on the minimum and/or maximum size of the layout (e.g.,- SetMinAndMaxSize) will cause the size of the scroll area to be updated whenever the contents of the layout changes.- See also - Note - Properties can be used directly when - from __feature__ import true_propertyis used or via accessor functions otherwise.- property alignmentᅟ: Combination of Qt.AlignmentFlag¶
 - This property holds the alignment of the scroll area’s widget. - A valid alignment is a combination of the following flags: - Qt::AlignLeft
- Qt::AlignHCenter
- Qt::AlignRight
- Qt::AlignTop
- Qt::AlignVCenter
- Qt::AlignBottom
 - By default, the widget stays rooted to the top-left corner of the scroll area. - Access functions:
 - property widgetResizableᅟ: bool¶
 - This property holds 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. - Access functions:
 - Constructs an empty scroll area with the given - parent.- See also - alignment()¶
- Return type:
- Combination of - AlignmentFlag
 - See also 
 - Getter of property - alignmentᅟ.- ensureVisible(x, y[, xmargin=50[, ymargin=50]])¶
- Parameters:
- x – int 
- y – int 
- xmargin – int 
- ymargin – int 
 
 
 - 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- xmarginand- 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.- ensureWidgetVisible(childWidget[, xmargin=50[, ymargin=50]])¶
- Parameters:
- childWidget – - QWidget
- xmargin – int 
- ymargin – int 
 
 
 - Scrolls the contents of the scroll area so that the - childWidgetof- widget()is visible inside the viewport with margins specified in pixels by- xmarginand- 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.- setAlignment(arg__1)¶
- Parameters:
- arg__1 – Combination of - AlignmentFlag
 - See also 
 - Setter of property - alignmentᅟ.- Sets the scroll area’s - widget.- The - widgetbecomes 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 - autoFillBackgroundproperty will be set to- true.- If the scroll area is visible when the - widgetis added, you must- show()it explicitly.- Note that You must add the layout of - widgetbefore you call this function; if you add it later, the- widgetwill not be visible - regardless of when you- show()the scroll area. In this case, you can also not- show()the- widgetlater.- See also - setWidgetResizable(resizable)¶
- Parameters:
- resizable – bool 
 - See also 
 - Setter of property - widgetResizableᅟ.- Removes the scroll area’s widget, and passes ownership of the widget to the caller. - See also - Returns the scroll area’s widget, or - Noneif there is none.- See also - widgetResizable()¶
- Return type:
- bool 
 - See also 
 - Getter of property - widgetResizableᅟ.