📄 qrect.html
字号:
<!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/kernel/qrect.cpp:42 -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="Translator" content="Cavendish">
<meta name="Qt zh_CN Documents Website" content="http://www.qiliang.net/qt">
<title>QRect类</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; font-family: "Times New Roman" }
--></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">主页</font></a>
| <a href="classes.html">
<font color="#004faf">所有的类</font></a>
| <a href="mainclasses.html">
<font color="#004faf">主要的类</font></a>
| <a href="annotated.html">
<font color="#004faf">注释的类</font></a>
| <a href="groups.html">
<font color="#004faf">分组的类</font></a>
| <a href="functions.html">
<font color="#004faf">函数</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>QRect类参考</h1>
<p>QRect类定了平面上的矩形。
<a href="#details">详情请见……</a>
<p><tt>#include <<a href="qrect-h.html">qrect.h</a>></tt>
<p><a href="qrect-members.html">所有成员函数的列表。</a>
<h2>公有成员</h2>
<ul>
<li><div class=fn><a href="#QRect"><b>QRect</b></a> ()</div></li>
<li><div class=fn><a href="#QRect-2"><b>QRect</b></a> ( const QPoint & topLeft, const QPoint & bottomRight )</div></li>
<li><div class=fn><a href="#QRect-3"><b>QRect</b></a> ( const QPoint & topLeft, const QSize & size )</div></li>
<li><div class=fn><a href="#QRect-4"><b>QRect</b></a> ( int left, int top, int width, int height )</div></li>
<li><div class=fn>bool <a href="#isNull"><b>isNull</b></a> () const</div></li>
<li><div class=fn>bool <a href="#isEmpty"><b>isEmpty</b></a> () const</div></li>
<li><div class=fn>bool <a href="#isValid"><b>isValid</b></a> () const</div></li>
<li><div class=fn>QRect <a href="#normalize"><b>normalize</b></a> () const</div></li>
<li><div class=fn>int <a href="#left"><b>left</b></a> () const</div></li>
<li><div class=fn>int <a href="#top"><b>top</b></a> () const</div></li>
<li><div class=fn>int <a href="#right"><b>right</b></a> () const</div></li>
<li><div class=fn>int <a href="#bottom"><b>bottom</b></a> () const</div></li>
<li><div class=fn>QCOORD & <a href="#rLeft"><b>rLeft</b></a> ()</div></li>
<li><div class=fn>QCOORD & <a href="#rTop"><b>rTop</b></a> ()</div></li>
<li><div class=fn>QCOORD & <a href="#rRight"><b>rRight</b></a> ()</div></li>
<li><div class=fn>QCOORD & <a href="#rBottom"><b>rBottom</b></a> ()</div></li>
<li><div class=fn>int <a href="#x"><b>x</b></a> () const</div></li>
<li><div class=fn>int <a href="#y"><b>y</b></a> () const</div></li>
<li><div class=fn>void <a href="#setLeft"><b>setLeft</b></a> ( int pos )</div></li>
<li><div class=fn>void <a href="#setTop"><b>setTop</b></a> ( int pos )</div></li>
<li><div class=fn>void <a href="#setRight"><b>setRight</b></a> ( int pos )</div></li>
<li><div class=fn>void <a href="#setBottom"><b>setBottom</b></a> ( int pos )</div></li>
<li><div class=fn>void <a href="#setX"><b>setX</b></a> ( int x )</div></li>
<li><div class=fn>void <a href="#setY"><b>setY</b></a> ( int y )</div></li>
<li><div class=fn>QPoint <a href="#topLeft"><b>topLeft</b></a> () const</div></li>
<li><div class=fn>QPoint <a href="#bottomRight"><b>bottomRight</b></a> () const</div></li>
<li><div class=fn>QPoint <a href="#topRight"><b>topRight</b></a> () const</div></li>
<li><div class=fn>QPoint <a href="#bottomLeft"><b>bottomLeft</b></a> () const</div></li>
<li><div class=fn>QPoint <a href="#center"><b>center</b></a> () const</div></li>
<li><div class=fn>void <a href="#rect"><b>rect</b></a> ( int * x, int * y, int * w, int * h ) const</div></li>
<li><div class=fn>void <a href="#coords"><b>coords</b></a> ( int * xp1, int * yp1, int * xp2, int * yp2 ) const</div></li>
<li><div class=fn>void <a href="#moveTopLeft"><b>moveTopLeft</b></a> ( const QPoint & p )</div></li>
<li><div class=fn>void <a href="#moveBottomRight"><b>moveBottomRight</b></a> ( const QPoint & p )</div></li>
<li><div class=fn>void <a href="#moveTopRight"><b>moveTopRight</b></a> ( const QPoint & p )</div></li>
<li><div class=fn>void <a href="#moveBottomLeft"><b>moveBottomLeft</b></a> ( const QPoint & p )</div></li>
<li><div class=fn>void <a href="#moveCenter"><b>moveCenter</b></a> ( const QPoint & p )</div></li>
<li><div class=fn>void <a href="#moveBy"><b>moveBy</b></a> ( int dx, int dy )</div></li>
<li><div class=fn>void <a href="#setRect"><b>setRect</b></a> ( int x, int y, int w, int h )</div></li>
<li><div class=fn>void <a href="#setCoords"><b>setCoords</b></a> ( int xp1, int yp1, int xp2, int yp2 )</div></li>
<li><div class=fn>void <a href="#addCoords"><b>addCoords</b></a> ( int xp1, int yp1, int xp2, int yp2 )</div></li>
<li><div class=fn>QSize <a href="#size"><b>size</b></a> () const</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>void <a href="#setWidth"><b>setWidth</b></a> ( int w )</div></li>
<li><div class=fn>void <a href="#setHeight"><b>setHeight</b></a> ( int h )</div></li>
<li><div class=fn>void <a href="#setSize"><b>setSize</b></a> ( const QSize & s )</div></li>
<li><div class=fn>QRect <a href="#operator|"><b>operator|</b></a> ( const QRect & r ) const</div></li>
<li><div class=fn>QRect <a href="#operator-and"><b>operator&</b></a> ( const QRect & r ) const</div></li>
<li><div class=fn>QRect & <a href="#operator|-eq"><b>operator|=</b></a> ( const QRect & r )</div></li>
<li><div class=fn>QRect & <a href="#operator-and-eq"><b>operator&=</b></a> ( const QRect & r )</div></li>
<li><div class=fn>bool <a href="#contains"><b>contains</b></a> ( const QPoint & p, bool proper = FALSE ) const</div></li>
<li><div class=fn>bool <a href="#contains-2"><b>contains</b></a> ( int x, int y, bool proper = FALSE ) const</div></li>
<li><div class=fn>bool <a href="#contains-3"><b>contains</b></a> ( const QRect & r, bool proper = FALSE ) const</div></li>
<li><div class=fn>QRect <a href="#unite"><b>unite</b></a> ( const QRect & r ) const</div></li>
<li><div class=fn>QRect <a href="#intersect"><b>intersect</b></a> ( const QRect & r ) const</div></li>
<li><div class=fn>bool <a href="#intersects"><b>intersects</b></a> ( const QRect & r ) const</div></li>
</ul>
<h2>相关函数</h2>
<ul>
<li><div class=fn>bool <a href="#operator-eq-eq"><b>operator==</b></a> ( const QRect & r1, const QRect & r2 )</div></li>
<li><div class=fn>bool <a href="#operator!-eq"><b>operator!=</b></a> ( const QRect & r1, const QRect & r2 )</div></li>
<li><div class=fn>QDataStream & <a href="#operator-lt-lt"><b>operator<<</b></a> ( QDataStream & s, const QRect & r )</div></li>
<li><div class=fn>QDataStream & <a href="#operator-gt-gt"><b>operator>></b></a> ( QDataStream & s, QRect & r )</div></li>
</ul>
<hr><a name="details"></a><h2>详细描述</h2>
QRect类定了平面上的矩形。
<p>
<p> 一个矩形在内部是由左上角和右下角表示的,但是通常它所表达到是一个左上角和一个大小。
<p> 坐标类型是QCOORD(和<tt>int</tt>一样在<a href="qwindowdefs-h.html">qwindowdefs.h</a>中定义的)。QCOORD的最小值是QCOORD_MIN(-2147483648),最大值是QCOORD_MAX(2147483647)。
<p> 注意矩形的大小(宽和高)也许与你通常所用的所有不同。如果左上角和右下角相同,那么这个矩形的宽和高都为1。
<p> 通常情况下,<em>width = right - left + 1</em>并且<em>height = bottom - top + 1</em>。我们这样设计是因为这样就可以使矩形空间可以用在绘制函数中,它的宽高就说明了所要绘制的象素。例如,我们画一个宽和高都为1的矩形为一个单一点象素。
<p> 默认坐标系统的原点(0,0)在左上角。y轴的正方向向下,并且x轴的正方向从左到右。
<p> 一个QRect可以用一组上、左、宽、高四个整数,或者从两个QPoint或者从一个<a href="qpoint.html">QPoint</a>和一个<a href="qsize.html">QSize</a>来构造。创建之后,空间可以被改变,比如使用<a href="#setLeft">setLeft</a>()、<a href="#setRight">setRight</a>()、<a href="#setTop">setTop</a>()和<a href="#setBottom">setBottom</a>(),或者通过设置,比如<a href="#setWidth">setWidth</a>()、<a href="#setHeight">setHeight</a>()和<a href="#setSize">setSize</a>()。空间也可以通过移动函数来改变,比如<a href="#moveBy">moveBy</a>()、<a href="#moveCenter">moveCenter</a>()和<a href="#moveBottomRight">moveBottomRight</a>()等等。你也可以用<a href="#addCoords">addCoords</a>()给矩形加上坐标。
<p> 你也可以通过<a href="#contains">contains</a>()测试来看一个QRect是否包含一个特定点。你也可以通过<a href="#intersects">intersects</a>()测试来看两个QRect是否相交(也可以参考<a href="#intersect">intersect</a>())。可以使用<a href="#unite">unite</a>()来获得两个QRect的边界长方形。
<p> <p>也可以参考<a href="qpoint.html">QPoint</a>、<a href="qsize.html">QSize</a>、<a href="graphics.html">图形类</a>和<a href="images.html">图像处理类</a>。
<hr><h2>成员函数文档</h2>
<h3 class=fn><a name="QRect"></a>QRect::QRect ()
</h3>
<p> 构造一个无效的矩形。
<h3 class=fn><a name="QRect-2"></a>QRect::QRect ( const <a href="qpoint.html">QPoint</a> & topLeft, const <a href="qpoint.html">QPoint</a> & bottomRight )
</h3>
构造一个左上角为<em>topLeft</em>,右下角为<em>bottomRight</em>的矩形。
<h3 class=fn><a name="QRect-3"></a>QRect::QRect ( const <a href="qpoint.html">QPoint</a> & topLeft, const <a href="qsize.html">QSize</a> & size )
</h3>
构造一个左上角为<em>topLeft</em>并且矩形大小为<em>size</em>的矩形。
<h3 class=fn><a name="QRect-4"></a>QRect::QRect ( int left, int top, int width, int height )
</h3>
<p> 构造一个上、左、宽、高分别为<em>top</em>、<em>left</em>、<em>width</em>和<em>height</em>的矩形。
<p> 实例(创建三个同样的矩形):
<pre>
QRect r1( QPoint(100,200), QPoint(110,215) );
QRect r2( QPoint(100,200), QSize(11,16) );
QRect r3( 100, 200, 11, 16 );
</pre>
<h3 class=fn>void <a name="addCoords"></a>QRect::addCoords ( int xp1, int yp1, int xp2, int yp2 )
</h3>
分别给矩形已经存在的坐标加上<em>xp1</em>、<em>yp1</em>、<em>xp2</em>和<em>yp2</em>。
<h3 class=fn>int <a name="bottom"></a>QRect::bottom () const
</h3>
<p> 返回矩形的下坐标。
<p> <p>也可以参考<a href="#top">top</a>()、<a href="#setBottom">setBottom</a>()、<a href="#bottomLeft">bottomLeft</a>()和<a href="#bottomRight">bottomRight</a>()。
<p>实例:<a href="desktop-example.html#x1786">desktop/desktop.cpp</a>、<a href="helpviewer-example.html#x1010">helpviewer/helpwindow.cpp</a>、<a href="qfd-example.html#x1985">qfd/fontdisplayer.cpp</a>、<a href="scribble-example.html#x946">scribble/scribble.cpp</a>和<a href="themes-example.html#x197">themes/wood.cpp</a>。
<h3 class=fn><a href="qpoint.html">QPoint</a> <a name="bottomLeft"></a>QRect::bottomLeft () const
</h3>
<p> 返回矩形的左下位置。
<p> <p>也可以参考<a href="#moveBottomLeft">moveBottomLeft</a>()、<a href="#bottomRight">bottomRight</a>()、<a href="#topLeft">topLeft</a>()、<a href="#topRight">topRight</a>()、<a href="#bottom">bottom</a>()和<a href="#left">left</a>()。
<p>实例:<a href="tictac-example.html#x128">tictac/tictac.cpp</a>。
<h3 class=fn><a href="qpoint.html">QPoint</a> <a name="bottomRight"></a>QRect::bottomRight () const
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -