Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions |

# QViewport Class Reference

The QViewport widget provides a scrolling area with on-demand scroll bars. More...

    #include <QViewport>

Inherits QFrame.

Inherited by QAbstractItemView, QTextEdit, and QWidgetView.

- List of all members, including inherited members

### Writable Properties

- horizontalScrollBarPolicy : Qt::ScrollBarPolicy
- verticalScrollBarPolicy : Qt::ScrollBarPolicy

- 5 writable properties inherited from QFrame
- 33 writable properties inherited from QWidget
- 1 writable property inherited from QObject

### Read-Only Properties

- acceptDrops : bool

- 1 read-only property inherited from QFrame
- 24 read-only properties inherited from QWidget

### Public Functions

- QViewport ( QWidget * parent = 0 )
- ~QViewport ()
- QScrollBar * horizontalScrollBar () const
- QSize maximumViewportSize () const
- QScrollBar * verticalScrollBar () const
- QWidget * viewport () const

- 2 public functions inherited from QFrame
- 83 public functions inherited from QWidget
- 24 public functions inherited from QObject
- 2 public functions inherited from QPaintDevice

### Public Slots

- 16 public slots inherited from QWidget
- 1 public slot inherited from QObject

### Signals

- 1 signal inherited from QObject

### Static Public Members

- 4 static public members inherited from QWidget
- 4 static public members inherited from QObject

### Protected Functions

- virtual void contextMenuEvent ( QContextMenuEvent * e )
- virtual void dragEnterEvent ( QDragEnterEvent * event )
- virtual void dragLeaveEvent ( QDragLeaveEvent * event )
- virtual void dragMoveEvent ( QDragMoveEvent * event )
- virtual void dropEvent ( QDropEvent * event )
- virtual bool event ( QEvent * e )
- virtual void keyPressEvent ( QKeyEvent * e )
- virtual void mouseDoubleClickEvent ( QMouseEvent * e )
- virtual void mouseMoveEvent ( QMouseEvent * e )
- virtual void mousePressEvent ( QMouseEvent * e )
- virtual void mouseReleaseEvent ( QMouseEvent * e )
- virtual void paintEvent ( QPaintEvent * event )
- virtual void resizeEvent ( QResizeEvent * event )
- virtual void scrollContentsBy ( int dx, int dy )
- void setViewportMargins ( int left, int top, int right, int bottom )
- virtual bool viewportEvent ( QEvent * e )
- virtual void wheelEvent ( QWheelEvent * e )

- 44 protected functions inherited from QWidget
- 9 protected functions inherited from QObject

## Detailed Description

The QViewport widget provides a scrolling area with on-demand scroll bars.

QViewport is a low-level abstraction of a scrolling area. It gives you full control of the scroll bars, at the cost of simplicity. In most cases, using a QWidgetView is preferable.

QViewport's central child widget is the scrolling area itself, called viewport(). The viewport widget uses all available space. Next to the viewport is a vertical scroll bar (accessible with verticalScrollBar()), and below a horizontal scroll bar (accessible with horizontalScrollBar()). Each scroll bar can be either visible or hidden, depending on the scroll bar's policy (see verticalScrollBarPolicy and horizontalScrollBarPolicy). When a scroll bar is hidden, the viewport expands in order to cover all available space. When a scroll bar becomes visible again, the viewport shrinks in order to make room for the scroll bar.

With a scroll bar policy of Qt::ScrollBarAsNeeded (the default), QViewport shows scroll bars when those provide a non-zero scrolling range, and hides them otherwise. You control the range of each scroll bar with QAbstractSlider::setRange().

In order to track scroll bar movements, reimplement the virtual function scrollContentsBy(). In order to fine-tune scrolling behavior, connect to a scroll bar's QAbstractSlider::actionTriggered() signal and adjust the QAbstractSlider::sliderPosition as you wish.

It is possible to reserve a margin area around the viewport, see setViewportMargins(). The feature is mostly used to place a QHeaderView widget above or beside the scrolling area.

For convience, QViewport makes all viewport events available in the virtual viewportEvent()-handler. QWidget's specialised handlers are remapped to viewport events in the cases where this makes sense. The remapped specialised handlers are: paintEvent(), mousePressEvent(), mouseReleaseEvent(), mouseDoubleClickEvent(), mouseMoveEvent(), wheelEvent(), dragEnterEvent(), dragMoveEvent(), dragLeaveEvent(), dropEvent(), contextMenuEvent(). and resizeEvent().

## Property Documentation

### acceptDrops : bool

This property holds whether the viewport accepts the dropping of dragged objects.

### horizontalScrollBarPolicy : Qt::ScrollBarPolicy

This property holds the policy for the horizontal scroll bar.

The default policy is `Qt::ScrollBarAsNeeded`.

Access functions:

- Qt::ScrollBarPolicy horizontalScrollBarPolicy () const
- void setHorizontalScrollBarPolicy ( Qt::ScrollBarPolicy )

See also verticalScrollBarPolicy.

### verticalScrollBarPolicy : Qt::ScrollBarPolicy

This property holds the policy for the vertical scroll bar.

The default policy is `Qt::ScrollBarAsNeeded`.

Access functions:

- Qt::ScrollBarPolicy verticalScrollBarPolicy () const
- void setVerticalScrollBarPolicy ( Qt::ScrollBarPolicy )

See also horizontalScrollBarPolicy.

## Member Function Documentation

### QViewport::QViewport ( QWidget * parent = 0 )

Constructs a viewport.

The parent arguments is sent to the QWidget constructor.

