返回介绍

QCanvasView Class

发布于 2019-10-04 14:58:43 字数 5559 浏览 1274 评论 0 收藏 0

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

#include <qcanvas.h>

Inherits QScrollView.

List of all member functions.

Public Members

  • QCanvasView ( QWidget*parent = 0, constchar*name = 0, WFlagsf = 0 )
  • QCanvasView ( QCanvas*canvas, QWidget*parent = 0, constchar*name = 0, WFlagsf = 0 )
  • ~QCanvasView ()
  • QCanvas * canvas () const
  • void setCanvas ( QCanvas*canvas )
  • const QWMatrix & worldMatrix () const
  • const QWMatrix & inverseWorldMatrix () const
  • bool setWorldMatrix ( constQWMatrix&wm )

Protected Members

  • virtual void drawContents ( QPainter*p, intcx, intcy, intcw, intch )

Detailed Description

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

A QCanvasView is widget which provides a view of a QCanvas.

If you want users to be able to interact with a canvas view, subclass QCanvasView. You might then reimplement QScrollView::contentsMousePressEvent() for example:

    void MyCanvasView::contentsMousePressEvent( QMouseEvent* e )
    {
        QCanvasItemList l = canvas()->collisions(e->pos());
        for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) {
            if ( (*it)->rtti() == QCanvasRectangle::RTTI )
                qDebug("A QCanvasRectangle lies somewhere at this point");
        }
    }
  

Set the canvas that the view shows with setCanvas() and retrieve the canvas which the view is showing with canvas().

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, QPainter::setWorldMatrix(), Graphics Classes and Image Processing Classes.


Member Function Documentation

QCanvasView::QCanvasView ( QWidget*parent = 0, constchar*name = 0, WFlagsf = 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 will need to call setCanvas() to display a canvas.

QCanvasView::QCanvasView ( QCanvas*canvas, QWidget*parent = 0, constchar*name = 0, WFlagsf = 0 )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

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, intcx, intcy, intcw, intch ) [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.

constQWMatrix& 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 ( constQWMatrix&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).

When you use this, you should note that the performance of the QCanvasView will decrease considerably.

Returns FALSE if wm is not invertable; otherwise returns TRUE.

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

Example: canvas/canvas.cpp.

constQWMatrix& QCanvasView::worldMatrix () const

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

See also setWorldMatrix() and inverseWorldMatrix().

Example: canvas/canvas.cpp.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文