~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to doc/html/graphicsview-porting.html

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi
  • Date: 2009-11-02 18:30:08 UTC
  • mfrom: (1.2.2 upstream)
  • mto: (15.2.5 experimental)
  • mto: This revision was merged to the branch mainline in revision 88.
  • Revision ID: james.westby@ubuntu.com-20091102183008-b6a4gcs128mvfb3m
Tags: upstream-4.6.0~beta1
ImportĀ upstreamĀ versionĀ 4.6.0~beta1

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
<!DOCTYPE html
3
3
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
4
4
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
 
<!-- /fasttmp/mkdist-qt-4.5.2-1245473805/qt-x11-opensource-src-4.5.2/doc/src/porting4-canvas.qdoc -->
 
5
<!-- porting4-canvas.qdoc -->
6
6
<head>
7
 
  <title>Qt 4.5: Porting to Graphics View</title>
 
7
  <title>Qt 4.6: Porting to Graphics View</title>
8
8
  <link rel="prev" href="porting4-designer.html" />
9
9
  <link rel="contents" href="porting.html" />
10
10
  <link rel="next" href="qt3to4.html" />
13
13
<body>
14
14
<table border="0" cellpadding="0" cellspacing="0" width="100%">
15
15
<tr>
16
 
<td align="left" valign="top" width="32"><a href="http://qtsoftware.com/products/qt"><img src="images/qt-logo.png" align="left" border="0" /></a></td>
17
 
<td width="1">&nbsp;&nbsp;</td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a>&nbsp;&middot; <a href="namespaces.html"><font color="#004faf">All&nbsp;Namespaces</font></a>&nbsp;&middot; <a href="classes.html"><font color="#004faf">All&nbsp;Classes</font></a>&nbsp;&middot; <a href="mainclasses.html"><font color="#004faf">Main&nbsp;Classes</font></a>&nbsp;&middot; <a href="groups.html"><font color="#004faf">Grouped&nbsp;Classes</font></a>&nbsp;&middot; <a href="modules.html"><font color="#004faf">Modules</font></a>&nbsp;&middot; <a href="functions.html"><font color="#004faf">Functions</font></a></td>
18
 
<td align="right" valign="top" width="230"></td></tr></table><p>
19
 
[Previous: <a href="porting4-designer.html">Porting .ui Files to Qt 4</a>]
 
16
<td align="left" valign="top" width="32"><a href="http://qt.nokia.com/"><img src="images/qt-logo.png" align="left" border="0" /></a></td>
 
17
<td width="1">&nbsp;&nbsp;</td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a>&nbsp;&middot; <a href="classes.html"><font color="#004faf">All&nbsp;Classes</font></a>&nbsp;&middot; <a href="functions.html"><font color="#004faf">All&nbsp;Functions</font></a>&nbsp;&middot; <a href="overviews.html"><font color="#004faf">Overviews</font></a></td><td class="searchBar" align="right" valign="center"><form action="http://www.google.com/cse" id="cse-search-box"><div><input type="hidden" name="cx" value="000136343326384750312:dhbxnqlakyu" /><input type="hidden" name="ie" value="UTF-8" /><input type="text" name="q" size="31" /><input type="submit" name="sa" value="Search" /></div></form></td>
 
18
</tr></table><p>
 
19
[Previous: <a href="porting4-designer.html">Porting UI Files to Qt 4</a>]
20
20
[<a href="porting.html">Contents</a>]
21
21
[Next: <a href="qt3to4.html">qt3to4 - The Qt 3 to 4 Porting Tool</a>]
22
22
</p>
48
48
</ul>
49
49
<li><a href="#other-resources">Other Resources</a></li>
50
50
</ul>
51
 
<p>Qt 4.2 provides two complete examples of <a href="q3canvas.html">Q3Canvas</a> applications ported to Graphics View:</p>
 
51
<p>Qt 4.2 provides two complete examples of <a href="q3canvas.html" class="compat">Q3Canvas</a> applications ported to Graphics View:</p>
52
52
<ul>
53
53
<li><a href="graphicsview-portedcanvas.html">Ported Canvas Example</a>, the canvas example from Qt 3.</li>
54
54
<li><a href="graphicsview-portedasteroids.html">Ported Asteroids Example</a>, the Asteroids game from the Qt 3 demo.</li>
56
56
<a name="introduction"></a>
57
57
<h3>Introduction</h3>
58
58
<p>Conceptually, the Graphics View classes from Qt 4 and the Canvas classes from Qt 3 provide similar functionality using a similar design. Instead of &quot;canvas&quot;, we use the term &quot;scene&quot;. Otherwise, the class names and functions are almost the same as in Qt 3. The easiest classes to port will be <a href="porting4.html#qcanvas">QCanvas</a> and QCanvasView. Experience shows that most time is spent porting the item classes, depending on the complexity of the QCanvasItem classes you have been using before.</p>
59
 
<p>This porting guide will assume you have already ported your application to Qt 4, by making use of <a href="q3canvas.html">Q3Canvas</a>. If you have not done so already, as a first step, run the <a href="qt3to4.html#qt3to4">qt3to4</a> tool on your project. This tool will automate the most tedious part of the porting effort.</p>
 
59
<p>This porting guide will assume you have already ported your application to Qt 4, by making use of <a href="q3canvas.html" class="compat">Q3Canvas</a>. If you have not done so already, as a first step, run the <a href="qt3to4.html#qt3to4">qt3to4</a> tool on your project. This tool will automate the most tedious part of the porting effort.</p>
60
60
<p>Some additional steps are usually required before your application will compile and run. You can read more about the porting process in <a href="porting4.html">Porting to Qt 4</a>.</p>
61
61
<a name="porting-from-q3canvas"></a>
62
62
<h3>Porting from Q3Canvas</h3>
63
 
<p><a href="qgraphicsscene.html">QGraphicsScene</a> is the closest equivalent to <a href="q3canvas.html">Q3Canvas</a>. There are some noticable differences in this new API: Whereas the <a href="q3canvas.html">Q3Canvas</a> classes use integer precision, <a href="qgraphicsscene.html">QGraphicsScene</a> is entirely based on double coordinates, with graphical primitives such as <a href="qpointf.html">QPointF</a> instead of <a href="qpoint.html">QPoint</a>, <a href="qrectf.html">QRectF</a> instead of <a href="qrect.html">QRect</a>, and <a href="qpolygonf.html">QPolygonF</a> and <a href="qpainterpath.html">QPainterPath</a>. The canvas area is defined by a scene rectangle, allowing negative coordinates, as opposed to <a href="q3canvas.html">Q3Canvas</a>, which only defines a size (<a href="qsize.html">QSize</a>), and whose top-left corner is always (0, 0).</p>
 
63
<p><a href="qgraphicsscene.html">QGraphicsScene</a> is the closest equivalent to <a href="q3canvas.html" class="compat">Q3Canvas</a>. There are some noticable differences in this new API: Whereas the <a href="q3canvas.html" class="compat">Q3Canvas</a> classes use integer precision, <a href="qgraphicsscene.html">QGraphicsScene</a> is entirely based on double coordinates, with graphical primitives such as <a href="qpointf.html">QPointF</a> instead of <a href="qpoint.html">QPoint</a>, <a href="qrectf.html">QRectF</a> instead of <a href="qrect.html">QRect</a>, and <a href="qpolygonf.html">QPolygonF</a> and <a href="qpainterpath.html">QPainterPath</a>. The canvas area is defined by a scene rectangle, allowing negative coordinates, as opposed to <a href="q3canvas.html" class="compat">Q3Canvas</a>, which only defines a size (<a href="qsize.html">QSize</a>), and whose top-left corner is always (0, 0).</p>
64
64
<p>In addition, there is no explicit support for canvas tiles anymore; see <a href="#porting-scenes-with-tiles">Porting scenes with tiles</a> for more information. The chunks-based indexing system has been replaced with an implicitly maintained internal BSP tree.</p>
65
65
<a name="porting-table"></a>
66
66
<h4>Porting table</h4>
67
 
<p><table align="center" cellpadding="2" cellspacing="1" border="0">
68
 
<thead><tr valign="top" class="qt-style"><th><a href="q3canvas.html">Q3Canvas</a></th><th><a href="qgraphicsscene.html">QGraphicsScene</a></th></tr></thead>
69
 