### QViewport::~QViewport ()

Destroys the viewport.

### void QViewport::contextMenuEvent ( QContextMenuEvent * e ) `[virtual protected]`

This event handler can be reimplemented in a subclass to receive context menu events for the viewport() widget. The event is passed in e.

Reimplemented from QWidget.

See also QWidget::contextMenuEvent().

### void QViewport::dragEnterEvent ( QDragEnterEvent * event ) `[virtual protected]`

This event handler can be reimplemented in a subclass to receive drag enter events (passed in event), for the viewport() widget.

Reimplemented from QWidget.

See also QWidget::dragEnterEvent().

### void QViewport::dragLeaveEvent ( QDragLeaveEvent * event ) `[virtual protected]`

This event handler can be reimplemented in a subclass to receive drag leave events (passed in event), for the viewport() widget.

Reimplemented from QWidget.

See also QWidget::dragLeaveEvent().

### void QViewport::dragMoveEvent ( QDragMoveEvent * event ) `[virtual protected]`

This event handler can be reimplemented in a subclass to receive drag move events (passed in event), for the viewport() widget.

Reimplemented from QWidget.

See also QWidget::dragMoveEvent().

### void QViewport::dropEvent ( QDropEvent * event ) `[virtual protected]`

This event handler can be reimplemented in a subclass to receive drop events (passed in event), for the viewport() widget.

Reimplemented from QWidget.

See also QWidget::dropEvent().

### bool QViewport::event ( QEvent * e ) `[virtual protected]`

This is the main event handler for the QViewport widget (not the scrolling area viewport()). The event is passed in e.

Reimplemented from QObject.

### QScrollBar * QViewport::horizontalScrollBar () const

Returns the horizontal scroll bar.

See also horizontalScrollBarPolicy and verticalScrollBar().

### void QViewport::keyPressEvent ( QKeyEvent * e ) `[virtual protected]`

This function is called with key event e when key presses occur. It handles PageUp, PageDown, Up, Down, Left, and Right, and ignores all other key presses.

Reimplemented from QWidget.

### QSize QViewport::maximumViewportSize () const

... still thinking about the name ###

Returns the size of the viewport as if the scroll bars had no valid scrolling range.

### void QViewport::mouseDoubleClickEvent ( QMouseEvent * e ) `[virtual protected]`

This event handler can be reimplemented in a subclass to receive mouse double click events for the viewport() widget. The event is passed in e.

Reimplemented from QWidget.

See also QWidget::mouseDoubleClickEvent().

### void QViewport::mouseMoveEvent ( QMouseEvent * e ) `[virtual protected]`

This event handler can be reimplemented in a subclass to receive mouse move events for the viewport() widget. The event is passed in e.

Reimplemented from QWidget.

See also QWidget::mouseMoveEvent().

### void QViewport::mousePressEvent ( QMouseEvent * e ) `[virtual protected]`

This event handler can be reimplemented in a subclass to receive mouse press events for the viewport() widget. The event is passed in e.

Reimplemented from QWidget.

See also QWidget::mousePressEvent().

### void QViewport::mouseReleaseEvent ( QMouseEvent * e ) `[virtual protected]`

This event handler can be reimplemented in a subclass to receive mouse release events for the viewport() widget. The event is passed in e.

Reimplemented from QWidget.

See also QWidget::mouseReleaseEvent().

### void QViewport::paintEvent ( QPaintEvent * event ) `[virtual protected]`

This event handler can be reimplemented in a subclass to receive paint events (passed in event), for the viewport() widget.

Note: If you open a painter, make sure to open it on the viewport().

Reimplemented from QWidget.

See also QWidget::paintEvent().

### void QViewport::resizeEvent ( QResizeEvent * event ) `[virtual protected]`

This event handler can be reimplemented in a subclass to receive resize events (passed in event), for the viewport() widget. When resizeEvent() is called, the viewport already has its new geometry. The old size is accessible through QResizeEvent::oldSize().

Reimplemented from QWidget.

See also QWidget::resizeEvent().

### void QViewport::scrollContentsBy ( int dx, int dy ) `[virtual protected]`

Scrolls the viewport's contents by dx, dy.

### void QViewport::setViewportMargins ( int left, int top, int right, int bottom ) `[protected]`

Sets the margins around the scrolling area to left, top, right and bottom. This is useful for applications such as spreadsheets with "locked" rows and columns. The marginal space is is left blank; put widgets in the unused area.

By default all margins are zero.

### QScrollBar * QViewport::verticalScrollBar () const

Returns the vertical scroll bar.

See also verticalScrollBarPolicy and verticalScrollBar().

### QWidget * QViewport::viewport () const

Returns the viewport's viewport

### bool QViewport::viewportEvent ( QEvent * e ) `[virtual protected]`

The main event handler for the scrolling area (the viewport() widget). It handles event e.

You can reimplement this function in a subclass, but we recommend using one of the specialized event handlers instead.

Specialised handlers for viewport events are: paintEvent(), mousePressEvent(), mouseReleaseEvent(), mouseDoubleClickEvent(), mouseMoveEvent(), wheelEvent(), dragEnterEvent(), dragMoveEvent(), dragLeaveEvent(), dropEvent(), contextMenuEvent(), and resizeEvent().

### void QViewport::wheelEvent ( QWheelEvent * e ) `[virtual protected]`

This event handler can be reimplemented in a subclass to receive wheel events for the viewport() widget. The event is passed in e.

Reimplemented from QWidget.

See also QWidget::wheelEvent().