qcanvas.html
来自「QT 下载资料仅供参考」· HTML 代码 · 共 569 行 · 第 1/3 页
HTML
569 行
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><!-- /home/reggie/tmp/qt-3.0-reggie-5401/qt-x11-commercial-3.0.5/src/canvas/qcanvas.cpp:414 --><html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>QCanvas Class</title><style type="text/css"><!--h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; }a:link { color: #004faf; text-decoration: none }a:visited { color: #672967; text-decoration: none }body { background: #ffffff; color: black; }--></style></head><body><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr bgcolor="#E5E5E5"><td valign=center> <a href="index.html"><font color="#004faf">Home</font></a> | <a href="classes.html"><font color="#004faf">All Classes</font></a> | <a href="mainclasses.html"><font color="#004faf">Main Classes</font></a> | <a href="annotated.html"><font color="#004faf">Annotated</font></a> | <a href="groups.html"><font color="#004faf">Grouped Classes</font></a> | <a href="functions.html"><font color="#004faf">Functions</font></a></td><td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>QCanvas Class Reference<br><small>[<a href="canvas.html">canvas module</a>]</small></h1><p>The QCanvas class provides a 2D area that can contain QCanvasItem objects.<a href="#details">More...</a><p><tt>#include <<a href="qcanvas-h.html">qcanvas.h</a>></tt><p>Inherits <a href="qobject.html">QObject</a>.<p><a href="qcanvas-members.html">List of all member functions.</a><h2>Public Members</h2><ul><li><div class=fn><a href="#QCanvas"><b>QCanvas</b></a> ( QObject * parent = 0, const char * name = 0 )</div></li><li><div class=fn><a href="#QCanvas-2"><b>QCanvas</b></a> ( int w, int h )</div></li><li><div class=fn><a href="#QCanvas-3"><b>QCanvas</b></a> ( QPixmap p, int h, int v, int tilewidth, int tileheight )</div></li><li><div class=fn>virtual <a href="#~QCanvas"><b>~QCanvas</b></a> ()</div></li><li><div class=fn>virtual void <a href="#setTiles"><b>setTiles</b></a> ( QPixmap p, int h, int v, int tilewidth, int tileheight )</div></li><li><div class=fn>virtual void <a href="#setBackgroundPixmap"><b>setBackgroundPixmap</b></a> ( const QPixmap & p )</div></li><li><div class=fn>QPixmap <a href="#backgroundPixmap"><b>backgroundPixmap</b></a> () const</div></li><li><div class=fn>virtual void <a href="#setBackgroundColor"><b>setBackgroundColor</b></a> ( const QColor & c )</div></li><li><div class=fn>QColor <a href="#backgroundColor"><b>backgroundColor</b></a> () const</div></li><li><div class=fn>virtual void <a href="#setTile"><b>setTile</b></a> ( int x, int y, int tilenum )</div></li><li><div class=fn>int <a href="#tile"><b>tile</b></a> ( int x, int y ) const</div></li><li><div class=fn>int <a href="#tilesHorizontally"><b>tilesHorizontally</b></a> () const</div></li><li><div class=fn>int <a href="#tilesVertically"><b>tilesVertically</b></a> () const</div></li><li><div class=fn>int <a href="#tileWidth"><b>tileWidth</b></a> () const</div></li><li><div class=fn>int <a href="#tileHeight"><b>tileHeight</b></a> () const</div></li><li><div class=fn>virtual void <a href="#resize"><b>resize</b></a> ( int w, int h )</div></li><li><div class=fn>int <a href="#width"><b>width</b></a> () const</div></li><li><div class=fn>int <a href="#height"><b>height</b></a> () const</div></li><li><div class=fn>QSize <a href="#size"><b>size</b></a> () const</div></li><li><div class=fn>QRect <a href="#rect"><b>rect</b></a> () const</div></li><li><div class=fn>bool <a href="#onCanvas"><b>onCanvas</b></a> ( int x, int y ) const</div></li><li><div class=fn>bool <a href="#onCanvas-2"><b>onCanvas</b></a> ( const QPoint & p ) const</div></li><li><div class=fn>bool <a href="#validChunk"><b>validChunk</b></a> ( int x, int y ) const</div></li><li><div class=fn>bool <a href="#validChunk-2"><b>validChunk</b></a> ( const QPoint & p ) const</div></li><li><div class=fn>int <a href="#chunkSize"><b>chunkSize</b></a> () const</div></li><li><div class=fn>virtual void <a href="#retune"><b>retune</b></a> ( int chunksze, int mxclusters = 100 )</div></li><li><div class=fn>virtual void <a href="#setAllChanged"><b>setAllChanged</b></a> ()</div></li><li><div class=fn>virtual void <a href="#setChanged"><b>setChanged</b></a> ( const QRect & area )</div></li><li><div class=fn>virtual void <a href="#setUnchanged"><b>setUnchanged</b></a> ( const QRect & area )</div></li><li><div class=fn>QCanvasItemList <a href="#allItems"><b>allItems</b></a> ()</div></li><li><div class=fn>QCanvasItemList <a href="#collisions"><b>collisions</b></a> ( const QPoint & p ) const</div></li><li><div class=fn>QCanvasItemList <a href="#collisions-2"><b>collisions</b></a> ( const QRect & r ) const</div></li><li><div class=fn>QCanvasItemList <a href="#collisions-3"><b>collisions</b></a> ( const QPointArray & chunklist, const QCanvasItem * item, bool exact ) const</div></li><li><div class=fn>void <a href="#drawArea"><b>drawArea</b></a> ( const QRect & clip, QPainter * painter, bool dbuf = FALSE )</div></li><li><div class=fn>virtual void <a href="#setAdvancePeriod"><b>setAdvancePeriod</b></a> ( int ms )</div></li><li><div class=fn>virtual void <a href="#setUpdatePeriod"><b>setUpdatePeriod</b></a> ( int ms )</div></li><li><div class=fn>virtual void <a href="#setDoubleBuffering"><b>setDoubleBuffering</b></a> ( bool y )</div></li></ul><h2>Public Slots</h2><ul><li><div class=fn>virtual void <a href="#advance"><b>advance</b></a> ()</div></li><li><div class=fn>virtual void <a href="#update"><b>update</b></a> ()</div></li></ul><h2>Signals</h2><ul><li><div class=fn>void <a href="#resized"><b>resized</b></a> ()</div></li></ul><h2>Protected Members</h2><ul><li><div class=fn>virtual void <a href="#drawBackground"><b>drawBackground</b></a> ( QPainter & painter, const QRect & clip )</div></li><li><div class=fn>virtual void <a href="#drawForeground"><b>drawForeground</b></a> ( QPainter & painter, const QRect & clip )</div></li></ul><hr><a name="details"></a><h2>Detailed Description</h2>The QCanvas class provides a 2D area that can contain <a href="qcanvasitem.html">QCanvasItem</a> objects.<p> <p> The QCanvas class manages its 2D graphic area and all the canvas itemsthe area contains. The canvas is displayed on screen with a <a href="qcanvasview.html">QCanvasView</a>widget. Multiple QCanvasView widgets may be associated with acanvas to provide multiple views of the same canvas.<p> The canvas is optimized for large numbers of items. Qt provides a richset of canvas item classes, e.g. <a href="qcanvasellipse.html">QCanvasEllipse</a>, <a href="qcanvasline.html">QCanvasLine</a>,<a href="qcanvaspolygon.html">QCanvasPolygon</a>, <a href="qcanvaspolygonalitem.html">QCanvasPolygonalItem</a>, <a href="qcanvasrectangle.html">QCanvasRectangle</a>, <a href="qcanvasspline.html">QCanvasSpline</a>,<a href="qcanvassprite.html">QCanvasSprite</a> and <a href="qcanvastext.html">QCanvasText</a>. You can subclass to create your owncanvas items; QCanvasPolygonalItem is the most common base class usedfor this purpose.<p> Items appear on the canvas after their <a href="qcanvasitem.html#show">show()</a> function has been called (or <a href="qcanvasitem.html#setVisible">setVisible(TRUE)</a>), and <em>after</em><a href="#update">update</a>() has been called. The canvas only shows items that are <a href="qcanvasitem.html#setVisible">visible</a>, and then only if <a href="#update">update</a>()is called. If you created the canvas without passing a width andheight to the constructor you'll also need to call <a href="#resize">resize</a>().<p> Although a canvas may appear to be similar to a widget with childwidgets, there are several notable differences:<p> <ul><li> Canvas items are usually far faster to manipulate and redraw thanchild widgets, with the speed advantage becoming especially great whenthere are <em>many</em> canvas items and non-rectangular items. In mostsituations canvas items are also a lot more memory efficient than childwidgets.<p> <li> It's easy to detect overlapping items (collision detection).<p> <li> The canvas can be larger than a widget. A million-by-million canvasis perfectly possible. At such a size a widget might be veryinefficient, and some window systems might not support it at all,whereas QCanvas scales well. Even with a billion pixels and a millionitems, finding a particular canvas item, detecting collisions, etc.,is still fast (though the memory consumption may be prohibitiveat such an extreme).<p> <li> Two or more <a href="qcanvasview.html">QCanvasView</a> objects can view the same canvas.<p> <li> An arbitrary transformation matrix can be set on each QCanvasViewwhich makes it easy to zoom, rotate or shear the viewed canvas.<p> <li> Widgets provide a lot more functionality, such as input (<a href="qkeyevent.html">QKeyEvent</a>,<a href="qmouseevent.html">QMouseEvent</a> etc.) and layout management (<a href="qgridlayout.html">QGridLayout</a> etc.).<p> </ul><p> A canvas consists of a background, a number of canvas items organized byx, y and z coordinates, and a foreground. A canvas item's z coordinatemay be treated as a layer number -- canvas items with a higher zcoordinate appear in front of canvas items with a lower z coordinate.<p> The background is white by default, but can be set to a different colorusing <a href="#setBackgroundColor">setBackgroundColor</a>(), or to a repeated pixmap using<a href="#setBackgroundPixmap">setBackgroundPixmap</a>() or to a mosaic of smaller pixmaps using<a href="#setTiles">setTiles</a>(). Individual tiles can be set with <a href="#setTile">setTile</a>(). Thereare corresponding get functions, e.g. <a href="#backgroundColor">backgroundColor</a>() and<a href="#backgroundPixmap">backgroundPixmap</a>().<p> Note that QCanvas does not inherit from <a href="qwidget.html">QWidget</a>, even though it has somefunctions which provide the same functionality as those in QWidget. Oneof these is setBackgroundPixmap(); some others are <a href="#resize">resize</a>(), <a href="#size">size</a>(),<a href="#width">width</a>() and <a href="#height">height</a>(). <a href="qcanvasview.html">QCanvasView</a> is the widget used to display acanvas on the screen.<p> Canvas items are added to a canvas by constructing them and passing thecanvas to the canvas item's constructor. An item can be moved to adifferent canvas using <a href="qcanvasitem.html#setCanvas">QCanvasItem::setCanvas</a>().<p> Canvas items are movable (and in the case of QCanvasSprites, animated)objects that inherit <a href="qcanvasitem.html">QCanvasItem</a>. Each canvas item has a position on thecanvas (x, y coordinates) and a height (z coordinate), all of which areheld as floating-point numbers. Moving canvas items also have x and yvelocities. It's possible for a canvas item to be outside the canvas(for example <a href="qcanvasitem.html#x">QCanvasItem::x</a>() is greater than width()). When a canvasitem is off the canvas, <a href="#onCanvas">onCanvas</a>() returns FALSE and the canvasdisregards the item. (Canvas items off the canvas do not slow down anyof the common operations on the canvas.)<p> Canvas items can be moved with <a href="qcanvasitem.html#move">QCanvasItem::move</a>(). The <a href="#advance">advance</a>()function moves all <a href="qcanvasitem.html#animated">QCanvasItem::animated</a>() canvas items and<a href="#setAdvancePeriod">setAdvancePeriod</a>() makes QCanvas move them automatically on a periodicbasis. In the context of the QCanvas classes, to `animate' a canvas itemis to set it in motion, i.e. using <a href="qcanvasitem.html#setVelocity">QCanvasItem::setVelocity</a>(). Animationof a canvas item itself, i.e. items which change over time, is enabledby calling <a href="qcanvassprite.html#setFrameAnimation">QCanvasSprite::setFrameAnimation</a>(), or more generally bysubclassing and reimplementing <a href="qcanvasitem.html#advance">QCanvasItem::advance</a>(). To detect collisionsuse one of the <a href="qcanvasitem.html#collisions">QCanvasItem::collisions</a>() functions.<p> The changed parts of the canvas are redrawn (if they are visible in acanvas view) whenever <a href="#update">update</a>() is called. You can either call update()manually after having changed the contents of the canvas, or forceperiodic updates using <a href="#setUpdatePeriod">setUpdatePeriod</a>(). If you have moving objects onthe canvas, you need to call <a href="#advance">advance</a>() every time the objects shouldmove one step further. Periodic calls to advance() can be forced using<a href="#setAdvancePeriod">setAdvancePeriod</a>(). The advance() function will callQCanvasItem::advance() on every item that is <a href="qcanvasitem.html#animated">animated</a> and trigger an update of theaffected areas afterwards. (A canvas item that is `animated' is simplya canvas item that is in motion.)<p> QCanvas organizes its canvas items into <em>chunks</em>; these are areas onthe canvas that are used to speed up most operations. Many operationsstart by eliminating most chunks (i.e. those which haven't changed)and then process only the canvas items that are in the few interesting(i.e. changed) chunks. A valid chunk, <a href="#validChunk">validChunk</a>(), is one which is onthe canvas.<p> The chunk size is a key factor to QCanvas's speed: if there are too many
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?