qcanvas.html

来自「QT 下载资料仅供参考」· HTML 代码 · 共 569 行 · 第 1/3 页

HTML
569
字号
chunks, the speed benefit of grouping canvas items into chunks isreduced. If the chunks are too large, it takes too long to process eachone. The QCanvas constructor picks a hopefully suitable size, but youcan call <a href="#retune">retune</a>() to change it at any time. The <a href="#chunkSize">chunkSize</a>() functionreturns the current chunk size.<p> The canvas items always make sure they're in the right chunks; all youneed to make sure of is that the canvas uses the right chunk size. Agood rule of thumb is that the size should be a bit smaller than theaverage canvas item size. If you have moving objects, the chunk sizeshould be a bit smaller than the average size of the moving items.<p> The foreground is normally nothing, but if you reimplement<a href="#drawForeground">drawForeground</a>(), you can draw things in front of all canvas items.<p> Areas can be set as changed with <a href="#setChanged">setChanged</a>() and set unchanged with<a href="#setUnchanged">setUnchanged</a>(). The entire canvas can be set as changed with<a href="#setAllChanged">setAllChanged</a>(). A list of all the items on the canvas is returned by<a href="#allItems">allItems</a>().<p> An area can be copied (painted) to a <a href="qpainter.html">QPainter</a> with <a href="#drawArea">drawArea</a>().<p> If the canvas is resized it emits the <a href="#resized">resized</a>() signal.<p> The examples/canvas application and the 2D graphics page of theexamples/demo application demonstrate many of QCanvas's facilities.<p> <p>See also <a href="qcanvasview.html">QCanvasView</a>, <a href="qcanvasitem.html">QCanvasItem</a>, <a href="abstractwidgets.html">Abstract Widget Classes</a>, <a href="graphics.html">Graphics Classes</a> and <a href="images.html">Image Processing Classes</a>.<hr><h2>Member Function Documentation</h2><h3 class=fn><a name="QCanvas"></a>QCanvas::QCanvas ( <a href="qobject.html">QObject</a>&nbsp;*&nbsp;parent = 0, const&nbsp;char&nbsp;*&nbsp;name = 0 )</h3>Create a QCanvas with no size. <em>parent</em> and <em>name</em> are passed tothe <a href="qobject.html">QObject</a> superclass.<p> <b>Warning:</b> You <em>must</em> call <a href="#resize">resize</a>() at some time after creation to beable to use the canvas.<h3 class=fn><a name="QCanvas-2"></a>QCanvas::QCanvas ( int&nbsp;w, int&nbsp;h )</h3>Constructs a QCanvas that is <em>w</em> pixels wide and <em>h</em> pixels high.<h3 class=fn><a name="QCanvas-3"></a>QCanvas::QCanvas ( <a href="qpixmap.html">QPixmap</a>&nbsp;p, int&nbsp;h, int&nbsp;v, int&nbsp;tilewidth, int&nbsp;tileheight )</h3>Constructs a QCanvas which will be composed of<em>h</em> tiles horizontally and <em>v</em> tiles vertically. Each tilewill be an image <em>tilewidth</em> by <em>tileheight</em> pixels taken frompixmap <em>p</em>.<p> The pixmap <em>p</em> is a list of tiles, arranged left to right, (and inthe case of pixmaps that have multiple rows of tiles, top to bottom),with tile 0 in the top-left corner, tile 1 next to the right, and soon, e.g.<p> <center><table cellpadding="4" cellspacing="2" border="0"><tr bgcolor="#f0f0f0"> <td valign="top">0 <td valign="top">1 <td valign="top">2 <td valign="top">3<tr bgcolor="#d0d0d0"> <td valign="top">4 <td valign="top">5 <td valign="top">6 <td valign="top">7</table></center><p> The QCanvas is initially sized to show exactly the given numberof tiles horizontally and vertically. If it is resized to be larger,the entire matrix of tiles will be repeated as much as necessary tocover the area. If it is smaller, tiles tothe right and bottom will not be visible.<p> <p>See also <a href="#setTiles">setTiles</a>().<h3 class=fn><a name="~QCanvas"></a>QCanvas::~QCanvas ()<tt> [virtual]</tt></h3>Destroys the canvas and all the canvas's canvas items.<h3 class=fn>void <a name="advance"></a>QCanvas::advance ()<tt> [virtual slot]</tt></h3><p> Moves all <a href="qcanvasitem.html#animated">QCanvasItem::animated</a>() canvas items on the canvas andrefreshes all changes to all views of the canvas. (An `animated'item is an item that is in motion; see setVelocity().)<p> The advance takes place in two phases. In phase 0, the<a href="qcanvasitem.html#advance">QCanvasItem::advance</a>() function of each QCanvasItem::animated() canvasitem is called with paramater 0. Then all these canvas items arecalled again, with parameter 1. In phase 0, the canvas items shouldnot change position, merely examine other items on the canvas forwhich special processing is required, such as collisions betweenitems. In phase 1, all canvas items should change positions, ignoringany other items on the canvas. This two-phase approach allows forconsiderations of "fairness", although no <a href="qcanvasitem.html">QCanvasItem</a> subclassessupplied with Qt do anything interesting in phase 0.<p> The canvas can be configured to call this function periodically with<a href="#setAdvancePeriod">setAdvancePeriod</a>().<p> <p>See also <a href="#update">update</a>().<h3 class=fn><a href="qcanvasitemlist.html">QCanvasItemList</a> <a name="allItems"></a>QCanvas::allItems ()</h3>Returns a list of all items in the canvas.<h3 class=fn><a href="qcolor.html">QColor</a> <a name="backgroundColor"></a>QCanvas::backgroundColor () const</h3>Returns the color set by <a href="#setBackgroundColor">setBackgroundColor</a>().By default, this is white.<p> This function is not a reimplementation of<a href="qwidget.html#backgroundColor">QWidget::backgroundColor</a>() (QCanvas is not a subclass of <a href="qwidget.html">QWidget</a>),but all QCanvasViews that are viewing the canvas will set theirbackgrounds to this color.<p> <p>See also <a href="#setBackgroundColor">setBackgroundColor</a>() and <a href="#backgroundPixmap">backgroundPixmap</a>().<h3 class=fn><a href="qpixmap.html">QPixmap</a> <a name="backgroundPixmap"></a>QCanvas::backgroundPixmap () const</h3>Returns the pixmap set by <a href="#setBackgroundPixmap">setBackgroundPixmap</a>(). By default,this is a null pixmap.<p> <p>See also <a href="#setBackgroundPixmap">setBackgroundPixmap</a>() and <a href="#backgroundColor">backgroundColor</a>().<h3 class=fn>int <a name="chunkSize"></a>QCanvas::chunkSize () const</h3><p> Returns the chunk size of the canvas.<p> <p>See also <a href="#retune">retune</a>().<h3 class=fn><a href="qcanvasitemlist.html">QCanvasItemList</a> <a name="collisions"></a>QCanvas::collisions ( const&nbsp;<a href="qpoint.html">QPoint</a>&nbsp;&amp;&nbsp;p ) const</h3>Returns a list of canvas items that intersect with the point <em>p</em>.The list is ordered by z coordinates, from highest z coordinate(front-most item) to lowest z coordinate (rear-most item).<h3 class=fn><a href="qcanvasitemlist.html">QCanvasItemList</a> <a name="collisions-2"></a>QCanvas::collisions ( const&nbsp;<a href="qrect.html">QRect</a>&nbsp;&amp;&nbsp;r ) const</h3>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.<p> Returns a list of items which intersect with the rectangle <em>r</em>.The list is ordered by z coordinates, from highest z coordinate(front-most item) to lowest z coordinate (rear-most item).<h3 class=fn><a href="qcanvasitemlist.html">QCanvasItemList</a> <a name="collisions-3"></a>QCanvas::collisions ( const&nbsp;<a href="qpointarray.html">QPointArray</a>&nbsp;&amp;&nbsp;chunklist, const&nbsp;<a href="qcanvasitem.html">QCanvasItem</a>&nbsp;*&nbsp;item, bool&nbsp;exact ) const</h3>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.<p> Returns a list of canvas items which intersect with the chunks listedin <em>chunklist</em>, excluding <em>item</em>. If <em>exact</em> is TRUE, onlythose which actually <a href="qcanvasitem.html#collidesWith">QCanvasItem::collidesWith</a>() <em>item</em> are returned;otherwise canvas items are included just for being in the chunks.<p> This is a utility function mainly used to implement the simpler<a href="qcanvasitem.html#collisions">QCanvasItem::collisions</a>() function.<h3 class=fn>void <a name="drawArea"></a>QCanvas::drawArea ( const&nbsp;<a href="qrect.html">QRect</a>&nbsp;&amp;&nbsp;clip, <a href="qpainter.html">QPainter</a>&nbsp;*&nbsp;painter, bool&nbsp;dbuf = FALSE )</h3>Paints all canvas items that are in the area <em>clip</em> to <em>painter</em>,using double-buffering if <em>dbuf</em> is TRUE.<p> e.g. to print the canvas to a printer:<pre>  <a href="qprinter.html">QPrinter</a> pr;  if ( pr.<a href="qprinter.html#setup">setup</a>() ) {    <a href="qpainter.html">QPainter</a> p(&amp;pr);    canvas.drawArea( canvas.rect(), &amp;p );  }  </pre> <p>Example: <a href="canvas-example.html#x2684">canvas/canvas.cpp</a>.<h3 class=fn>void <a name="drawBackground"></a>QCanvas::drawBackground ( <a href="qpainter.html">QPainter</a>&nbsp;&amp;&nbsp;painter, const&nbsp;<a href="qrect.html">QRect</a>&nbsp;&amp;&nbsp;clip )<tt> [virtual protected]</tt></h3>This virtual function is called for all updates of the canvas.It renders any background graphics using the painter <em>painter</em>, in thearea <em>clip</em>. If the canvas has a backgroundpixmap or a tiled background, that graphic is used, otherwise thecanvas is cleared using the background color.<p> If the graphics for an area change, you must explicitly call<a href="#setChanged">setChanged</a>(const <a href="qrect.html">QRect</a>&) for the result to be visible when <a href="#update">update</a>()is next called.<p> <p>See also <a href="#setBackgroundColor">setBackgroundColor</a>(), <a href="#setBackgroundPixmap">setBackgroundPixmap</a>() and <a href="#setTiles">setTiles</a>().<h3 class=fn>void <a name="drawForeground"></a>QCanvas::drawForeground ( <a href="qpainter.html">QPainter</a>&nbsp;&amp;&nbsp;painter, const&nbsp;<a href="qrect.html">QRect</a>&nbsp;&amp;&nbsp;clip )<tt> [virtual protected]</tt></h3>This virtual function is called for all updates of the canvas.It renders any foreground graphics using the painter <em>painter</em>, inthe area <em>clip</em>.<p> If the graphics for an area change, you must explicitly call<a href="#setChanged">setChanged</a>(const <a href="qrect.html">QRect</a>&) for the result to be visible when <a href="#update">update</a>()is next called.<p> The default is to draw nothing.<h3 class=fn>int <a name="height"></a>QCanvas::height () const</h3><p> Returns the height of the canvas, in pixels.<p>Example: <a href="canvas-example.html#x2685">canvas/canvas.cpp</a>.<h3 class=fn>bool <a name="onCanvas"></a>QCanvas::onCanvas ( int&nbsp;x, int&nbsp;y ) const</h3><p> Returns TRUE if the pixel position (<em>x</em>, <em>y</em>) is on the canvas;otherwise returns FALSE.<p> <p>See also <a href="#validChunk">validChunk</a>().<h3 class=fn>bool <a name="onCanvas-2"></a>QCanvas::onCanvas ( const&nbsp;<a href="qpoint.html">QPoint</a>&nbsp;&amp;&nbsp;p ) const</h3>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.<p> Returns TRUE if the pixel position <em>p</em> is on the canvas;otherwise returns FALSE.<p> <p>See also <a href="#validChunk">validChunk</a>().<h3 class=fn><a href="qrect.html">QRect</a> <a name="rect"></a>QCanvas::rect () const</h3><p> Returns a rectangle the size of the canvas.<h3 class=fn>void <a name="resize"></a>QCanvas::resize ( int&nbsp;w, int&nbsp;h )<tt> [virtual]</tt>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?