com.trolltech.qt.gui
Class QScrollArea

java.lang.Object
  extended by com.trolltech.qt.internal.QSignalEmitterInternal
      extended by com.trolltech.qt.QSignalEmitter
          extended by com.trolltech.qt.QtJambiObject
              extended by com.trolltech.qt.core.QObject
                  extended by com.trolltech.qt.gui.QWidget
                      extended by com.trolltech.qt.gui.QFrame
                          extended by com.trolltech.qt.gui.QAbstractScrollArea
                              extended by com.trolltech.qt.gui.QScrollArea
All Implemented Interfaces:
QPaintDeviceInterface, QtJambiInterface

public class QScrollArea
extends QAbstractScrollArea

The QScrollArea class provides a scrolling view onto another widget. 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:

        QLabel imageLabel = new QLabel();
        QImage image = new QImage("happyguy.png");
        imageLabel.setPixmap(QPixmap.fromImage(image));

        QScrollArea scrollArea = new QScrollArea();
        scrollArea.setBackgroundRole(QPalette.ColorRole.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 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 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 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.

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 hint of the child widget is set to a suitable value. If a standard QWidget is used for the child widget, it may be necessary to call QWidget::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 realise 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 constraint property to one which provides constraints on the minimum and/or maximum size of the layout (e.g., QLayout::SetMinAndMaxSize ) will cause the size of the the scroll area to be updated whenever the contents of the layout changes.

For a complete example using the QScrollArea class, see the Image Viewer example. The example shows how to combine QLabel and QScrollArea to display an image.

See also:
QAbstractScrollArea, QScrollBar, and Image Viewer Example.


Nested Class Summary
 
Nested classes/interfaces inherited from class com.trolltech.qt.gui.QFrame
QFrame.Shadow, QFrame.Shape, QFrame.StyleMask
 
Nested classes/interfaces inherited from class com.trolltech.qt.gui.QWidget
QWidget.RenderFlag, QWidget.RenderFlags
 
Nested classes/interfaces inherited from class com.trolltech.qt.QSignalEmitter
QSignalEmitter.AbstractSignal, QSignalEmitter.PrivateSignal0, QSignalEmitter.PrivateSignal1, QSignalEmitter.PrivateSignal2, QSignalEmitter.PrivateSignal3, QSignalEmitter.PrivateSignal4, QSignalEmitter.PrivateSignal5, QSignalEmitter.PrivateSignal6, QSignalEmitter.PrivateSignal7, QSignalEmitter.PrivateSignal8, QSignalEmitter.PrivateSignal9, QSignalEmitter.Signal0, QSignalEmitter.Signal1, QSignalEmitter.Signal2, QSignalEmitter.Signal3, QSignalEmitter.Signal4, QSignalEmitter.Signal5, QSignalEmitter.Signal6, QSignalEmitter.Signal7, QSignalEmitter.Signal8, QSignalEmitter.Signal9
 
Nested classes/interfaces inherited from class com.trolltech.qt.internal.QSignalEmitterInternal
com.trolltech.qt.internal.QSignalEmitterInternal.AbstractSignalInternal
 
Field Summary
 
Fields inherited from class com.trolltech.qt.gui.QWidget
customContextMenuRequested
 
Fields inherited from class com.trolltech.qt.internal.QSignalEmitterInternal
currentSender
 
Constructor Summary
QScrollArea()
          Constructs an empty scroll area with the given parent.
QScrollArea(QWidget parent)
          Constructs an empty scroll area with the given parent.
 
Method Summary
 Qt.Alignment alignment()
          This property holds the alignment of the scroll area's widget.
 void ensureVisible(int x, int y)
          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 ensureVisible(int x, int y, int xmargin)
          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 ensureVisible(int x, int y, int xmargin, int ymargin)
          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)
          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.
 void ensureWidgetVisible(QWidget childWidget, int xmargin)
          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.
 void ensureWidgetVisible(QWidget childWidget, int xmargin, int ymargin)
          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.
 void setAlignment(Qt.Alignment arg__1)
          This property holds the alignment of the scroll area's widget.
 void setAlignment(Qt.AlignmentFlag[] arg__1)
          This is an overloaded method provided for convenience.
 void setWidget(QWidget widget)
          Sets the scroll area's widget.
 void setWidgetResizable(boolean resizable)
          This property holds whether the scroll area should resize the view widget.
 QWidget takeWidget()
          Removes the scroll area's widget, and passes ownership of the widget to the caller.
 QWidget widget()
          Returns the scroll area's widget, or 0 if there is none.
 boolean widgetResizable()
          This property holds whether the scroll area should resize the view widget.
 
