<?xml version="1.0" encoding="iso-8859-1"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd"> <html><head><title>QScrollArea Class Reference</title><style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm } a:link { color: #004faf; text-decoration: none } a:visited { color: #672967; text-decoration: none } td.postheader { font-family: sans-serif } tr.address { font-family: sans-serif } body { background: #ffffff; color: black; } </style></head><body><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr /><td align="left" valign="top" width="32"><img align="left" border="0" height="32" src="images/rb-logo.png" width="32" /></td><td width="1">  </td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a> · <a href="classes.html"><font color="#004faf">All Classes</font></a> · <a href="modules.html"><font color="#004faf">Modules</font></a></td></table><h1 align="center">QScrollArea Class Reference<br /><sup><sup>[<a href="qtgui.html">QtGui</a> module]</sup></sup></h1><p>The QScrollArea class provides a scrolling view onto another widget. <a href="#details">More...</a></p> <p>Inherits <a href="qabstractscrollarea.html">QAbstractScrollArea</a>.</p><h3>Methods</h3><ul><li><div class="fn" /><b><a href="qscrollarea.html#QScrollArea">__init__</a></b> (<i>self</i>, QWidget <i>parent</i> = None)</li><li><div class="fn" />Qt.Alignment <b><a href="qscrollarea.html#alignment">alignment</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qscrollarea.html#ensureVisible">ensureVisible</a></b> (<i>self</i>, int <i>x</i>, int <i>y</i>, int <i>xMargin</i> = 50, int <i>yMargin</i> = 50)</li><li><div class="fn" /><b><a href="qscrollarea.html#ensureWidgetVisible">ensureWidgetVisible</a></b> (<i>self</i>, QWidget <i>childWidget</i>, int <i>xMargin</i> = 50, int <i>yMargin</i> = 50)</li><li><div class="fn" />bool <b><a href="qscrollarea.html#event">event</a></b> (<i>self</i>, QEvent)</li><li><div class="fn" />bool <b><a href="qscrollarea.html#eventFilter">eventFilter</a></b> (<i>self</i>, QObject, QEvent)</li><li><div class="fn" />bool <b><a href="qscrollarea.html#focusNextPrevChild">focusNextPrevChild</a></b> (<i>self</i>, bool <i>next</i>)</li><li><div class="fn" /><b><a href="qscrollarea.html#resizeEvent">resizeEvent</a></b> (<i>self</i>, QResizeEvent)</li><li><div class="fn" /><b><a href="qscrollarea.html#scrollContentsBy">scrollContentsBy</a></b> (<i>self</i>, int <i>dx</i>, int <i>dy</i>)</li><li><div class="fn" /><b><a href="qscrollarea.html#setAlignment">setAlignment</a></b> (<i>self</i>, Qt.Alignment)</li><li><div class="fn" /><b><a href="qscrollarea.html#setWidget">setWidget</a></b> (<i>self</i>, QWidget <i>w</i>)</li><li><div class="fn" /><b><a href="qscrollarea.html#setWidgetResizable">setWidgetResizable</a></b> (<i>self</i>, bool <i>resizable</i>)</li><li><div class="fn" />QSize <b><a href="qscrollarea.html#sizeHint">sizeHint</a></b> (<i>self</i>)</li><li><div class="fn" />QWidget <b><a href="qscrollarea.html#takeWidget">takeWidget</a></b> (<i>self</i>)</li><li><div class="fn" />QWidget <b><a href="qscrollarea.html#widget">widget</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qscrollarea.html#widgetResizable">widgetResizable</a></b> (<i>self</i>)</li></ul><a name="details" /><hr /><h2>Detailed Description</h2><p>The QScrollArea class provides a scrolling view onto another widget.</p> <p>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 <a href="qscrollarea.html#setWidget">setWidget</a>(). For example:</p> <pre class="cpp"> <span class="type"><a href="qlabel.html">QLabel</a></span> <span class="operator">*</span>imageLabel <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qlabel.html">QLabel</a></span>; <span class="type"><a href="qimage.html">QImage</a></span> image(<span class="string">"happyguy.png"</span>); imageLabel<span class="operator">-</span><span class="operator">></span>setPixmap(<span class="type"><a href="qpixmap.html">QPixmap</a></span><span class="operator">.</span>fromImage(image)); scrollArea <span class="operator">=</span> <span class="keyword">new</span> <span class="type">QScrollArea</span>; scrollArea<span class="operator">-</span><span class="operator">></span><a href="qwidget.html#setBackgroundRole">setBackgroundRole</a>(<span class="type"><a href="qpalette.html">QPalette</a></span><span class="operator">.</span>Dark); scrollArea<span class="operator">-</span><span class="operator">></span><a href="qscrollarea.html#setWidget">setWidget</a>(imageLabel); </pre> <p>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:</p> <table class="generic"> <tr class="odd" valign="top"> <td><img alt="" src="images/qscrollarea-noscrollbars.png" /></td> <td><img alt="" src="images/qscrollarea-onescrollbar.png" /></td> <td><img alt="" src="images/qscrollarea-twoscrollbars.png" /></td> </tr> </table> <p>The scroll bars appearance depends on the currently set <a href="qt.html#ScrollBarPolicy-enum">scroll bar policies</a>. You can control the appearance of the scroll bars using the inherited functionality from <a href="qabstractscrollarea.html">QAbstractScrollArea</a>.</p> <p>For example, you can set the <a href="qabstractscrollarea.html#horizontalScrollBarPolicy-prop">QAbstractScrollArea.horizontalScrollBarPolicy</a> and <a href="qabstractscrollarea.html#verticalScrollBarPolicy-prop">QAbstractScrollArea.verticalScrollBarPolicy</a> properties. Or if you want the scroll bars to adjust dynamically when the contents of the scroll area changes, you can use the <a href="qabstractscrollarea.html#horizontalScrollBar">horizontalScrollBar()</a> and <a href="qabstractscrollarea.html#verticalScrollBar">verticalScrollBar()</a> functions (which enable you to access the scroll bars) and set the scroll bars' values whenever the scroll area's contents change, using the <a href="qabstractslider.html#value-prop">QScrollBar.setValue</a>() function.</p> <p>You can retrieve the child widget using the <a href="qscrollarea.html#widget">widget</a>() function. The view can be made to be resizable with the <a href="qscrollarea.html#widgetResizable-prop">setWidgetResizable</a>() function. The alignment of the widget can be specified with <a href="qscrollarea.html#alignment-prop">setAlignment</a>().</p> <p>Two convenience functions <a href="qscrollarea.html#ensureVisible">ensureVisible</a>() and <a href="qscrollarea.html#ensureWidgetVisible">ensureWidgetVisible</a>() ensure a certain region of the contents is visible inside the viewport, by scrolling the contents if necessary.</p> <a id="size-hints-and-layouts" name="size-hints-and-layouts" /> <h3>Size Hints and Layouts</h3> <p>When using a scroll area to display the contents of a custom widget, it is important to ensure that the <a href="qwidget.html#sizeHint-prop">size hint</a> of the child widget is set to a suitable value. If a standard <a href="qwidget.html">QWidget</a> is used for the child widget, it may be necessary to call <a href="qwidget.html#minimumSize-prop">QWidget.setMinimumSize</a>() to ensure that the contents of the widget are shown correctly within the scroll area.</p> <p>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 <a href="qlayout.html#sizeConstraint-prop">size constraint</a> property to one which provides constraints on the minimum and/or maximum size of the layout (e.g., <a href="qlayout.html#SizeConstraint-enum">QLayout.SetMinAndMaxSize</a>) will cause the size of the scroll area to be updated whenever the contents of the layout changes.</p> <p>For a complete example using the QScrollArea class, see the <a href="widgets-imageviewer.html">Image Viewer</a> example. The example shows how to combine <a href="qlabel.html">QLabel</a> and QScrollArea to display an image.</p> <hr /><h2>Method Documentation</h2><h3 class="fn"><a name="QScrollArea" />QScrollArea.__init__ (<i>self</i>, <a href="qwidget.html">QWidget</a> <i>parent</i> = None)</h3><p>The <i>parent</i> argument, if not None, causes <i>self</i> to be owned by Qt instead of PyQt.</p><p>Constructs an empty scroll area with the given <i>parent</i>.</p> <p><b>See also</b> <a href="qscrollarea.html#setWidget">setWidget</a>().</p> <h3 class="fn"><a name="alignment" /><a href="qt-alignment.html">Qt.Alignment</a> QScrollArea.alignment (<i>self</i>)</h3><h3 class="fn"><a name="ensureVisible" />QScrollArea.ensureVisible (<i>self</i>, int <i>x</i>, int <i>y</i>, int <i>xMargin</i> = 50, int <i>yMargin</i> = 50)</h3><p>Scrolls the contents of the scroll area so that the point (<i>x</i>, <i>y</i>) is visible inside the region of the viewport with margins specified in pixels by <i>xmargin</i> and <i>ymargin</i>. 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.</p> <h3 class="fn"><a name="ensureWidgetVisible" />QScrollArea.ensureWidgetVisible (<i>self</i>, <a href="qwidget.html">QWidget</a> <i>childWidget</i>, int <i>xMargin</i> = 50, int <i>yMargin</i> = 50)</h3><p>Scrolls the contents of the scroll area so that the <i>childWidget</i> of <a href="qscrollarea.html#widget">QScrollArea.widget</a>() is visible inside the viewport with margins specified in pixels by <i>xmargin</i> and <i>ymargin</i>. 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.</p> <p>This function was introduced in Qt 4.2.</p> <h3 class="fn"><a name="event" />bool QScrollArea.event (<i>self</i>, <a href="qevent.html">QEvent</a>)</h3><p>Reimplemented from <a href="qobject.html#event">QObject.event</a>().</p> <h3 class="fn"><a name="eventFilter" />bool QScrollArea.eventFilter (<i>self</i>, <a href="qobject.html">QObject</a>, <a href="qevent.html">QEvent</a>)</h3><p>Reimplemented from <a href="qobject.html#eventFilter">QObject.eventFilter</a>().</p> <h3 class="fn"><a name="focusNextPrevChild" />bool QScrollArea.focusNextPrevChild (<i>self</i>, bool <i>next</i>)</h3><p>Reimplemented from <a href="qwidget.html#focusNextPrevChild">QWidget.focusNextPrevChild</a>().</p> <h3 class="fn"><a name="resizeEvent" />QScrollArea.resizeEvent (<i>self</i>, <a href="qresizeevent.html">QResizeEvent</a>)</h3><p>Reimplemented from <a href="qwidget.html#resizeEvent">QWidget.resizeEvent</a>().</p> <h3 class="fn"><a name="scrollContentsBy" />QScrollArea.scrollContentsBy (<i>self</i>, int <i>dx</i>, int <i>dy</i>)</h3><p>Reimplemented from <a href="qabstractscrollarea.html#scrollContentsBy">QAbstractScrollArea.scrollContentsBy</a>().</p> <h3 class="fn"><a name="setAlignment" />QScrollArea.setAlignment (<i>self</i>, <a href="qt-alignment.html">Qt.Alignment</a>)</h3><h3 class="fn"><a name="setWidget" />QScrollArea.setWidget (<i>self</i>, <a href="qwidget.html">QWidget</a> <i>w</i>)</h3><p>The <i>w</i> argument has it's ownership transferred to Qt.</p><p>Sets the scroll area's <i>widget</i>.</p> <p>The <i>widget</i> becomes a child of the scroll area, and will be destroyed when the scroll area is deleted or when a new widget is set.</p> <p>The widget's <a href="qwidget.html#autoFillBackground-prop">autoFillBackground</a> property will be set to <tt>true</tt>.</p> <p>If the scroll area is visible when the <i>widget</i> is added, you must <a href="qwidget.html#show">show()</a> it explicitly.</p> <p>Note that You must add the layout of <i>widget</i> before you call this function; if you add it later, the <i>widget</i> will not be visible - regardless of when you <a href="qwidget.html#show">show()</a> the scroll area. In this case, you can also not <a href="qwidget.html#show">show()</a> the <i>widget</i> later.</p> <p><b>See also</b> <a href="qscrollarea.html#widget">widget</a>().</p> <h3 class="fn"><a name="setWidgetResizable" />QScrollArea.setWidgetResizable (<i>self</i>, bool <i>resizable</i>)</h3><h3 class="fn"><a name="sizeHint" /><a href="qsize.html">QSize</a> QScrollArea.sizeHint (<i>self</i>)</h3><p>Reimplemented from <a href="qwidget.html#sizeHint-prop">QWidget.sizeHint</a>().</p> <h3 class="fn"><a name="takeWidget" /><a href="qwidget.html">QWidget</a> QScrollArea.takeWidget (<i>self</i>)</h3><p>The <i>QWidget</i> result</p><p>Removes the scroll area's widget, and passes ownership of the widget to the caller.</p> <p><b>See also</b> <a href="qscrollarea.html#widget">widget</a>().</p> <h3 class="fn"><a name="widget" /><a href="qwidget.html">QWidget</a> QScrollArea.widget (<i>self</i>)</h3><p>Returns the scroll area's widget, or 0 if there is none.</p> <p><b>See also</b> <a href="qscrollarea.html#setWidget">setWidget</a>().</p> <h3 class="fn"><a name="widgetResizable" />bool QScrollArea.widgetResizable (<i>self</i>)</h3><address><hr /><div align="center"><table border="0" cellspacing="0" width="100%"><tr class="address"><td align="left" width="25%">PyQt 4.10.3 for X11</td><td align="center" width="50%">Copyright © <a href="http://www.riverbankcomputing.com">Riverbank Computing Ltd</a> and <a href="http://www.qtsoftware.com">Nokia</a> 2012</td><td align="right" width="25%">Qt 4.8.5</td></tr></table></div></address></body></html>