<tr valign="top" class="odd"><td><a href="q3canvas.html#Q3Canvas">Q3Canvas::Q3Canvas</a>()</td><td>There is no <a href="qpixmap.html">QPixmap</a> based constructor, and the concept of tiles is gone. You can use <a href="qgraphicsscene.html#backgroundBrush-prop">QGraphicsScene::backgroundBrush</a> to set a brush pattern for the background, or reimplement <a href="qgraphicsscene.html#drawBackground">QGraphicsScene::drawBackground</a>() in a <a href="qgraphicsscene.html">QGraphicsScene</a> subclass (see <a href="#porting-scenes-with-tiles">Porting scenes with tiles</a>). In addition, the <a href="qgraphicsscene.html">QGraphicsScene</a> geometry is provided as a full <a href="qrectf.html">QRectF</a>. Instead of <a href="q3canvas.html">Q3Canvas</a>(int width, int height), you can use <a href="qgraphicsscene.html">QGraphicsScene</a>(int top, int left, int width, int height).</td></tr>
 
67
<p><table class="generic" align="center" cellpadding="2" cellspacing="1" border="0">
 
68
<thead><tr valign="top" class="qt-style"><th><a href="q3canvas.html" class="compat">Q3Canvas</a></th><th><a href="qgraphicsscene.html">QGraphicsScene</a></th></tr></thead>
 
69
<tr valign="top" class="odd"><td><a href="q3canvas.html#Q3Canvas">Q3Canvas::Q3Canvas</a>()</td><td>There is no <a href="qpixmap.html">QPixmap</a> based constructor, and the concept of tiles is gone. You can use <a href="qgraphicsscene.html#backgroundBrush-prop">QGraphicsScene::backgroundBrush</a> to set a brush pattern for the background, or reimplement <a href="qgraphicsscene.html#drawBackground">QGraphicsScene::drawBackground</a>() in a <a href="qgraphicsscene.html">QGraphicsScene</a> subclass (see <a href="#porting-scenes-with-tiles">Porting scenes with tiles</a>). In addition, the <a href="qgraphicsscene.html">QGraphicsScene</a> geometry is provided as a full <a href="qrectf.html">QRectF</a>. Instead of <a href="q3canvas.html" class="compat">Q3Canvas</a>(int width, int height), you can use <a href="qgraphicsscene.html">QGraphicsScene</a>(int top, int left, int width, int height).</td></tr>
70
70
<tr valign="top" class="even"><td><a href="q3canvas.html#allItems">Q3Canvas::allItems</a>()</td><td><a href="qgraphicsscene.html#items">QGraphicsScene::items</a>() returns a list of all items on the scene.</td></tr>
71
71
<tr valign="top" class="odd"><td><a href="q3canvas.html#backgroundColor">Q3Canvas::backgroundColor</a>()</td><td>You can assign a color for the background through the <a href="qgraphicsscene.html#backgroundBrush-prop">QGraphicsScene::backgroundBrush</a> or <a href="qgraphicsview.html#backgroundBrush-prop">QGraphicsView::backgroundBrush</a> properties.</td></tr>
72
72
<tr valign="top" class="even"><td><a href="q3canvas.html#backgroundPixmap">Q3Canvas::backgroundPixmap</a>()</td><td>You can set a tiled pixmap for the background through <a href="qgraphicsscene.html#backgroundBrush-prop">QGraphicsScene::backgroundBrush</a> or <a href="qgraphicsview.html#backgroundBrush-prop">QGraphicsView::backgroundBrush</a>. For more control on the pixmap positioning, you can reimplement <a href="qgraphicsscene.html#drawBackground">QGraphicsScene::drawBackground</a>() or <a href="qgraphicsview.html#drawBackground">QGraphicsView::drawBackground</a>().</td></tr>
73
 
<tr valign="top" class="odd"><td><a href="q3canvas.html#chunkSize">Q3Canvas::chunkSize</a>()</td><td>The closest equivalent to the chunks size in <a href="q3canvas.html">Q3Canvas</a> is the depth of <a href="qgraphicsscene.html">QGraphicsScene</a>'s BSP tree. <a href="qgraphicsscene.html">QGraphicsScene</a> assigns a depth automatically, and the size of each scene segment depends on this depth, and <a href="qgraphicsscene.html#sceneRect-prop">QGraphicsScene::sceneRect</a>(). See <a href="qgraphicsscene.html#itemIndexMethod-prop">QGraphicsScene::itemIndexMethod</a>.</td></tr>
 
73
<tr valign="top" class="odd"><td><a href="q3canvas.html#chunkSize">Q3Canvas::chunkSize</a>()</td><td>The closest equivalent to the chunks size in <a href="q3canvas.html" class="compat">Q3Canvas</a> is the depth of <a href="qgraphicsscene.html">QGraphicsScene</a>'s BSP tree. <a href="qgraphicsscene.html">QGraphicsScene</a> assigns a depth automatically, and the size of each scene segment depends on this depth, and <a href="qgraphicsscene.html#sceneRect-prop">QGraphicsScene::sceneRect</a>(). See <a href="qgraphicsscene.html#itemIndexMethod-prop">QGraphicsScene::itemIndexMethod</a>.</td></tr>
74
74
<tr valign="top" class="even"><td><a href="q3canvas.html#collisions">Q3Canvas::collisions</a>()</td><td><a href="qgraphicsscene.html">QGraphicsScene</a> provides several means to detect item collisions. The <a href="qgraphicsscene.html#items">QGraphicsScene::items</a>() overloads return items that collide with a point, a rectangle, a polygon, or an arbitrary vector path (<a href="qpainterpath.html">QPainterPath</a>). You can also call <a href="qgraphicsscene.html#collidingItems">QGraphicsScene::collidingItems</a>() to determine collision with an item.</td></tr>
75
75
<tr valign="top" class="odd"><td><a href="q3canvas.html#drawArea">Q3Canvas::drawArea</a>()</td><td>The <a href="qgraphicsscene.html#render">QGraphicsScene::render</a>() function provides the original behavior <a href="q3canvas.html#drawArea">Q3Canvas::drawArea</a>(). In addition, you can pass a source rectangle for rendering only parts of the scene, and a destination rectangle for rendering onto designated area of the destination device. <a href="qgraphicsscene.html#render">QGraphicsScene::render</a>() can optionally transform the source rectangle to fit into the destination rectangle. See <a href="graphicsview.html#printing">Printing</a></td></tr>
76
76
<tr valign="top" class="even"><td><a href="q3canvas.html#onCanvas">Q3Canvas::onCanvas</a>()</td><td>The is no equivalent to this function in Graphics View. However, you can combine <a href="qgraphicsscene.html#sceneRect-prop">QGraphicsScene::sceneRect</a>() and <a href="qrectf.html#intersects">QRectF::intersects</a>():<pre> item-&gt;scene().sceneRect().intersects(item-&gt;sceneBoundingRect());</pre>
81
81
<tr valign="top" class="even"><td><a href="q3canvas.html#setAdvancePeriod">Q3Canvas::setAdvancePeriod</a>()</td><td>There is no concept of an advance period in the new API; instead, you can connect <a href="qtimer.html#timeout">QTimer::timeout</a>() to the <a href="qgraphicsscene.html#advance">QGraphicsScene::advance</a>() slot to obtain similar functionality. This will cause all items' <a href="qgraphicsitem.html#advance">QGraphicsItem::advance</a>() function to be called. See also <a href="qgraphicsitemanimation.html">QGraphicsItemAnimation</a>.</td></tr>
82
82
<tr valign="top" class="odd"><td><a href="q3canvas.html#setAllChanged">Q3Canvas::setAllChanged</a>()</td><td>You can call <a href="qgraphicsscene.html#update">QGraphicsScene::update</a>() with no arguments.</td></tr>
83
83
<tr valign="top" class="even"><td><a href="q3canvas.html#setChanged">Q3Canvas::setChanged</a>()</td><td><a href="qgraphicsscene.html#update">QGraphicsScene::update</a>() will trigger a repaint of the whole scene, or parts of the scene.</td></tr>
84
 
<tr valign="top" class="odd"><td><a href="q3canvas.html#setDoubleBuffering">Q3Canvas::setDoubleBuffering</a>()</td><td><a href="q3canvas.html">Q3Canvas</a>' double buffering enabled cacheing of the scene contents in device (i.e&#x2e;, viewport) coordinates. This cache layer has been moved to the view instead; you can cache <a href="qgraphicsscene.html">QGraphicsScene</a>'s background through <a href="qgraphicsview.html#cacheMode-prop">QGraphicsView::setCacheMode</a>(). <a href="qgraphicsview.html#resetCachedContent">QGraphicsView::resetCachedContent</a>() will reset the areas of the cache that has changed.</td></tr>
 