Methods inherited from class com.trolltech.qt.gui.QAbstractScrollArea
addScrollBarWidget, addScrollBarWidget, cornerWidget, horizontalScrollBar, horizontalScrollBarPolicy, maximumViewportSize, scrollBarWidgets, scrollBarWidgets, scrollContentsBy, setCornerWidget, setHorizontalScrollBar, setHorizontalScrollBarPolicy, setupViewport, setVerticalScrollBar, setVerticalScrollBarPolicy, setViewport, setViewportMargins, verticalScrollBar, verticalScrollBarPolicy, viewport, viewportEvent
 
Methods inherited from class com.trolltech.qt.gui.QFrame
frameRect, frameShadow, frameShape, frameStyle, frameWidth, lineWidth, midLineWidth, setFrameRect, setFrameShadow, setFrameShape, setFrameStyle, setLineWidth, setMidLineWidth
 
Methods inherited from class com.trolltech.qt.gui.QWidget
acceptDrops, accessibleDescription, accessibleName, actionEvent, actions, activateWindow, addAction, addActions, adjustSize, autoFillBackground, backgroundRole, baseSize, changeEvent, childAt, childAt, childrenRect, childrenRegion, clearFocus, clearMask, close, closeEvent, contentsRect, contextMenuEvent, contextMenuPolicy, cursor, depth, destroy, destroy, destroy, dragEnterEvent, dragLeaveEvent, dragMoveEvent, dropEvent, effectiveWinId, ensurePolished, enterEvent, focusInEvent, focusNextChild, focusNextPrevChild, focusOutEvent, focusPolicy, focusPreviousChild, focusProxy, focusWidget, font, fontInfo, fontMetrics, foregroundRole, frameGeometry, frameSize, geometry, getContentsMargins, grabKeyboard, grabMouse, grabMouse, grabShortcut, grabShortcut, graphicsProxyWidget, hasFocus, hasMouseTracking, height, heightForWidth, heightMM, hide, hideEvent, inputContext, inputMethodEvent, inputMethodQuery, insertAction, insertActions, isActiveWindow, isAncestorOf, isEnabled, isEnabledTo, isFullScreen, isHidden, isMaximized, isMinimized, isModal, isVisible, isVisibleTo, isWindow, isWindowModified, keyboardGrabber, keyPressEvent, keyReleaseEvent, languageChange, layout, layoutDirection, leaveEvent, locale, logicalDpiX, logicalDpiY, lower, mapFrom, mapFromGlobal, mapFromParent, mapTo, mapToGlobal, mapToParent, mask, maximumHeight, maximumSize, maximumWidth, metric, minimumHeight, minimumSize, minimumSizeHint, minimumWidth, mouseDoubleClickEvent, mouseGrabber, mouseMoveEvent, mousePressEvent, mouseReleaseEvent, move, move, moveEvent, nativeParentWidget, nextInFocusChain, normalGeometry, numColors, overrideWindowFlags, overrideWindowFlags, overrideWindowState, paintEngine, paintEvent, paintingActive, palette, parentWidget, physicalDpiX, physicalDpiY, pos, raise, rect, releaseKeyboard, releaseMouse, releaseShortcut, removeAction, render, render, render, render, render, render, render, render, render, repaint, repaint, repaint, repaint, resetInputContext, resize, resize, resizeEvent, restoreGeometry, saveGeometry, scroll, scroll, setAcceptDrops, setAccessibleDescription, setAccessibleName, setAttribute, setAttribute, setAutoFillBackground, setBackgroundRole, setBaseSize, setBaseSize, setContentsMargins, setContentsMargins, setContextMenuPolicy, setCursor, setDisabled, setEnabled, setFixedHeight, setFixedSize, setFixedSize, setFixedWidth, setFocus, setFocus, setFocusPolicy, setFocusProxy, setFont, setForegroundRole, setGeometry, setGeometry, setHidden, setInputContext, setLayout, setLayoutDirection, setLocale, setMask, setMask, setMaximumHeight, setMaximumSize, setMaximumSize, setMaximumWidth, setMinimumHeight, setMinimumSize, setMinimumSize, setMinimumWidth, setMouseTracking, setPalette, setParent, setParent, setParent, setShortcutAutoRepeat, setShortcutAutoRepeat, setShortcutEnabled, setShortcutEnabled, setSizeIncrement, setSizeIncrement, setSizePolicy, setSizePolicy, setStatusTip, setStyle, setStyleSheet, setTabOrder, setToolTip, setUpdatesEnabled, setVisible, setWhatsThis, setWindowFilePath, setWindowFlags, setWindowFlags, setWindowIcon, setWindowIconText, setWindowModality, setWindowModified, setWindowOpacity, setWindowRole, setWindowState, setWindowState, setWindowTitle, show, showEvent, showFullScreen, showMaximized, showMinimized, showNormal, size, sizeHint, sizeIncrement, sizePolicy, stackUnder, statusTip, style, styleSheet, tabletEvent, testAttribute, toolTip, underMouse, unsetCursor, unsetLayoutDirection, unsetLocale, update, update, update, update, updateGeometry, updateMicroFocus, updatesEnabled, visibleRegion, whatsThis, wheelEvent, width, widthMM, window, windowFilePath, windowFlags, windowIcon, windowIconText, windowModality, windowOpacity, windowRole, windowState, windowTitle, windowType, winId, x, y
 
