The QRectF 類使用浮點精度定義平麵矩形。 更多...
| 頭: | #include <QRectF> |
| qmake: | QT += core |
注意: 此類的所有函數 可重入 .
| QRectF () | |
| QRectF (const QPointF & topLeft , const QSizeF & size ) | |
| QRectF (const QPointF & topLeft , const QPointF & bottomRight ) | |
| QRectF (qreal x , qreal y , qreal width , qreal height ) | |
| QRectF (const QRect & rectangle ) | |
| void | adjust (qreal dx1 , qreal dy1 , qreal dx2 , qreal dy2 ) |
| QRectF | adjusted (qreal dx1 , qreal dy1 , qreal dx2 , qreal dy2 ) const |
| qreal | bottom () const |
| QPointF | bottomLeft () const |
| QPointF | bottomRight () const |
| QPointF | center () const |
| bool | contains (const QPointF & point ) const |
| bool | contains (const QRectF & rectangle ) const |
| bool | contains (qreal x , qreal y ) const |
| void | getCoords (qreal * x1 , qreal * y1 , qreal * x2 , qreal * y2 ) const |
| void | getRect (qreal * x , qreal * y , qreal * width , qreal * height ) const |
| qreal | height () const |
| QRectF | intersected (const QRectF & rectangle ) const |
| bool | intersects (const QRectF & rectangle ) const |
| bool | isEmpty () const |
| bool | isNull () const |
| bool | isValid () const |
| qreal | left () const |
| QRectF | marginsAdded (const QMarginsF & margins ) const |
| QRectF | marginsRemoved (const QMarginsF & margins ) const |
| void | moveBottom (qreal y ) |
| void | moveBottomLeft (const QPointF & position ) |
| void | moveBottomRight (const QPointF & position ) |
| void | moveCenter (const QPointF & position ) |
| void | moveLeft (qreal x ) |
| void | moveRight (qreal x ) |
| void | moveTo (qreal x , qreal y ) |
| void | moveTo (const QPointF & position ) |
| void | moveTop (qreal y ) |
| void | moveTopLeft (const QPointF & position ) |
| void | moveTopRight (const QPointF & position ) |
| QRectF | normalized () const |
| qreal | right () const |
| void | setBottom (qreal y ) |
| void | setBottomLeft (const QPointF & position ) |
| void | setBottomRight (const QPointF & position ) |
| void | setCoords (qreal x1 , qreal y1 , qreal x2 , qreal y2 ) |
| void | setHeight (qreal height ) |
| void | setLeft (qreal x ) |
| void | setRect (qreal x , qreal y , qreal width , qreal height ) |
| void | setRight (qreal x ) |
| void | setSize (const QSizeF & size ) |
| void | setTop (qreal y ) |
| void | setTopLeft (const QPointF & position ) |
| void | setTopRight (const QPointF & position ) |
| void | setWidth (qreal width ) |
| void | setX (qreal x ) |
| void | setY (qreal y ) |
| QSizeF | size () const |
| QRect | toAlignedRect () const |
| CGRect | toCGRect () const |
| QRect | toRect () const |
| qreal | top () const |
| QPointF | topLeft () const |
| QPointF | topRight () const |
| void | translate (qreal dx , qreal dy ) |
| void | translate (const QPointF & offset ) |
| QRectF | translated (qreal dx , qreal dy ) const |
| QRectF | translated (const QPointF & offset ) const |
| QRectF | transposed () const |
| QRectF | united (const QRectF & rectangle ) const |
| qreal | width () const |
| qreal | x () const |
| qreal | y () const |
| QRectF | operator& (const QRectF & rectangle ) const |
| QRectF & | operator&= (const QRectF & rectangle ) |
| QRectF & | operator+= (const QMarginsF & margins ) |
| QRectF & | operator-= (const QMarginsF & margins ) |
| QRectF | operator| (const QRectF & rectangle ) const |
| QRectF & | operator|= (const QRectF & rectangle ) |
| QRectF | fromCGRect (CGRect rect ) |
| bool | operator!= (const QRectF & r1 , const QRectF & r2 ) |
| QRectF | operator+ (const QRectF & lhs , const QMarginsF & rhs ) |
| QRectF | operator+ (const QMarginsF & lhs , const QRectF & rhs ) |
| QRectF | operator- (const QRectF & lhs , const QMarginsF & rhs ) |
| QDataStream & | operator<< (QDataStream & stream , const QRectF & rectangle ) |
| bool | operator== (const QRectF & r1 , const QRectF & r2 ) |
| QDataStream & | operator>> (QDataStream & stream , QRectF & rectangle ) |
The QRectF 類使用浮點精度定義平麵矩形。
A rectangle is normally expressed as a top-left corner and a size. The size (width and height) of a QRectF 始終相當於形成其渲染基礎的數學矩形。
A QRectF 可以按一組左、上、寬度和高度坐標構造,或從 QPointF 和 QSizeF 。以下代碼創建 2 個恒等矩形。
QRectF r1(100.0, 200.1, 11.2, 16.3); QRectF r2(QPointF(100.0, 200.1), QSizeF(11.2, 16.3));
還有第 3 個構造函數創建 QRectF 從 QRect ,且相應 toRect () 函數返迴 QRect 對象基於此矩形值 (注意:返迴矩形的坐標會被四捨五入到最近整數)。
The QRectF 類提供瞭返迴各種矩形坐標,並使之能夠操縱這些坐標的一批函數。 QRectF also provides functions to move the rectangle relative to the various coordinates. In addition there is a moveTo () 函數能移動矩形,使其左上角留在給定坐標處。另外, translate () 函數相對當前位置將矩形移動給定偏移,和 translated () 函數返迴此矩形的翻譯副本。
The size () 函數返迴矩形的尺度按 QSizeF 。還可以單獨檢索尺度使用 width () 和 height () 函數。要操縱維度使用 setSize (), setWidth () 或 setHeight () 函數。另外,通過應用設置矩形坐標的函數可以改變大小,例如 setBottom () 或 setRight ().
The
contains
() 函數告訴給定點是否在矩形內,和
intersects
() 函數返迴
true
若此矩形與給定矩形相交 (否則 false)。
QRectF
類還提供
intersected
() 函數返迴交集矩形,和
united
() 函數返迴包圍給定矩形的矩形,如下所示:
|
|
| intersected () | united () |
The
isEmpty
() 函數返迴
true
若矩形的寬度或高度小於或等於 0。注意,空矩形無效:
isValid
() 函數返迴
true
若寬度和高度兩者 > 0。null 矩形 (
isNull
() == true) 另一方麵,有將寬度和高度兩者設為 0。
注意,由於方式有關 QRect and QRectF 的定義,空 QRectF 的定義方式本質上如同 QRect .
最後, QRectF 對象可以被流化及比較。
當使用 抗鋸齒 描繪器,邊界綫對於 QRectF 將對稱渲染在數學矩形邊界綫的 2 側。但當使用鋸齒描繪器 (默認) 時,應用其它規則。
那麼,當按 1 像素寬鋼筆渲染時 QRectF 的邊界綫將渲染在數學矩形邊界綫的右側和下方。
當按 2 像素寬鋼筆渲染時,數學矩形將從中間分割邊界綫。將是這種情況每當將鋼筆設為偶數像素時,當以奇數像素鋼筆渲染時,將把備用像素渲染到數學矩形的右側和下方 (如 1 像素情況)。
|
|
| 邏輯錶示 | 1 像素寬鋼筆 |
|
|
| 2 像素寬鋼筆 | 3 像素寬鋼筆 |
The QRectF 類提供瞭返迴各種矩形坐標,並使之能夠操縱這些坐標的一批函數。 QRectF also provides functions to move the rectangle relative to the various coordinates.
例如: bottom (), setBottom () 和 moveBottom () 函數: bottom () 返迴矩形下邊緣的 Y 坐標, setBottom () 將矩形下邊緣設為給定 Y 坐標 (可能改變高度,但從不改變矩形的上邊緣) 和 moveBottom () 垂直移動整個矩形,使矩形下邊緣留在給定 Y 坐標處且其大小保持不變。
也是可能的,將偏移添加到此矩形的坐標使用 adjust () 函數,及基於原始矩形的調節檢索新矩形是使用 adjusted () 函數。若寬度和高度兩者任一為負,使用 normalized () 函數以檢索角交換矩形。
此外, QRectF 提供 getCoords () 函數提取矩形左上角和右下角的位置,和 getRect () 函數提取矩形的左上角、寬度和高度。使用 setCoords () 和 setRect () 函數能一次性操縱矩形的坐標和尺度。
構造 null 矩形。
另請參閱 isNull ().
構造矩形采用給定 topLeft 角和給定 size .
另請參閱 setTopLeft () 和 setSize ().
構造矩形采用給定 topLeft and bottomRight 角。
該函數在 Qt 4.3 引入。
另請參閱 setTopLeft () 和 setBottomRight ().
構造矩形采用 ( x , y ) 作為其左上角和給定 width and height .
另請參閱 setRect ().
構造 QRectF 矩形從給定 QRect rectangle .
另請參閱 toRect ().
添加 dx1 , dy1 , dx2 and dy2 分彆到矩形的現有坐標。
另請參閱 adjusted () 和 setRect ().
返迴新的矩形采用 dx1 , dy1 , dx2 and dy2 分彆添加到此矩形的現有坐標。
另請參閱 adjust ().
返迴矩形底部邊緣的 Y 坐標。
另請參閱 setBottom (), bottomLeft (),和 bottomRight ().
返迴矩形左下角位置。
另請參閱 setBottomLeft (), bottom (),和 left ().
返迴矩形右下角的位置。
另請參閱 setBottomRight (), bottom (),和 right ().
返迴矩形的中心點。
另請參閱 moveCenter ().
返迴
true
若給定
point
在矩形內或邊緣;否則返迴
false
.
另請參閱 intersects ().
這是重載函數。
返迴
true
若給定
rectangle
在此矩形內;否則返迴
false
.
這是重載函數。
返迴
true
若點 (
x
,
y
) 在矩形內或邊緣;否則返迴
false
.
[static]
QRectF
QRectF::
fromCGRect
(
CGRect
rect
)
創建 QRectF 從 CGRect rect .
該函數在 Qt 5.8 引入。
另請參閱 toCGRect ().
將矩形左上角位置提取到 * x1 和 * y1 ,和右下角位置到 * x2 和 * y2 .
另請參閱 setCoords () 和 getRect ().
將矩形左上角位置提取到 * x 和 * y ,和其尺度到 * width 和 * height .
另請參閱 setRect () 和 getCoords ().
返迴矩形的高度。
另請參閱 setHeight (), width (),和 size ().
返迴交集為此矩形和給定
rectangle
。注意,
r.intersected(s)
相當於
r & s
.
該函數在 Qt 4.2 引入。
另請參閱 intersects (), united (),和 operator&= ().
返迴
true
若此矩形相交給定
rectangle
(即:在它們之間存在非空重疊區域),否則返迴
false
.
可以檢索交集矩形使用 intersected () 函數。
另請參閱 contains ().
返迴
true
若矩形為空,否則返迴
false
.
空矩形擁有 width () <= 0 或 height () <= 0。空矩形無效 (即:isEmpty() == ! isValid ()).
使用 normalized () 函數以檢索角交換矩形。
另請參閱 isNull (), isValid (),和 normalized ().
返迴
true
若矩形是 null 矩形,否則返迴
false
.
null 矩形有將寬度和高度兩者設為 0。null 矩形也為空,因此無效。
返迴
true
若矩形有效,否則返迴
false
.
有效矩形擁有 width () > 0 和 height () > 0。注意,非通俗操作 (像交集) 對於無效矩形未定義。有效矩形不為空 (即 isValid() == ! isEmpty ()).
另請參閱 isNull (), isEmpty (),和 normalized ().
返迴矩形左邊緣的 X 坐標。相當於 x ().
另請參閱 setLeft (), topLeft (),和 bottomLeft ().
返迴矩形增長按 margins .
該函數在 Qt 5.3 引入。
另請參閱 operator+= (), marginsRemoved (),和 operator-= ().
移除 margins 從矩形,收縮它。
該函數在 Qt 5.3 引入。
另請參閱 marginsAdded (), operator+= (),和 operator-= ().
垂直移動矩形,使矩形底邊綫留在給定 y 坐標。矩形的大小保持不變。
另請參閱 bottom (), setBottom (),和 moveTop ().
移動矩形,使左下角留在給定 position 。矩形的大小保持不變。
另請參閱 setBottomLeft (), moveBottom (),和 moveLeft ().
移動矩形,使右下角留在給定 position 。矩形的大小保持不變。
另請參閱 setBottomRight (), moveBottom (),和 moveRight ().
移動矩形,使中心點位於給定 position 。矩形的大小保持不變。
另請參閱 center ().
水平移動矩形,使矩形左邊緣留在給定 x 坐標。矩形的大小保持不變。
另請參閱 left (), setLeft (),和 moveRight ().
水平移動矩形,使矩形右邊緣留在給定 x 坐標。矩形的大小保持不變。
另請參閱 right (), setRight (),和 moveLeft ().
移動矩形,使左上角留在給定位置 ( x , y )。矩形的大小保持不變。
另請參閱 translate () 和 moveTopLeft ().
這是重載函數。
移動矩形,使左上角留在給定 position .
垂直移動矩形,使矩形上邊綫留在給定 y 坐標。矩形的大小保持不變。
另請參閱 top (), setTop (),和 moveBottom ().
移動矩形,使左上角留在給定 position 。矩形的大小保持不變。
另請參閱 setTopLeft (), moveTop (),和 moveLeft ().
移動矩形,使右上角留在給定 position 。矩形的大小保持不變。
另請參閱 setTopRight (), moveTop (),和 moveRight ().
返迴規範化矩形;即:矩形擁有非負值寬度和高度。
若 width () < 0 函數交換左右角,和它交換上下角若 height () < 0.
返迴矩形右邊的 X 坐標。
另請參閱 setRight (), topRight (),和 bottomRight ().
將矩形下邊緣設為給定 y 坐標。可能改變高度,但從不會改變矩形的上邊緣。
另請參閱 bottom () 和 moveBottom ().
將矩形左下角設為給定 position 。可能改變大小,但從不會改變矩形的右上角。
另請參閱 bottomLeft () 和 moveBottomLeft ().
將矩形右下角設為給定 position 。可能改變大小,但從不改變矩形左上角。
另請參閱 bottomRight () 和 moveBottomRight ().
將矩形左上角坐標設為 ( x1 , y1 ),和它的右下角坐標到 ( x2 , y2 ).
另請參閱 getCoords () 和 setRect ().
將矩形高度設為給定 height 。下邊緣改變,但不改變上邊緣。
將矩形左邊緣設為給定 x 坐標。可能改變寬度,但從不會改變矩形的右邊緣。
相當於 setX ().
將矩形左上角坐標設為 ( x , y ),和它的大小到給定 width and height .
另請參閱 getRect () 和 setCoords ().
將矩形右邊緣設為給定 x 坐標。可能改變寬度,但從不會改變矩形的左邊緣。
將矩形大小設為給定 size 。不移動左上角。
另請參閱 size (), setWidth (),和 setHeight ().
將矩形上邊緣設為給定 y 坐標。可能改變高度,但從不會改變矩形的下邊緣。
相當於 setY ().
將矩形左上角設為給定 position 。可能改變大小,但從不改變矩形的右下角。
另請參閱 topLeft () 和 moveTopLeft ().
將矩形右上角設為給定 position 。可能改變大小,但從不改變矩形的右下角。
另請參閱 topRight () 和 moveTopRight ().
將矩形寬度設為給定 width 。右邊緣改變,但左邊緣不改變。
將矩形左邊緣設為給定 x 坐標。可能改變寬度,但從不會改變矩形的右邊緣。
相當於 setLeft ().
另請參閱 x (), setY (),和 setTopLeft ().
將矩形上邊緣設為給定 y 坐標。可能改變高度,但從不會改變矩形的下邊緣。
相當於 setTop ().
另請參閱 y (), setX (),和 setTopLeft ().
返迴矩形的大小。
另請參閱 setSize (), width (),和 height ().
返迴 QRect 基於此矩形 (完全包含此矩形的最小可能整數矩形) 的值。
該函數在 Qt 4.3 引入。
另請參閱 toRect ().
創建 CGRect 從 QRectF .
該函數在 Qt 5.8 引入。
另請參閱 fromCGRect ().
返迴 QRect 基於此矩形的值。注意,返迴矩形的坐標會被四捨五入到最近整數。
另請參閱 QRectF () 和 toAlignedRect ().
返迴矩形上邊緣的 Y 坐標。相當於 y ().
另請參閱 setTop (), topLeft (),和 topRight ().
返迴矩形左上角的位置。
另請參閱 setTopLeft (), top (),和 left ().
返迴矩形右上角的位置。
另請參閱 setTopRight (), top (),和 right ().
移動矩形 dx 沿 X 軸和 dy 沿 Y 軸,相對當前位置。正值將矩形嚮右和嚮下移動。
另請參閱 moveTopLeft (), moveTo (),和 translated ().
這是重載函數。
移動矩形 offset . x() 沿 X 軸和 offset . y() 沿 Y 軸,相對當前位置。
返迴的矩形副本有平移 dx 沿 X 軸和 dy 沿 Y 軸,相對當前位置。正值嚮右下移動矩形。
另請參閱 translate ().
這是重載函數。
返迴的矩形副本有平移 offset . x() 沿 X 軸和 offset . y() 沿 Y 軸,相對當前位置。
返迴交換瞭寬度和高度的矩形副本:
QRectF r = {1.5, 5.1, 4.2, 2.4}; r = r.transposed(); // r == {1.5, 5.1, 2.4, 4.2}
該函數在 Qt 5.7 引入。
另請參閱 QSizeF::transposed ().
返迴邊界矩形為此矩形和給定 rectangle .
該函數在 Qt 4.2 引入。
另請參閱 intersected ().
返迴矩形的寬度。
另請參閱 setWidth (), height (),和 size ().
返迴矩形左邊緣的 X 坐標。相當於 left ().
另請參閱 setX (), y (),和 topLeft ().
返迴矩形上邊緣的 Y 坐標。相當於 top ().
另請參閱 setY (), x (),和 topLeft ().
返迴交集為此矩形和給定 rectangle 。返迴空矩形若沒有交集。
另請參閱 operator&= () 和 intersected ().
相交此矩形與給定 rectangle .
另請參閱 intersected () 和 operator|= ().
添加 margins 到矩形,增長它。
該函數在 Qt 5.3 引入。
另請參閱 marginsAdded (), marginsRemoved (),和 operator-= ().
返迴矩形的收縮按 margins .
該函數在 Qt 5.3 引入。
另請參閱 marginsRemoved (), operator+= (),和 marginsAdded ().
返迴邊界矩形為此矩形和給定 rectangle .
另請參閱 united () 和 operator|= ().
聯閤此矩形與給定 rectangle .
另請參閱 united () 和 operator| ().
返迴
true
若矩形
r1
and
r2
are sufficiently different, otherwise returns
false
.
警告: This function does not check for strict inequality; instead, it uses a fuzzy comparison to compare the rectangles' coordinates.
返迴 lhs 矩形增長按 rhs 邊距。
該函數在 Qt 5.3 引入。
這是重載函數。
返迴 lhs 矩形增長按 rhs 邊距。
該函數在 Qt 5.3 引入。
返迴 lhs rectangle shrunk by the rhs 邊距。
該函數在 Qt 5.3 引入。
寫入 rectangle 到 stream ,並返迴流引用。
另請參閱 序列化 Qt 數據類型 .
返迴
true
若矩形
r1
and
r2
are
approximately
等於,否則返迴
false
.
警告: This function does not check for strict equality; instead, it uses a fuzzy comparison to compare the rectangles' coordinates.
另請參閱 qFuzzyCompare .
讀取 rectangle 從 stream ,並返迴流引用。
另請參閱 序列化 Qt 數據類型 .