84
<tr valign="top" class="odd"><td><a href="q3canvas.html#setDoubleBuffering">Q3Canvas::setDoubleBuffering</a>()</td><td><a href="q3canvas.html" class="compat">Q3Canvas</a>' double buffering enabled cacheing of the scene contents in device (i.e&#x2e;, viewport) coordinates. This cache layer has been moved to the view instead; you can cache <a href="qgraphicsscene.html">QGraphicsScene</a>'s background through <a href="qgraphicsview.html#cacheMode-prop">QGraphicsView::setCacheMode</a>(). <a href="qgraphicsview.html#resetCachedContent">QGraphicsView::resetCachedContent</a>() will reset the areas of the cache that has changed.</td></tr>
85
85
<tr valign="top" class="even"><td><a href="q3canvas.html#tile">Q3Canvas::tile</a>()</td><td>See <a href="#porting-scenes-with-tiles">Porting scenes with tiles</a>.</td></tr>
86
86
<tr valign="top" class="odd"><td><a href="q3canvas.html#setTiles">Q3Canvas::setTiles</a>()</td><td>See <a href="#porting-scenes-with-tiles">Porting scenes with tiles</a>.</td></tr>
87
87
<tr valign="top" class="even"><td><a href="q3canvas.html#setUnchanged">Q3Canvas::setUnchanged</a>()</td><td>There is no equivalent in Graphics View. This call can usually be removed with no side effects.</td></tr>
95
95
<a name="porting-scenes-with-tiles"></a>
96
96
<h4>Porting scenes with tiles</h4>
97
97
<p><a href="qgraphicsscene.html">QGraphicsScene</a> does not provide an API for tiles. However, you can achieve similar behavior by drawing pixmaps in a reimplementation of <a href="qgraphicsscene.html#drawBackground">QGraphicsScene::drawBackground</a>().</p>
98
 
<p><a href="q3canvas.html">Q3Canvas</a>' tile support is based on providing one pixmap containing tiles of a fixed width and height, and then accessing them (reading and replacing tiles) by index. The tiles in the pixmap are arranged from the left to right, top to bottom.</p>
99
 
<p><table align="center" cellpadding="2" cellspacing="1" border="0">
 
98
<p><a href="q3canvas.html" class="compat">Q3Canvas</a>' tile support is based on providing one pixmap containing tiles of a fixed width and height, and then accessing them (reading and replacing tiles) by index. The tiles in the pixmap are arranged from the left to right, top to bottom.</p>
 
99
<p><table class="generic" align="center" cellpadding="2" cellspacing="1" border="0">
100
100
<tr valign="top" class="odd"><td>0</td><td>1</td><td>2</td><td>3</td></tr>
101
101
<tr valign="top" class="even"><td>4</td><td>5</td><td>6</td><td>7</td></tr>
102
102
</table></p>
119
119
     int tileW, tileH;
120
120
     int hTiles, vTiles;
121
121
 };</pre>
122
 
<p>Depending on how your scene uses tiles, you may be able to simplify this approach. In this example, we will try to mimic the behavior of the <a href="q3canvas.html">Q3Canvas</a> functions.</p>
123
 
<p>We start by creating a subclass of <a href="qgraphicsscene.html">QGraphicsScene</a> (&quot;TileScene&quot;). In this class, we declare two of the tile functions from <a href="q3canvas.html">Q3Canvas</a>, and we then add two helper function that returns the rectangle for a certain tile in our tile pixmap. We will use a two-dimensional vector of ints to keep track of what tiles should be used at what parts of the scene.</p>
 
122
<p>Depending on how your scene uses tiles, you may be able to simplify this approach. In this example, we will try to mimic the behavior of the <a href="q3canvas.html" class="compat">Q3Canvas</a> functions.</p>
 
123
<p>We start by creating a subclass of <a href="qgraphicsscene.html">QGraphicsScene</a> (&quot;TileScene&quot;). In this class, we declare two of the tile functions from <a href="q3canvas.html" class="compat">Q3Canvas</a>, and we then add two helper function that returns the rectangle for a certain tile in our tile pixmap. We will use a two-dimensional vector of ints to keep track of what tiles should be used at what parts of the scene.</p>
124
124
<pre> void TileScene::setTiles(const QPixmap &amp;pixmap, int h, int v,
125
125
                          int tileHeight, int tileWidth)