Methods inherited from class com.trolltech.qt.core.QObject
childEvent, children, connectSlotsByName, customEvent, disposeLater, dumpObjectInfo, dumpObjectTree, dynamicPropertyNames, event, eventFilter, findChild, findChild, findChild, findChildren, findChildren, findChildren, findChildren, indexOfProperty, installEventFilter, isWidgetType, killTimer, moveToThread, objectName, parent, properties, property, removeEventFilter, setObjectName, setParent, setProperty, startTimer, timerEvent, toString, userProperty
 
Methods inherited from class com.trolltech.qt.QtJambiObject
dispose, disposed, equals, finalize, reassignNativeResources, tr, tr, tr
 
Methods inherited from class com.trolltech.qt.QSignalEmitter
blockSignals, disconnect, disconnect, signalsBlocked, signalSender, thread
 
Methods inherited from class com.trolltech.qt.internal.QSignalEmitterInternal
__qt_signalInitialization
 
Methods inherited from class java.lang.Object
clone, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.trolltech.qt.QtJambiInterface
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership
 

Constructor Detail

QScrollArea

public QScrollArea()
Constructs an empty scroll area with the given parent.

See also:
setWidget().


QScrollArea

public QScrollArea(QWidget parent)
Constructs an empty scroll area with the given parent.

See also:
setWidget().

Method Detail

alignment

public final Qt.Alignment alignment()
This property holds the alignment of the scroll area's widget. By default, the widget stays rooted to the top-left corner of the scroll area.


ensureVisible

public final void ensureVisible(int x,
                                int y,
                                int xmargin)
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.


ensureVisible

public final void ensureVisible(int x,
                                int y)
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.


ensureVisible

public final void ensureVisible(int x,
                                int y,
                                int xmargin,
                                int ymargin)
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.


ensureWidgetVisible

public final void ensureWidgetVisible(QWidget childWidget,
                                      int xmargin)
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.


ensureWidgetVisible

public final void ensureWidgetVisible(QWidget childWidget)
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.


ensureWidgetVisible

public final void ensureWidgetVisible(QWidget childWidget,
                                      int xmargin,
                                      int ymargin)
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.


setAlignment

public final void setAlignment(Qt.AlignmentFlag[] arg__1)
This is an overloaded method provided for convenience.


setAlignment

public final void setAlignment(Qt.Alignment arg__1)
This property holds the alignment of the scroll area's widget. By default, the widget stays rooted to the top-left corner of the scroll area.


setWidget

public final void setWidget(QWidget widget)
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 autoFillBackground property will be set to true.

If the scroll area is visible when the widget is added, you must 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 show() the scroll area. In this case, you can also not show() the widget later.

See also:
widget().


setWidgetResizable

public final void setWidgetResizable(boolean resizable)
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.


takeWidget

public final QWidget takeWidget()
Removes the scroll area's widget, and passes ownership of the widget to the caller.

See also:
widget().


widget

public final QWidget widget()
Returns the scroll area's widget, or 0 if there is none.

See also:
setWidget().


widgetResizable

public final boolean widgetResizable()
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.