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

# QCanvasView Class Reference

The QCanvasView class provides an on-screen view of a QCanvas. More...

    #include <QCanvasView>

This class is part of the Qt 3 compatibility library. It is provided to keep old source code working. We strongly advise against using it in new code.

Inherits QScrollView.

- List of all members, including inherited members

### Writable Properties

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

### Read-Only Properties

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

### Public Functions

- QCanvasView ( QWidget * parent = 0, const char * name = 0, Qt::WFlags f = 0 )
- QCanvasView ( QCanvas * canvas, QWidget * parent = 0, const char * name = 0, Qt::WFlags f = 0 )
- ~QCanvasView ()
- QCanvas * canvas () const
- const QWMatrix & inverseWorldMatrix () const
- void setCanvas ( QCanvas * canvas )
- bool setWorldMatrix ( const QWMatrix & wm )
- virtual QSize sizeHint () const
- const QWMatrix & worldMatrix () const

- 32 public functions inherited from QScrollView
- 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

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

### Signals

- 5 signals inherited from QScrollView
- 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 drawContents ( QPainter * p, int cx, int cy, int cw, int ch )

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

## Detailed Description

The QCanvasView class provides an on-screen view of a QCanvas.

If you want users to be able to interact with a canvas view, you will need to subclass QCanvasView. You might then reimplement some of the event handlers, for example, QScrollView::contentsMousePressEvent():

        void MyCanvasView::contentsMousePressEvent(QMouseEvent* evt)
        {
            QCanvasItemList lst = canvas()->collisions(evt->pos());
            QCanvasItemList::ConstIterator i = lst.constBegin();
            for (; i != lst.constEnd(); ++i) {
                if ((*i)->rtti() == QCanvasRectangle::RTTI)
                    qDebug("A QCanvasRectangle lies somewhere at this point");
            }
        }

The canvas view shows canvas canvas(); this can be changed using setCanvas().

A transformation matrix can be used to transform the view of the canvas in various ways, for example, zooming in or out or rotating. For example:

        QWMatrix wm;
        wm.scale(2, 2);   // Zooms in by 2 times
        wm.rotate(90);    // Rotates 90 degrees counter clockwise
                          // around the origin.
        wm.translate(0, -canvas->height());
                          // moves the canvas down so what was visible
                          // before is still visible.
        myCanvasView->setWorldMatrix(wm);

Use setWorldMatrix() to set the canvas view's world matrix: you must ensure that the world matrix is invertible. The current world matrix is retrievable with worldMatrix(), and its inversion is retrievable with inverseWorldMatrix().

Example:

The following code finds the part of the canvas that is visible in this view, i.e. the bounding rectangle of the view in canvas coordinates.

        QRect rc = QRect(myCanvasView->contentsX(), myCanvasView->contentsY(),
                         myCanvasView->visibleWidth(), myCanvasView->visibleHeight());
        QRect canvasRect = myCanvasView->inverseWorldMatrix().mapRect(rc);

See also QWMatrix and QPainter::setWorldMatrix().

## Member Function Documentation

### QCanvasView::QCanvasView ( QWidget * parent = 0, const char * name = 0, Qt::WFlags f = 0 )

Constructs a QCanvasView with parent parent, and name name, using the widget flags f. The canvas view is not associated with a canvas, so you must to call setCanvas() to view a canvas.

### QCanvasView::QCanvasView ( QCanvas * canvas, QWidget * parent = 0, const char * name = 0, Qt::WFlags f = 0 )

Constructs a QCanvasView which views canvas canvas, with parent parent, and name name, using the widget flags f.

### QCanvasView::~QCanvasView ()

Destroys the canvas view. The associated canvas is not deleted.

### QCanvas * QCanvasView::canvas () const

Returns a pointer to the canvas which the QCanvasView is currently showing.

### void QCanvasView::drawContents ( QPainter * p, int cx, int cy, int cw, int ch ) `[virtual protected]`

Repaints part of the QCanvas that the canvas view is showing starting at cx by cy, with a width of cw and a height of ch using the painter p.

Reimplemented from QScrollView.

### const QWMatrix & QCanvasView::inverseWorldMatrix () const

Returns a reference to the inverse of the canvas view's current transformation matrix.

See also setWorldMatrix() and worldMatrix().

### void QCanvasView::setCanvas ( QCanvas * canvas )

Sets the canvas that the QCanvasView is showing to the canvas canvas.

### bool QCanvasView::setWorldMatrix ( const QWMatrix & wm )

Sets the transformation matrix of the QCanvasView to wm. The matrix must be invertible (i.e. if you create a world matrix that zooms out by 2 times, then the inverse of this matrix is one that will zoom in by 2 times).

Using this function will considerably reduce the speed of the canvas view.

Returns false if wm is not invertable; otherwise returns true.

See also worldMatrix(), inverseWorldMatrix(), and QWMatrix::isInvertible().

### QSize QCanvasView::sizeHint () const `[virtual]`

Suggests a size sufficient to view the entire canvas.

Reimplemented from QWidget.

### const QWMatrix & QCanvasView::worldMatrix () const

Returns a reference to the canvas view's current transformation matrix.

See also setWorldMatrix() and inverseWorldMatrix().