126
126
 {
168
168
<p>In drawBackground(), we redraw all tiles that have been exposed by intersecting each tile rect with the exposed background area.</p>
169
169
<a name="porting-from-q3canvasview"></a>
170
170
<h3>Porting from Q3CanvasView</h3>
171
 
<p>The closest equivalent to <a href="q3canvasview.html">Q3CanvasView</a> in Graphics View is called <a href="qgraphicsview.html">QGraphicsView</a>. In most cases, this is the easiest class to port. In addition to providing all of <a href="q3canvasview.html">Q3CanvasView</a>'s functionality, <a href="qgraphicsview.html">QGraphicsView</a> includes some useful new features. You can read more about this in <a href="qgraphicsview.html">QGraphicsView</a>'s documentation.</p>
 
171
<p>The closest equivalent to <a href="q3canvasview.html" class="compat">Q3CanvasView</a> in Graphics View is called <a href="qgraphicsview.html">QGraphicsView</a>. In most cases, this is the easiest class to port. In addition to providing all of <a href="q3canvasview.html" class="compat">Q3CanvasView</a>'s functionality, <a href="qgraphicsview.html">QGraphicsView</a> includes some useful new features. You can read more about this in <a href="qgraphicsview.html">QGraphicsView</a>'s documentation.</p>
172
172
<a name="porting-table"></a>
173
173
<h4>Porting table</h4>
174
 
<p><table align="center" cellpadding="2" cellspacing="1" border="0">
175
 
<thead><tr valign="top" class="qt-style"><th><a href="q3canvasview.html">Q3CanvasView</a></th><th><a href="qgraphicsview.html">QGraphicsView</a></th></tr></thead>
176
 
<tr valign="top" class="odd"><td><a href="q3canvasview.html#Q3CanvasView">Q3CanvasView::Q3CanvasView</a>()</td><td><a href="qgraphicsview.html">QGraphicsView</a> provides the same constructors as <a href="q3canvasview.html">Q3CanvasView</a>, but without the name and flags arguments. You can set the name by calling <a href="qobject.html#objectName-prop">setObjectName()</a>, and the flags by calling <a href="qwidget.html#windowFlags-prop">setWindowFlags()</a>.</td></tr>
 
174
<p><table class="generic" align="center" cellpadding="2" cellspacing="1" border="0">
 
175
<thead><tr valign="top" class="qt-style"><th><a href="q3canvasview.html" class="compat">Q3CanvasView</a></th><th><a href="qgraphicsview.html">QGraphicsView</a></th></tr></thead>
 
176
<tr valign="top" class="odd"><td><a href="q3canvasview.html#Q3CanvasView">Q3CanvasView::Q3CanvasView</a>()</td><td><a href="qgraphicsview.html">QGraphicsView</a> provides the same constructors as <a href="q3canvasview.html" class="compat">Q3CanvasView</a>, but without the name and flags arguments. You can set the name by calling <a href="qobject.html#objectName-prop">setObjectName()</a>, and the flags by calling <a href="qwidget.html#windowFlags-prop">setWindowFlags()</a>.</td></tr>
177
177
<tr valign="top" class="even"><td><a href="q3canvasview.html#canvas">Q3CanvasView::canvas</a>()</td><td><a href="qgraphicsview.html#scene">QGraphicsView::scene</a>() returns the scene that is currently associated with the view. <a href="qgraphicsscene.html">QGraphicsScene</a> also provides the opposite function, <a href="qgraphicsscene.html#views">QGraphicsScene::views</a>(), which returns a list of views observing the scene.</td></tr>
178
178
<tr valign="top" class="odd"><td><a href="q3canvasview.html#inverseWorldMatrix">Q3CanvasView::inverseWorldMatrix</a>()</td><td>You can call <a href="qgraphicsview.html#matrix">QGraphicsView::matrix</a>() and <a href="qmatrix.html#inverted">QMatrix::inverted</a>(). <a href="qgraphicsview.html#mapToScene">QGraphicsView::mapToScene</a>() and <a href="qgraphicsview.html#mapFromScene">QGraphicsView::mapFromScene</a>() allow transforming of viewport shapes to scene shapes, and vice versa.</td></tr>
179
179
<tr valign="top" class="even"><td><a href="q3canvasview.html#setCanvas">Q3CanvasView::setCanvas</a>()</td><td><a href="qgraphicsview.html#setScene">QGraphicsView::setScene</a>().</td></tr>
187
187
<p>For improved navigation support, you can set a resize or transformation anchor through <a href="qgraphicsview.html#resizeAnchor-prop">QGraphicsView::resizeAnchor</a> and <a href="qgraphicsview.html#transformationAnchor-prop">QGraphicsView::transformationAnchor</a>. This allows you to easily rotate and zoom the view while keeping the center fixed, or zooming towards the position under the mouse cursor. In addition, if you set the <a href="qgraphicsview.html#dragMode-prop">QGraphicsView::dragMode</a> of the view, <a href="qgraphicsview.html">QGraphicsView</a> will provide rubber band selection or click-and-pull navigation using the <a href="qt.html#CursorShape-enum">OpenHandCursor</a> and <a href="qt.html#CursorShape-enum">ClosedHandCursor</a> cursors.</p>
188
188
<a name="porting-from-q3canvasitem"></a>
189
189
<h3>Porting from Q3CanvasItem</h3>
190
 
<p>The closest equivalent to <a href="q3canvasitem.html">Q3CanvasItem</a> in Graphics View is called <a href="qgraphicsitem.html">QGraphicsItem</a>. Deriving from this class is very common, and because of that, porting from <a href="q3canvasitem.html">Q3CanvasItem</a> often involves more work than <a href="q3canvas.html">Q3Canvas</a> and <a href="q3canvasview.html">Q3CanvasView</a>.</p>
191
 
<p><a href="q3canvasitem.html">Q3CanvasItem</a> has become easier to use, easier to subclass, and more powerful with <a href="qgraphicsitem.html">QGraphicsItem</a>. The key difference from <a href="q3canvasitem.html">Q3CanvasItem</a> lies in event propagation and item groups, but you will also find several convenient new features, such as support for tooltips, cursors, item transformation and drag and drop. You can read all about <a href="qgraphicsitem.html">QGraphicsItem</a> in its own class documentation.</p>
192
 
<p>This section starts with a table that shows how to port each function from <a href="q3canvasitem.html">Q3CanvasItem</a> to <a href="qgraphicsitem.html">QGraphicsItem</a>. Immediately after that, each of <a href="q3canvasitem.html">Q3CanvasItem</a>'s standard subclasses have a section of their own.</p>
193
 
<p><table align="center" cellpadding="2" cellspacing="1" border="0">
194
 
<thead><tr valign="top" class="qt-style"><th><a href="q3canvasitem.html">Q3CanvasItem</a></th><th><a href="qgraphicsitem.html">QGraphicsItem</a></th></tr></thead>
 
190
<p>The closest equivalent to <a href="q3canvasitem.html" class="compat">Q3CanvasItem</a> in Graphics View is called <a href="qgraphicsitem.html">QGraphicsItem</a>. Deriving from this class is very common, and because of that, porting from <a href="q3canvasitem.html" class="compat">Q3CanvasItem</a> often involves more work than <a href="q3canvas.html" class="compat">Q3Canvas</a> and <a href="q3canvasview.html" class="compat">Q3CanvasView</a>.</p>
 
191
<p><a href="q3canvasitem.html" class="compat">Q3CanvasItem</a> has become easier to use, easier to subclass, and more powerful with <a href="qgraphicsitem.html">QGraphicsItem</a>. The key difference from <a href="q3canvasitem.html" class="compat">Q3CanvasItem</a> lies in event propagation and item groups, but you will also find several convenient new features, such as support for tooltips, cursors, item transformation and drag and drop. You can read all about <a href="qgraphicsitem.html">QGraphicsItem</a> in its own class documentation.</p>
 
192
<p>This section starts with a table that shows how to port each function from <a href="q3canvasitem.html" class="compat">Q3CanvasItem</a> to <a href="qgraphicsitem.html">QGraphicsItem</a>. Immediately after that, each of <a href="q3canvasitem.html" class="compat">Q3CanvasItem</a>'s standard subclasses have a section of their own.</p>
 
193
<p><table class="generic" align="center" cellpadding="2" cellspacing="1" border="0">
 
194
<thead><tr valign="top" class="qt-style"><th><a href="q3canvasitem.html" class="compat">Q3CanvasItem</a></th><th><a href="qgraphicsitem.html">QGraphicsItem</a></th></tr></thead>
195
195
<tr valign="top" class="odd"><td><a href="q3canvasitem.html#advance">Q3CanvasItem::advance</a>()</td><td><a href="qgraphicsitem.html#advance">QGraphicsItem::advance</a>() is provided for compatibility. <a href="qgraphicsscene.html#advance">QGraphicsScene::advance</a>() calls <a href="qgraphicsitem.html#advance">QGraphicsItem::advance</a>() for all items. See also <a href="qtimeline.html">QTimeLine</a> and <a href="qgraphicsitemanimation.html">QGraphicsItemAnimation</a>.</td></tr>
196
196
<tr valign="top" class="even"><td><a href="q3canvasitem.html#animated">Q3CanvasItem::animated</a>()</td><td>No equivalent; all items are advanced by <a href="qgraphicsscene.html#advance">QGraphicsScene::advance</a>().</td></tr>
197
197
<tr valign="top" class="odd"><td><a href="q3canvasitem.html#boundingRectAdvanced">Q3CanvasItem::boundingRectAdvanced</a>()</td><td>No equivalent. You can translate <a href="qgraphicsitem.html#boundingRect">QGraphicsItem::boundingRect</a>() instead (see <a href="qrectf.html#translate">QRectF::translate</a>()).</td></tr>
199
199
<tr valign="top" class="odd"><td><a href="q3canvasitem.html#collidesWith">Q3CanvasItem::collidesWith</a>()</td><td><a href="qgraphicsitem.html#collidesWithItem">QGraphicsItem::collidesWithItem</a>() and <a href="qgraphicsitem.html#collidesWithPath">QGraphicsItem::collidesWithPath</a>().</td></tr>
200
200
<tr valign="top" class="even"><td><a href="q3canvasitem.html#collisions">Q3CanvasItem::collisions</a>()</td><td><a href="qgraphicsitem.html#collidingItems">QGraphicsItem::collidingItems</a>() returns a list of all items that collide with an item. You can specify whether you want fast, rough estimate collision between bounding rectangles, or the slower, more accurate shapes.</td></tr>
201
201
<tr valign="top" class="odd"><td><a href="q3canvasitem.html#draw">Q3CanvasItem::draw</a>()</td><td><a href="qgraphicsitem.html#paint">QGraphicsItem::paint</a>(). See also <a href="qstyleoptiongraphicsitem.html">QStyleOptionGraphicsItem</a>, <a href="qgraphicsscene.html#drawItems">QGraphicsScene::drawItems</a>() and <a href="qgraphicsview.html#drawItems">QGraphicsView::drawItems</a>().</td></tr>
202
 
<tr valign="top" class="even"><td><a href="q3canvasitem.html#hide">Q3CanvasItem::hide</a>()</td><td><a href="qgraphicsitem.html#hide">QGraphicsItem::hide</a>() or <a href="qgraphicsitem.html#setVisible">QGraphicsItem::setVisible</a>(). <a href="qgraphicsitem.html">QGraphicsItem</a>s are <i>visible</i> by default; <a href="q3canvasitem.html">Q3CanvasItem</a>s, however, are not.</td></tr>
 
202
<tr valign="top" class="even"><td><a href="q3canvasitem.html#hide">Q3CanvasItem::hide</a>()</td><td><a href="qgraphicsitem.html#hide">QGraphicsItem::hide</a>() or <a href="qgraphicsitem.html#setVisible">QGraphicsItem::setVisible</a>(). <a href="qgraphicsitem.html">QGraphicsItem</a>s are <i>visible</i> by default; <a href="q3canvasitem.html" class="compat">Q3CanvasItem</a>s, however, are not.</td></tr>
203
203
<tr valign="top" class="odd"><td><a href="q3canvasitem.html#isActive">Q3CanvasItem::isActive</a>()</td><td>No equivalent. To achieve similar behavior, you can add this property in a custom subclass of <a href="qgraphicsitem.html">QGraphicsItem</a>.</td></tr>
204
 
<tr valign="top" class="even"><td><a href="q3canvasitem.html#isVisible">Q3CanvasItem::isVisible</a>()</td><td><a href="qgraphicsitem.html#isVisible">QGraphicsItem::isVisible</a>(). <a href="qgraphicsitem.html">QGraphicsItem</a>s are <i>visible</i> by default; <a href="q3canvasitem.html">Q3CanvasItem</a>s, however, are not.</td></tr>
 
204
<tr valign="top" class="even"><td><a href="q3canvasitem.html#isVisible">Q3CanvasItem::isVisible</a>()</td><td><a href="qgraphicsitem.html#isVisible">QGraphicsItem::isVisible</a>(). <a href="qgraphicsitem.html">QGraphicsItem</a>s are <i>visible</i> by default; <a href="q3canvasitem.html" class="compat">Q3CanvasItem</a>s, however, are not.</td></tr>
205
205
<tr valign="top" class="odd"><td><a href="q3canvasitem.html#move">Q3CanvasItem::move</a>()</td><td>You can call <a href="qgraphicsitem.html#setPos">QGraphicsItem::setPos</a>() to change the position of the item.</td></tr>
206
206
<tr valign="top" class="even"><td><a href="q3canvasitem.html#rtti">Q3CanvasItem::rtti</a>()</td><td><a href="qgraphicsitem.html#type">QGraphicsItem::type</a>() and <a href="qgraphicsitem.html#qgraphicsitem_cast">qgraphicsitem_cast</a>().</td></tr>
207
207
<tr valign="top" class="odd"><td><a href="q3canvasitem.html#setActive">Q3CanvasItem::setActive</a>()</td><td>No equivalent.</td></tr>
208
208
<tr valign="top" class="even"><td><a href="q3canvasitem.html#setAnimated">Q3CanvasItem::setAnimated</a>()</td><td>No equivalent; all items are by default &quot;animated&quot; (i.e&#x2e;, <a href="qgraphicsscene.html#advance">QGraphicsScene::advance</a>() advances all items on the scene).</td></tr>
209
209
<tr valign="top" class="odd"><td><a href="q3canvasitem.html#setCanvas">Q3CanvasItem::setCanvas</a>()</td><td>You can call <a href="qgraphicsscene.html#addItem">QGraphicsScene::addItem</a>(), or pass a pointer to the canvas to <a href="qgraphicsitem.html">QGraphicsItem</a>'s constructor.</td></tr>
210
210
<tr valign="top" class="even"><td><a href="q3canvasitem.html#setVelocity">Q3CanvasItem::setVelocity</a>()</td><td>No equivalent. You can add x and y velocity as member data of your class, and call QGraphicsItem::moveBy(x, y) from inside <a href="qgraphicsitem.html#advance">QGraphicsItem::advance</a>(). See also <a href="qtimeline.html">QTimeLine</a> and <a href="qgraphicsitemanimation.html">QGraphicsItemAnimation</a>.</td></tr>
211
 
<tr valign="top" class="odd"><td><a href="q3canvasitem.html#setVisible">Q3CanvasItem::setVisible</a>()</td><td><a href="qgraphicsitem.html#setVisible">QGraphicsItem::setVisible</a>(). <a href="qgraphicsitem.html">QGraphicsItem</a>s are <i>visible</i> by default; <a href="q3canvasitem.html">Q3CanvasItem</a>s, however, are not.</td></tr>
 
211
<tr valign="top" class="odd"><td><a href="q3canvasitem.html#setVisible">Q3CanvasItem::setVisible</a>()</td><td><a href="qgraphicsitem.html#setVisible">QGraphicsItem::setVisible</a>(). <a href="qgraphicsitem.html">QGraphicsItem</a>s are <i>visible</i> by default; <a href="q3canvasitem.html" class="compat">Q3CanvasItem</a>s, however, are not.</td></tr>
212
212
<tr valign="top" class="even"><td><a href="q3canvasitem.html#setX">Q3CanvasItem::setX</a>()</td><td><a href="qgraphicsitem.html#setPos">QGraphicsItem::setPos</a>()</td></tr>
213
213
<tr valign="top" class="odd"><td><a href="q3canvasitem.html#setY">Q3CanvasItem::setY</a>()</td><td><a href="qgraphicsitem.html#setPos">QGraphicsItem::setPos</a>()</td></tr>
214
214
<tr valign="top" class="even"><td><a href="q3canvasitem.html#setXVelocity">Q3CanvasItem::setXVelocity</a>()</td><td>No equivalent.</td></tr>
215
215
<tr valign="top" class="odd"><td><a href="q3canvasitem.html#setYVelocity">Q3CanvasItem::setYVelocity</a>()</td><td>No equivalent.</td></tr>
216
216
<tr valign="top" class="even"><td><a href="q3canvasitem.html#setZ">Q3CanvasItem::setZ</a>()</td><td><a href="qgraphicsitem.html#setZValue">QGraphicsItem::setZValue</a>()</td></tr>
217
 
<tr valign="top" class="odd"><td><a href="q3canvasitem.html#show">Q3CanvasItem::show</a>()</td><td><a href="qgraphicsitem.html#show">QGraphicsItem::show</a>() or <a href="qgraphicsitem.html#setVisible">QGraphicsItem::setVisible</a>(). <a href="qgraphicsitem.html">QGraphicsItem</a>s are <i>visible</i> by default; <a href="q3canvasitem.html">Q3CanvasItem</a>s, however, are not.</td></tr>
 
217
<tr valign="top" class="odd"><td><a href="q3canvasitem.html#show">Q3CanvasItem::show</a>()</td><td><a href="qgraphicsitem.html#show">QGraphicsItem::show</a>() or <a href="qgraphicsitem.html#setVisible">QGraphicsItem::setVisible</a>(). <a href="qgraphicsitem.html">QGraphicsItem</a>s are <i>visible</i> by default; <a href="q3canvasitem.html" class="compat">Q3CanvasItem</a>s, however, are not.</td></tr>
218
218
<tr valign="top" class="even"><td><a href="q3canvasitem.html#xVelocity">Q3CanvasItem::xVelocity</a>()</td><td>No equivalent.</td></tr>
219
219
<tr valign="top" class="odd"><td><a href="q3canvasitem.html#yVelocity">Q3CanvasItem::yVelocity</a>()</td><td>No equivalent.</td></tr>
220
220
</table></p>
221
221
<p>Note that some virtual functions that have passed on to <a href="qgraphicsitem.html">QGraphicsItem</a> have lost their virtuality. An example is <a href="q3canvasitem.html#moveBy">Q3CanvasItem::moveBy</a>(), which was often used to track movement of items. In this case, the virtual <a href="qgraphicsitem.html#itemChange">QGraphicsItem::itemChange</a>() has taken over as a substitute.</p>
222
222
<a name="q3canvaspolygonalitem"></a>
223
223
<h4>Q3CanvasPolygonalItem</h4>
224
 
<p>The closest equivalent to <a href="q3canvaspolygonalitem.html">Q3CanvasPolygonalItem</a> in Graphics View is called <a href="qabstractgraphicsshapeitem.html">QAbstractGraphicsShapeItem</a>. Unlike <a href="q3canvaspolygonalitem.html">Q3CanvasPolygonalItem</a>, it does not define area points (<a href="q3canvaspolygonalitem.html#areaPoints">Q3CanvasPolygonalItem::areaPoints</a>()); instead, each item's geometry is stored as a member of the subclasses.</p>
 
224
<p>The closest equivalent to <a href="q3canvaspolygonalitem.html" class="compat">Q3CanvasPolygonalItem</a> in Graphics View is called <a href="qabstractgraphicsshapeitem.html">QAbstractGraphicsShapeItem</a>. Unlike <a href="q3canvaspolygonalitem.html" class="compat">Q3CanvasPolygonalItem</a>, it does not define area points (<a href="q3canvaspolygonalitem.html#areaPoints">Q3CanvasPolygonalItem::areaPoints</a>()); instead, each item's geometry is stored as a member of the subclasses.</p>
225
225
<p>The <a href="q3canvaspolygonalitem.html#drawShape">Q3CanvasPolygonalItem::drawShape</a>() function is no longer available; instead, you can set the brush and pen from inside <a href="qgraphicsitem.html#paint">QGraphicsItem::paint</a>().</p>
226
 
<p><table align="center" cellpadding="2" cellspacing="1" border="0">
227
 
<thead><tr valign="top" class="qt-style"><th><a href="q3canvaspolygonalitem.html">Q3CanvasPolygonalItem</a></th><th><a href="qabstractgraphicsshapeitem.html">QAbstractGraphicsShapeItem</a></th></tr></thead>
 
226
<p><table class="generic" align="center" cellpadding="2" cellspacing="1" border="0">
 
227
<thead><tr valign="top" class="qt-style"><th><a href="q3canvaspolygonalitem.html" class="compat">Q3CanvasPolygonalItem</a></th><th><a href="qabstractgraphicsshapeitem.html">QAbstractGraphicsShapeItem</a></th></tr></thead>
228
228
<tr valign="top" class="odd"><td><a href="q3canvaspolygonalitem.html#areaPoints">Q3CanvasPolygonalItem::areaPoints</a>()</td><td>No equivalent; each item's geometry is stored in the respective subclass.</td></tr>
229
 
<tr valign="top" class="even"><td><a href="q3canvaspolygonalitem.html#areaPointsAdvanced">Q3CanvasPolygonalItem::areaPointsAdvanced</a>()</td><td>No equivalent; you can use <a href="qpolygonf.html#translate">QPolygonF::translate</a>() or QPainterPath::translate() instead.</td></tr>
 
229
<tr valign="top" class="even"><td><a href="q3canvaspolygonalitem.html#areaPointsAdvanced">Q3CanvasPolygonalItem::areaPointsAdvanced</a>()</td><td>No equivalent; you can use <a href="qpolygonf.html#translate">QPolygonF::translate</a>() or <a href="qpainterpath.html#translate">QPainterPath::translate</a>() instead.</td></tr>
230
230
<tr valign="top" class="odd"><td><a href="q3canvaspolygonalitem.html#drawShape">Q3CanvasPolygonalItem::drawShape</a>()</td><td><a href="qgraphicsitem.html#paint">QGraphicsItem::paint</a>(). You can set the pen and brush from inside this function.</td></tr>
231
231
<tr valign="top" class="even"><td><a href="q3canvaspolygonalitem.html#invalidate">Q3CanvasPolygonalItem::invalidate</a>()</td><td>Call <a href="qgraphicsitem.html#prepareGeometryChange">QGraphicsItem::prepareGeometryChange</a>() before changing the item's geometry.</td></tr>
232
232
<tr valign="top" class="odd"><td><a href="q3canvaspolygonalitem.html#isValid">Q3CanvasPolygonalItem::isValid</a>()</td><td>No equivalent; items' geometry is always in a valid state.</td></tr>
234
234
</table></p>
235
235
<a name="q3canvasellipse"></a>
236
236
<h4>Q3CanvasEllipse</h4>
237
 
<p>The closest equivalent to <a href="q3canvasellipse.html">Q3CanvasEllipse</a> in Graphics View is called <a href="qgraphicsellipseitem.html">QGraphicsEllipseItem</a>. The most noticable difference to <a href="qgraphicsellipseitem.html">QGraphicsEllipseItem</a> is that the ellipse is not longer drawn centered around its position; rather, it is drawn using a bounding <a href="qrectf.html">QRectF</a>, just like <a href="qpainter.html#drawEllipse">QPainter::drawEllipse</a>().</p>
 
237
<p>The closest equivalent to <a href="q3canvasellipse.html" class="compat">Q3CanvasEllipse</a> in Graphics View is called <a href="qgraphicsellipseitem.html">QGraphicsEllipseItem</a>. The most noticable difference to <a href="qgraphicsellipseitem.html">QGraphicsEllipseItem</a> is that the ellipse is not longer drawn centered around its position; rather, it is drawn using a bounding <a href="qrectf.html">QRectF</a>, just like <a href="qpainter.html#drawEllipse">QPainter::drawEllipse</a>().</p>
238
238
<p>For compatibility, you may want to shift the ellipse up and to the left to keep the ellipse centered. Example:</p>
239
239
<pre>     // Before
240
240
     Q3CanvasEllipse ellipse(10, 10);
241
241
 
242
242
     // After
243
243
     QGraphicsEllipseItem ellipse(-5, -5, 10, 10);</pre>
244
 
<p>Note: <a href="qgraphicsellipseitem.html">QGraphicsEllipseItem</a> uses <a href="qabstractgraphicsshapeitem.html#pen">QAbstractGraphicsShapeItem::pen</a>() for outlines, whereas <a href="q3canvasellipse.html">Q3CanvasEllipse</a> did not use <a href="q3canvaspolygonalitem.html#pen">Q3CanvasPolygonalItem::pen</a>().</p>
245
 
<p><table align="center" cellpadding="2" cellspacing="1" border="0">
246
 
<thead><tr valign="top" class="qt-style"><th><a href="q3canvasellipse.html">Q3CanvasEllipse</a></th><th><a href="qgraphicsellipseitem.html">QGraphicsEllipseItem</a></th></tr></thead>
 
244
<p>Note: <a href="qgraphicsellipseitem.html">QGraphicsEllipseItem</a> uses <a href="qabstractgraphicsshapeitem.html#pen">QAbstractGraphicsShapeItem::pen</a>() for outlines, whereas <a href="q3canvasellipse.html" class="compat">Q3CanvasEllipse</a> did not use <a href="q3canvaspolygonalitem.html#pen">Q3CanvasPolygonalItem::pen</a>().</p>
 
245
<p><table class="generic" align="center" cellpadding="2" cellspacing="1" border="0">
 
246
<thead><tr valign="top" class="qt-style"><th><a href="q3canvasellipse.html" class="compat">Q3CanvasEllipse</a></th><th><a href="qgraphicsellipseitem.html">QGraphicsEllipseItem</a></th></tr></thead>
247
247
<tr valign="top" class="odd"><td><a href="q3canvasellipse.html#angleLength">Q3CanvasEllipse::angleLength</a>()</td><td><a href="qgraphicsellipseitem.html#spanAngle">QGraphicsEllipseItem::spanAngle</a>()</td></tr>
248
248
<tr valign="top" class="even"><td><a href="q3canvasellipse.html#angleStart">Q3CanvasEllipse::angleStart</a>()</td><td><a href="qgraphicsellipseitem.html#startAngle">QGraphicsEllipseItem::startAngle</a>()</td></tr>
249
249
<tr valign="top" class="odd"><td><a href="q3canvasellipse.html#setAngles">Q3CanvasEllipse::setAngles</a>()</td><td><a href="qgraphicsellipseitem.html#setStartAngle">QGraphicsEllipseItem::setStartAngle</a>() and <a href="qgraphicsellipseitem.html#setSpanAngle">QGraphicsEllipseItem::setSpanAngle</a>()</td></tr>
251
251
</table></p>
252
252
<a name="q3canvasline"></a>
253
253
<h4>Q3CanvasLine</h4>
254
 
<p>The closest equivalent to <a href="q3canvasline.html">Q3CanvasLine</a> in Graphics View is called <a href="qgraphicslineitem.html">QGraphicsLineItem</a>.</p>
255
 
<p><table align="center" cellpadding="2" cellspacing="1" border="0">
256
 
<thead><tr valign="top" class="qt-style"><th><a href="q3canvasline.html">Q3CanvasLine</a></th><th><a href="qgraphicslineitem.html">QGraphicsLineItem</a></th></tr></thead>
 
254
<p>The closest equivalent to <a href="q3canvasline.html" class="compat">Q3CanvasLine</a> in Graphics View is called <a href="qgraphicslineitem.html">QGraphicsLineItem</a>.</p>
 
255
<p><table class="generic" align="center" cellpadding="2" cellspacing="1" border="0">
 
256
<thead><tr valign="top" class="qt-style"><th><a href="q3canvasline.html" class="compat">Q3CanvasLine</a></th><th><a href="qgraphicslineitem.html">QGraphicsLineItem</a></th></tr></thead>
257
257
<tr valign="top" class="odd"><td><a href="q3canvasline.html#endPoint">Q3CanvasLine::endPoint</a>()</td><td><a href="qgraphicslineitem.html#line">QGraphicsLineItem::line</a>() and <a href="qlinef.html#p2">QLineF::p2</a>()</td></tr>
258
258
<tr valign="top" class="even"><td><a href="q3canvasline.html#setPoints">Q3CanvasLine::setPoints</a>()</td><td><a href="qgraphicslineitem.html#setLine">QGraphicsLineItem::setLine</a>()</td></tr>
259
259
<tr valign="top" class="odd"><td><a href="q3canvasline.html#startPoint">Q3CanvasLine::startPoint</a>()</td><td><a href="qgraphicslineitem.html#line">QGraphicsLineItem::line</a>() and <a href="qlinef.html#p1">QLineF::p1</a>()</td></tr>
260
260
</table></p>
261
261
<a name="q3canvaspolygon"></a>
262
262
<h4>Q3CanvasPolygon</h4>
263
 
<p>The closest equivalent to <a href="q3canvaspolygon.html">Q3CanvasPolygon</a> in Graphics View is called <a href="qgraphicspolygonitem.html">QGraphicsPolygonItem</a>.</p>
264
 
<p><table align="center" cellpadding="2" cellspacing="1" border="0">
265
 
<thead><tr valign="top" class="qt-style"><th><a href="q3canvaspolygon.html">Q3CanvasPolygon</a></th><th><a href="qgraphicspolygonitem.html">QGraphicsPolygonItem</a></th></tr></thead>
 
263
<p>The closest equivalent to <a href="q3canvaspolygon.html" class="compat">Q3CanvasPolygon</a> in Graphics View is called <a href="qgraphicspolygonitem.html">QGraphicsPolygonItem</a>.</p>
 
264
<p><table class="generic" align="center" cellpadding="2" cellspacing="1" border="0">
 
265
<thead><tr valign="top" class="qt-style"><th><a href="q3canvaspolygon.html" class="compat">Q3CanvasPolygon</a></th><th><a href="qgraphicspolygonitem.html">QGraphicsPolygonItem</a></th></tr></thead>
266
266
<tr valign="top" class="odd"><td><a href="q3canvaspolygon.html#areaPoints">Q3CanvasPolygon::areaPoints</a>()</td><td><a href="qgraphicspolygonitem.html#polygon">QGraphicsPolygonItem::polygon</a>() and <a href="qgraphicsitem.html#mapToParent">QGraphicsItem::mapToParent</a>()</td></tr>
267
267
<tr valign="top" class="even"><td><a href="q3canvaspolygon.html#points">Q3CanvasPolygon::points</a>()</td><td><a href="qgraphicspolygonitem.html#polygon">QGraphicsPolygonItem::polygon</a>()</td></tr>
268
268
<tr valign="top" class="odd"><td><a href="q3canvaspolygon.html#setPoints">Q3CanvasPolygon::setPoints</a>()</td><td><a href="qgraphicspolygonitem.html#setPolygon">QGraphicsPolygonItem::setPolygon</a>()</td></tr>
269
269
</table></p>
270
270
<a name="q3canvasspline"></a>
271
271
<h4>Q3CanvasSpline</h4>
272
 
<p>The closest equivalent to <a href="q3canvasspline.html">Q3CanvasSpline</a> in Graphics View is called <a href="qgraphicspathitem.html">QGraphicsPathItem</a>. This item can be used to describe any type of path supported by <a href="qpainter.html">QPainter</a>.</p>
273
 
<p><a href="q3canvasspline.html">Q3CanvasSpline</a> takes its control points as a <a href="q3pointarray.html">Q3PointArray</a>, but <a href="qpainterpath.html">QPainterPath</a> operates on a sequence of calls to <a href="qpainterpath.html#moveTo">QPainterPath::moveTo</a>() and <a href="qpainterpath.html#cubicTo">QPainterPath::cubicTo</a>(). Here is how you can convert a bezier curve <a href="q3pointarray.html">Q3PointArray</a> to a <a href="qpainterpath.html">QPainterPath</a>:</p>
 
272
<p>The closest equivalent to <a href="q3canvasspline.html" class="compat">Q3CanvasSpline</a> in Graphics View is called <a href="qgraphicspathitem.html">QGraphicsPathItem</a>. This item can be used to describe any type of path supported by <a href="qpainter.html">QPainter</a>.</p>
 
273
<p><a href="q3canvasspline.html" class="compat">Q3CanvasSpline</a> takes its control points as a <a href="q3pointarray.html" class="compat">Q3PointArray</a>, but <a href="qpainterpath.html">QPainterPath</a> operates on a sequence of calls to <a href="qpainterpath.html#moveTo">QPainterPath::moveTo</a>() and <a href="qpainterpath.html#cubicTo">QPainterPath::cubicTo</a>(). Here is how you can convert a bezier curve <a href="q3pointarray.html" class="compat">Q3PointArray</a> to a <a href="qpainterpath.html">QPainterPath</a>:</p>
274
274
<pre> static QPainterPath fromControlPoints(const Q3PointArray &amp;pa)
275
275
 {
276
276
     QPainterPath path;
279
279
         path.cubicTo(pa[i], pa[(i + 1) % pa.size()], pa[(i + 2) % pa.size()]);
280
280
     return path;
281
281
 }</pre>
282
 
<p>Note: <a href="qgraphicspathitem.html">QGraphicsPathItem</a> uses <a href="qabstractgraphicsshapeitem.html#pen">QAbstractGraphicsShapeItem::pen</a>() for outlines, whereas <a href="q3canvasspline.html">Q3CanvasSpline</a> did not use <a href="q3canvaspolygonalitem.html#pen">Q3CanvasPolygonalItem::pen</a>().</p>
283
 
<p><table align="center" cellpadding="2" cellspacing="1" border="0">
284
 
<thead><tr valign="top" class="qt-style"><th><a href="q3canvasspline.html">Q3CanvasSpline</a></th><th><a href="qgraphicspathitem.html">QGraphicsPathItem</a></th></tr></thead>
 
282
<p>Note: <a href="qgraphicspathitem.html">QGraphicsPathItem</a> uses <a href="qabstractgraphicsshapeitem.html#pen">QAbstractGraphicsShapeItem::pen</a>() for outlines, whereas <a href="q3canvasspline.html" class="compat">Q3CanvasSpline</a> did not use <a href="q3canvaspolygonalitem.html#pen">Q3CanvasPolygonalItem::pen</a>().</p>
 
283
<p><table class="generic" align="center" cellpadding="2" cellspacing="1" border="0">
 
284
<thead><tr valign="top" class="qt-style"><th><a href="q3canvasspline.html" class="compat">Q3CanvasSpline</a></th><th><a href="qgraphicspathitem.html">QGraphicsPathItem</a></th></tr></thead>
285
285
<tr valign="top" class="odd"><td><a href="q3canvasspline.html#closed">Q3CanvasSpline::closed</a>()</td><td>No equivalent. You can call QPainterPath::closeSubPath() to close a subpath explicitly.</td></tr>
286
286
</table></p>
287
287
<a name="q3canvasrectangle"></a>
288
288
<h4>Q3CanvasRectangle</h4>
289
 
<p>The closest equivalent to <a href="q3canvasrectangle.html">Q3CanvasRectangle</a> in Graphics View is called <a href="qgraphicsrectitem.html">QGraphicsRectItem</a>.</p>
290
 
<p><table align="center" cellpadding="2" cellspacing="1" border="0">
291
 
<thead><tr valign="top" class="qt-style"><th><a href="q3canvasrectangle.html">Q3CanvasRectangle</a></th><th><a href="qgraphicsrectitem.html">QGraphicsRectItem</a></th></tr></thead>
 
289
<p>The closest equivalent to <a href="q3canvasrectangle.html" class="compat">Q3CanvasRectangle</a> in Graphics View is called <a href="qgraphicsrectitem.html">QGraphicsRectItem</a>.</p>
 
290
<p><table class="generic" align="center" cellpadding="2" cellspacing="1" border="0">
 
291
<thead><tr valign="top" class="qt-style"><th><a href="q3canvasrectangle.html" class="compat">Q3CanvasRectangle</a></th><th><a href="qgraphicsrectitem.html">QGraphicsRectItem</a></th></tr></thead>
292
292
<tr valign="top" class="odd"><td><a href="q3canvasrectangle.html#height">Q3CanvasRectangle::height</a>()</td><td><a href="qgraphicsrectitem.html#rect">QGraphicsRectItem::rect</a>() and <a href="qrectf.html#height">QRectF::height</a>()</td></tr>
293
293
<tr valign="top" class="even"><td><a href="q3canvasrectangle.html#setSize">Q3CanvasRectangle::setSize</a>()</td><td><a href="qgraphicsrectitem.html#setRect">QGraphicsRectItem::setRect</a>()</td></tr>
294
294
<tr valign="top" class="odd"><td><a href="q3canvasrectangle.html#size">Q3CanvasRectangle::size</a>()</td><td><a href="qgraphicsrectitem.html#rect">QGraphicsRectItem::rect</a>() and <a href="qrectf.html#size">QRectF::size</a>()</td></tr>
297
297
</table></p>
298
298
<a name="q3canvassprite"></a>
299
299
<h4>Q3CanvasSprite</h4>
300
 
<p><a href="q3canvassprite.html">Q3CanvasSprite</a> is the item class that differs the most from its <a href="q3canvas.html">Q3Canvas</a> predecessor. The closest resemblance of <a href="q3canvassprite.html">Q3CanvasSprite</a> in Graphics View is <a href="qgraphicspixmapitem.html">QGraphicsPixmapItem</a>.</p>
301
 
<p><a href="q3canvassprite.html">Q3CanvasSprite</a> supports animated pixmaps; <a href="qgraphicspixmapitem.html">QGraphicsPixmapItem</a>, however, is a simple single-frame pixmap item. If all you need is a pixmap item, porting is straight-forward. If you do need the animation support, extra work is required; there is no direct porting approach.</p>
302
 
<p>For the <a href="graphicsview-portedasteroids.html">Ported Asteroids Example</a>, a subclass of <a href="qgraphicspixmapitem.html">QGraphicsPixmapItem</a> is used to replace <a href="q3canvassprite.html">Q3CanvasSprite</a>, storing a list of pixmaps and a frame counter. The animation is advanced in <a href="qgraphicsitem.html#advance">QGraphicsItem::advance</a>().</p>
 
300
<p><a href="q3canvassprite.html" class="compat">Q3CanvasSprite</a> is the item class that differs the most from its <a href="q3canvas.html" class="compat">Q3Canvas</a> predecessor. The closest resemblance of <a href="q3canvassprite.html" class="compat">Q3CanvasSprite</a> in Graphics View is <a href="qgraphicspixmapitem.html">QGraphicsPixmapItem</a>.</p>
 
301
<p><a href="q3canvassprite.html" class="compat">Q3CanvasSprite</a> supports animated pixmaps; <a href="qgraphicspixmapitem.html">QGraphicsPixmapItem</a>, however, is a simple single-frame pixmap item. If all you need is a pixmap item, porting is straight-forward. If you do need the animation support, extra work is required; there is no direct porting approach.</p>
 
302
<p>For the <a href="graphicsview-portedasteroids.html">Ported Asteroids Example</a>, a subclass of <a href="qgraphicspixmapitem.html">QGraphicsPixmapItem</a> is used to replace <a href="q3canvassprite.html" class="compat">Q3CanvasSprite</a>, storing a list of pixmaps and a frame counter. The animation is advanced in <a href="qgraphicsitem.html#advance">QGraphicsItem::advance</a>().</p>
303
303
<a name="q3canvaspixmap-q3canvaspixmaparray"></a>
304
304
<h5>Q3CanvasPixmap, Q3CanvasPixmapArray</h5>
305
 
<p>These classes have been removed from the API. You can use <a href="qpixmap.html">QPixmap</a> instead of <a href="q3canvaspixmap.html">Q3CanvasPixmap</a>, and <a href="qlist.html">QList</a> instead of <a href="q3canvaspixmaparray.html">Q3CanvasPixmapArray</a>.</p>
306
 
<p><a href="q3canvaspixmaparray.html">Q3CanvasPixmapArray</a> included convenience for loading a sequence of pixmaps or masks using a path with a wildcard (see <a href="q3canvaspixmaparray.html#readPixmaps">Q3CanvasPixmapArray::readPixmaps</a>() and <a href="q3canvaspixmaparray.html#readCollisionMasks">Q3CanvasPixmapArray::readCollisionMasks</a>()). To achieve similar functionality using Graphics View, you can load the images by using <a href="qdir.html">QDir</a>:</p>
 
305
<p>These classes have been removed from the API. You can use <a href="qpixmap.html">QPixmap</a> instead of <a href="q3canvaspixmap.html" class="compat">Q3CanvasPixmap</a>, and <a href="qlist.html">QList</a> instead of <a href="q3canvaspixmaparray.html" class="compat">Q3CanvasPixmapArray</a>.</p>
 
306
<p><a href="q3canvaspixmaparray.html" class="compat">Q3CanvasPixmapArray</a> included convenience for loading a sequence of pixmaps or masks using a path with a wildcard (see <a href="q3canvaspixmaparray.html#readPixmaps">Q3CanvasPixmapArray::readPixmaps</a>() and <a href="q3canvaspixmaparray.html#readCollisionMasks">Q3CanvasPixmapArray::readCollisionMasks</a>()). To achieve similar functionality using Graphics View, you can load the images by using <a href="qdir.html">QDir</a>:</p>
307
307
<pre> wildcardPath.replace(&quot;%1&quot;, &quot;*&quot;);
308
308
 QFileInfo fi(wildcardPath);
309
309
 
312
312
     frames &lt;&lt; QPixmap(fi.path() + &quot;/&quot; + entry);</pre>
313
313
<a name="q3canvastext"></a>
314
314
<h4>Q3CanvasText</h4>
315
 
<p><a href="q3canvastext.html">Q3CanvasText</a> has been split into two classes in Graphics View: <a href="qgraphicssimpletextitem.html">QGraphicsSimpleTextItem</a> and <a href="qgraphicstextitem.html">QGraphicsTextItem</a>. For porting, <a href="qgraphicssimpletextitem.html">QGraphicsSimpleTextItem</a> should be adequate. <a href="qgraphicstextitem.html">QGraphicsTextItem</a> provides advanced document structuring features similar to that of <a href="qtextedit.html">QTextEdit</a>, and it also allows interaction (e.g&#x2e;, editing and selection).</p>
316
 
<p><table align="center" cellpadding="2" cellspacing="1" border="0">
317
 
<thead><tr valign="top" class="qt-style"><th><a href="q3canvastext.html">Q3CanvasText</a></th><th><a href="qgraphicssimpletextitem.html">QGraphicsSimpleTextItem</a></th></tr></thead>
 
315
<p><a href="q3canvastext.html" class="compat">Q3CanvasText</a> has been split into two classes in Graphics View: <a href="qgraphicssimpletextitem.html">QGraphicsSimpleTextItem</a> and <a href="qgraphicstextitem.html">QGraphicsTextItem</a>. For porting, <a href="qgraphicssimpletextitem.html">QGraphicsSimpleTextItem</a> should be adequate. <a href="qgraphicstextitem.html">QGraphicsTextItem</a> provides advanced document structuring features similar to that of <a href="qtextedit.html">QTextEdit</a>, and it also allows interaction (e.g&#x2e;, editing and selection).</p>
 
316
<p><table class="generic" align="center" cellpadding="2" cellspacing="1" border="0">
 
317
<thead><tr valign="top" class="qt-style"><th><a href="q3canvastext.html" class="compat">Q3CanvasText</a></th><th><a href="qgraphicssimpletextitem.html">QGraphicsSimpleTextItem</a></th></tr></thead>
318
318
<tr valign="top" class="odd"><td><a href="q3canvastext.html#color">Q3CanvasText::color</a>()</td><td><a href="qabstractgraphicsshapeitem.html#pen">QGraphicsSimpleTextItem::pen</a>().</td></tr>
319
319
<tr valign="top" class="even"><td><a href="q3canvastext.html#setColor">Q3CanvasText::setColor</a>()</td><td><a href="qabstractgraphicsshapeitem.html#setPen">QGraphicsSimpleTextItem::setPen</a>().</td></tr>
320
320
<tr valign="top" class="odd"><td><a href="q3canvastext.html#textFlags">Q3CanvasText::textFlags</a>()</td><td>Use <a href="qgraphicstextitem.html">QGraphicsTextItem</a> instead.</td></tr>
324
324
<p>Use <a href="qlist.html">QList</a> instead.</p>
325
325
<a name="other-resources"></a>
326
326
<h3>Other Resources</h3>
327
 
<p>The <a href="http://doc.trolltech.com/qq/qq21-portingcanvas.html">Porting to Qt 4.2's Graphics View</a> article in Qt Quarterly 21 covered the process of porting the Qt 3 canvas example to Qt 4. The result of this is the <a href="graphicsview-portedcanvas.html">Ported Canvas</a> example.</p>
 
327
<p>The <a href="http://qt.nokia.com/qq/qq21-portingcanvas.html">Porting to Qt 4.2's Graphics View</a> article in Qt Quarterly 21 covered the process of porting the Qt 3 canvas example to Qt 4. The result of this is the <a href="graphicsview-portedcanvas.html">Ported Canvas</a> example.</p>
328
328
<p>
329
 
[Previous: <a href="porting4-designer.html">Porting .ui Files to Qt 4</a>]
 
329
[Previous: <a href="porting4-designer.html">Porting UI Files to Qt 4</a>]
330
330
[<a href="porting.html">Contents</a>]
331
331
[Next: <a href="qt3to4.html">qt3to4 - The Qt 3 to 4 Porting Tool</a>]
332
332
</p>
333
333
<p /><address><hr /><div align="center">
334
334
<table width="100%" cellspacing="0" border="0"><tr class="address">
335
 
<td width="30%" align="left">Copyright &copy; 2009 Nokia Corporation and/or its subsidiary(-ies)</td>
336
 
<td width="40%" align="center"><a href="trademarks.html">Trademarks</a></td>
337
 
<td width="30%" align="right"><div align="right">Qt 4.5.2</div></td>
338
 
</tr></table></div></address></body>
 
335
<td width="40%" align="left">Copyright &copy; 2009 Nokia Corporation and/or its subsidiary(-ies)</td>
 
336
<td width="20%" align="center"><a href="trademarks.html">Trademarks</a></td>
 
337
<td width="40%" align="right"><div align="right">Qt 4.6.0</div></td>
 
338
<script type="text/javascript" src="http://www.google.com/jsapi"></script><script type="text/javascript">google.load("elements", "1", {packages: "transliteration"});</script><script type="text/javascript" src="http://www.google.com/coop/cse/t13n?form=cse-search-box&t13n_langs=en"></script><script type="text/javascript" src="http://www.google.com/coop/cse/brand?form=cse-search-box&lang=en"></script></tr></table></div></address></body>
339
339
</html>