QRegion 類為描繪器指定裁剪區域。 更多...
| 頭: |
#include <QRegion>
|
| CMake: |
find_package(Qt6 REQUIRED COMPONENTS Gui)
target_link_libraries(mytarget PRIVATE Qt6::Gui)
|
| qmake: |
QT += gui
|
| enum | RegionType { Rectangle, Ellipse } |
| const_iterator | |
| const_reverse_iterator |
| QRegion () | |
| QRegion (const QBitmap & bm ) | |
| QRegion (const QPolygon & a , Qt::FillRule fillRule = Qt::OddEvenFill) | |
| QRegion (int x , int y , int w , int h , QRegion::RegionType t = Rectangle) | |
| QRegion (const QRect & r , QRegion::RegionType t = Rectangle) | |
| QRegion (const QRegion & r ) | |
| QRegion (QRegion && other ) | |
| QRegion::const_iterator | begin () const |
| QRect | boundingRect () const |
| QRegion::const_iterator | cbegin () const |
| QRegion::const_iterator | cend () const |
| bool | contains (const QPoint & p ) const |
| bool | contains (const QRect & r ) const |
| QRegion::const_reverse_iterator | crbegin () const |
| QRegion::const_reverse_iterator | crend () const |
| QRegion::const_iterator | end () const |
| QRegion | intersected (const QRect & rect ) const |
| QRegion | intersected (const QRegion & r ) const |
| bool | intersects (const QRect & rect ) const |
| bool | intersects (const QRegion & region ) const |
| bool | isEmpty () const |
| bool | isNull () const |
| QRegion::const_reverse_iterator | rbegin () const |
| int | rectCount () const |
(從 6.8 起)
QSpan<const QRect>
|
rects () const |
| QRegion::const_reverse_iterator | rend () const |
(從 6.8 起)
void
|
setRects (QSpan<const QRect> rects ) |
| QRegion | subtracted (const QRegion & r ) const |
| void | swap (QRegion & other ) |
(從 6.0 起)
HRGN
|
toHRGN () const |
| void | translate (int dx , int dy ) |
| void | translate (const QPoint & point ) |
| QRegion | translated (int dx , int dy ) const |
| QRegion | translated (const QPoint & p ) const |
| QRegion | united (const QRect & rect ) const |
| QRegion | united (const QRegion & r ) const |
| QRegion | xored (const QRegion & r ) const |
| QVariant | operator QVariant () const |
| bool | operator!= (const QRegion & other ) const |
| QRegion | operator& (const QRegion & r ) const |
| QRegion | operator& (const QRect & r ) const |
| QRegion & | operator&= (const QRegion & r ) |
| QRegion & | operator&= (const QRect & r ) |
| QRegion | operator+ (const QRegion & r ) const |
| QRegion | operator+ (const QRect & r ) const |
| QRegion & | operator+= (const QRect & rect ) |
| QRegion & | operator+= (const QRegion & r ) |
| QRegion | operator- (const QRegion & r ) const |
| QRegion & | operator-= (const QRegion & r ) |
| QRegion & | operator= (QRegion && other ) |
| QRegion & | operator= (const QRegion & r ) |
| bool | operator== (const QRegion & r ) const |
| QRegion | operator^ (const QRegion & r ) const |
| QRegion & | operator^= (const QRegion & r ) |
| QRegion | operator| (const QRegion & r ) const |
| QRegion & | operator|= (const QRegion & r ) |
(從 6.0 起)
QRegion
|
fromHRGN (HRGN hrgn ) |
| QDataStream & | operator<< (QDataStream & s , const QRegion & r ) |
| QDataStream & | operator>> (QDataStream & s , QRegion & r ) |
QRegion 用於 QPainter::setClipRegion () 以將描繪區域限製到需要描繪的區域。另外 QWidget::repaint () 函數接受 QRegion 參數。QRegion 是重新描繪更新屏幕區域最小化數量的最佳工具。
此類不適於構造渲染形狀 (尤其作為輪廓)。使用 QPainterPath 以創建路徑和形狀為用於 QPainter .
QRegion 是 隱式共享 類。
可以從矩形、橢圓、多邊形或位圖創建區域。可以創建復雜區域通過組閤簡單區域使用 united (), intersected (), subtracted (),或 xored () (異或)。可以移動區域使用 translate ().
可以測試區域是否 isEmpty () 或者若它 contains () QPoint or QRect 。查找邊界矩形可以采用 boundingRect ().
迭代片區 (采用 begin (), end (), or ranged-for loops) gives a decomposition of the region into rectangles.
使用復雜區域的範例:
void MyWidget::paintEvent(QPaintEvent *) { QRegion r1(QRect(100, 100, 200, 80), // r1: elliptic region QRegion::Ellipse); QRegion r2(QRect(100, 120, 90, 30)); // r2: rectangular region QRegion r3 = r1.intersected(r2); // r3: intersection QPainter painter(this); painter.setClipRegion(r3); // ... // paint clipped graphics }
另請參閱 QPainter::setClipRegion (), QPainter::setClipRect (),和 QPainterPath .
指定要創建的區域形狀。
| 常量 | 值 | 描述 |
|---|---|---|
QRegion::Rectangle
|
0
|
區域覆蓋整個矩形。 |
QRegion::Ellipse
|
1
|
區域是矩形內的橢圓。 |
An iterator over the non-overlapping rectangles that make up the region.
所有矩形的並集等於原始區域。
QRegion 不提供可變迭代器。
A reverse iterator over the non-overlapping rectangles that make up the region.
所有矩形的並集等於原始區域。
QRegion 不提供可變迭代器。
構造空區域。
另請參閱 isEmpty ().
構造區域從位圖 bm .
The resulting region consists of the pixels in bitmap bm that are Qt::color1 , as if each pixel was a 1 by 1 rectangle.
This constructor may create complex regions that will slow down painting when used. Note that drawing masked pixmaps can be done much faster using QPixmap::setMask ().
構造多邊形區域從點數組 a 采用填充規則指定通過 fillRule .
若 fillRule is Qt::WindingFill , the polygon region is defined using the winding algorithm; if it is Qt::OddEvenFill , the odd-even fill algorithm is used.
警告: This constructor can be used to create complex regions that will slow down painting when used.
構造矩形 (或橢圓) 區域。
若
t
is
Rectangle
,區域是填充矩形 (
x
,
y
,
w
,
h
)。若
t
is
Ellipse
,區域是填充橢圓具有中心 (
x
+
w
/ 2,
y
+
h
/ 2) 和大小 (
w
,
h
).
創建片區基於矩形 r 采用片區類型 t .
若矩形無效,將創建 null 區域。
這是重載函數。
另請參閱 QRegion::RegionType .
構造的新區域等於區域 r .
[noexcept]
QRegion::
QRegion
(
QRegion
&&
other
)
Move-constructs a new region from region other . After the call, other 為 null。
另請參閱 isNull ().
[noexcept]
QRegion::const_iterator
QRegion::
begin
() const
返迴 const_iterator pointing to the beginning of the range of non-overlapping rectangles that make up the region.
所有矩形的並集等於原始區域。
另請參閱 rbegin (), cbegin (),和 end ().
[noexcept]
QRect
QRegion::
boundingRect
() const
返迴此區域的邊界矩形。空區域給齣的矩形為 QRect::isNull ().
[noexcept]
QRegion::const_iterator
QRegion::
cbegin
() const
如同 begin ().
[noexcept]
QRegion::const_iterator
QRegion::
cend
() const
如同 end ().
返迴
true
若區域包含點
p
;否則返迴
false
.
返迴
true
若區域重疊矩形
r
;否則返迴
false
.
這是重載函數。
[noexcept]
QRegion::const_reverse_iterator
QRegion::
crbegin
() const
如同 rbegin ().
[noexcept]
QRegion::const_reverse_iterator
QRegion::
crend
() const
如同 rend ().
[noexcept]
QRegion::const_iterator
QRegion::
end
() const
返迴 const_iterator pointing to one past the end of non-overlapping rectangles that make up the region.
所有矩形的並集等於原始區域。
另請參閱 rend (), cend (),和 begin ().
[static, since 6.0]
QRegion
QRegion::
fromHRGN
(
HRGN
hrgn
)
返迴 QRegion 相當於給定 hrgn .
該函數在 Qt 6.0 引入。
返迴區域交集此區域和給定 rect .
另請參閱 subtracted (), united (),和 xored ().
返迴區域交集此區域和 r .
圖形展示 2 橢圓區域的交集。
另請參閱 subtracted (), united (),和 xored ().
返迴
true
若此區域相交
rect
,否則返迴
false
.
返迴
true
若此區域相交
region
,否則返迴
false
.
返迴
true
若區域為空;否則返迴
false
。空區域是不包含任何點的區域。
範例:
QRegion r1(10, 10, 20, 20); r1.isEmpty(); // false QRegion r3; r3.isEmpty(); // true QRegion r2(40, 40, 20, 20); r3 = r1.intersected(r2); // r3: intersection of r1 and r2 r3.isEmpty(); // true r3 = r1.united(r2); // r3: union of r1 and r2 r3.isEmpty(); // false
返迴
true
若區域為空;否則返迴
false
。空區域是不包含點的區域。此函數如同
isEmpty
另請參閱 isEmpty ().
[noexcept]
QRegion::const_reverse_iterator
QRegion::
rbegin
() const
返迴 const_reverse_iterator pointing to the beginning of the range of non-overlapping rectangles that make up the region.
所有矩形的並集等於原始區域。
另請參閱 begin (), crbegin (),和 rend ().
[noexcept]
int
QRegion::
rectCount
() const
Returns the number of rectangles that this region is composed of. Same as
end() - begin()
.
[noexcept, since 6.8]
QSpan
<const
QRect
> QRegion::
rects
() const
Returns a span of non-overlapping rectangles that make up the region. The span remains valid until the next call of a mutating (non-const) method on this region.
所有矩形的並集等於原始區域。
注意: This functions existed in Qt 5, too, but returned QVector < QRect > 代替。
該函數在 Qt 6.8 引入。
另請參閱 setRects ().
[noexcept]
QRegion::const_reverse_iterator
QRegion::
rend
() const
返迴 const_reverse_iterator pointing to one past the end of the range of non-overlapping rectangles that make up the region.
所有矩形的並集等於原始區域。
另請參閱 end (), crend (),和 rbegin ().
[since 6.8]
void
QRegion::
setRects
(
QSpan
<const
QRect
>
rects
)
Sets the region using the array of rectangles specified by rects . The rectangles must be optimally Y-X sorted and follow these restrictions:
注意:
For historical reasons,
rects.size()
must be less than
INT_MAX
(見
rectCount
()).
該函數在 Qt 6.8 引入。
另請參閱 rects ().
返迴區域為 r 減去此區域。
圖形展示左側橢圓減去右側橢圓時的結果 (
left - right
).
另請參閱 intersected (), united (),和 xored ().
[noexcept]
void
QRegion::
swap
(
QRegion
&
other
)
Swaps this region with other 。此操作很快且從不失敗。
[since 6.0]
HRGN
QRegion::
toHRGN
() const
Returns a HRGN that is equivalent to the given region.
該函數在 Qt 6.0 引入。
翻譯 (移動) 區域 dx 沿 X 軸和 dy 沿 Y 軸。
平移片區 point .x() 沿 X 軸和 point .y() along the y axis, relative to the current position. Positive values move the region to the right and down.
翻譯為給定 point .
這是重載函數。
Returns a copy of the region that is translated dx 沿 X 軸和 dy along the y axis, relative to the current position. Positive values move the region to the right and down.
另請參閱 translate ().
返迴的區域副本有平移 p .x() 沿 X 軸和 p .y() 沿 Y 軸,相對當前位置。正值嚮右下移動矩形。
這是重載函數。
另請參閱 translate ().
返迴區域將並集此區域和給定 rect .
另請參閱 intersected (), subtracted (),和 xored ().
返迴區域將並集此區域和 r .
圖形展示 2 橢圓區域的 union (並集)。
另請參閱 intersected (), subtracted (),和 xored ().
返迴區域 XOR (異或) 此區域和 r .
圖形展示 2 橢圓區域的 XOR (異或)。
另請參閱 intersected (), united (),和 subtracted ().
返迴區域按 QVariant
返迴
true
若此區域不同於
other
區域;否則返迴
false
.
應用
intersected
() 函數到此區域和
r
.
r1&r2
相當於
r1.intersected(r2)
.
另請參閱 intersected ().
這是重載函數。
應用
intersected
() 函數到此區域和
r
並將結果賦值給此區域。
r1&=r2
相當於
r1
= r1.intersected(r2).
另請參閱 intersected ().
這是重載函數。
應用
united
() 函數到此區域和
r
.
r1+r2
相當於
r1.united(r2)
.
另請參閱 united () 和 operator| ().
這是重載函數。
Returns a region that is the union of this region with the specified rect .
另請參閱 united ().
應用
united
() 函數到此區域和
r
並將結果賦值給此區域。
r1+=r2
相當於
r1 = r1.united(r2)
.
另請參閱 intersected ().
應用
subtracted
() 函數到此區域和
r
.
r1-r2
相當於
r1.subtracted(r2)
.
另請參閱 subtracted ().
應用
subtracted
() 函數到此區域和
r
並將結果賦值給此區域。
r1-=r2
相當於
r1 = r1.subtracted(r2)
.
另請參閱 subtracted ().
[noexcept]
QRegion
&QRegion::
operator=
(
QRegion
&&
other
)
移動賦值 other 到此 QRegion 實例。
賦值 r 到此區域並返迴區域引用。
返迴
true
若區域等於
r
;否則返迴 false。
應用
xored
() 函數到此區域和
r
.
r1^r2
相當於
r1.xored(r2)
.
另請參閱 xored ().
應用
xored
() 函數到此區域和
r
並將結果賦值給此區域。
r1^=r2
相當於
r1 = r1.xored(r2)
.
另請參閱 xored ().
應用
united
() 函數到此區域和
r
.
r1|r2
相當於
r1.united(r2)
.
另請參閱 united () 和 operator+ ().
應用
united
() 函數到此區域和
r
並將結果賦值給此區域。
r1|=r2
相當於
r1 = r1.united(r2)
.
另請參閱 united ().
寫入片區 r 到流 s 並返迴流引用。
另請參閱 QDataStream 運算符格式 .
讀取區域從流 s into r 並返迴流引用。
另請參閱 QDataStream 運算符格式 .