Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qrect.cpp
Go to the documentation of this file.
1
// Copyright (C) 2022 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
// Qt-Security score:significant reason:default
4
5
#
include
"qrect.h"
6
#
include
"qdatastream.h"
7
#
include
"qmath.h"
8
9
#
include
<
private
/
qdebug_p
.
h
>
10
11
QT_BEGIN_NAMESPACE
12
13
/*!
14
\class QRect
15
\inmodule QtCore
16
\ingroup painting
17
\reentrant
18
19
\compares equality
20
\compareswith equality QRectF
21
\endcompareswith
22
23
\brief The QRect class defines a rectangle in the plane using
24
integer precision.
25
26
A rectangle is normally expressed as a top-left corner and a
27
size. The size (width and height) of a QRect is always equivalent
28
to the mathematical rectangle that forms the basis for its
29
rendering.
30
31
A QRect can be constructed with a set of left, top, width and
32
height integers, or from a QPoint and a QSize. The following code
33
creates two identical rectangles.
34
35
\snippet code/src_corelib_tools_qrect.cpp 0
36
37
There is a third constructor that creates a QRect using the
38
top-left and bottom-right coordinates, but we recommend that you
39
avoid using it. The rationale is that for historical reasons the
40
values returned by the bottom() and right() functions deviate from
41
the true bottom-right corner of the rectangle.
42
43
The QRect class provides a collection of functions that return the
44
various rectangle coordinates, and enable manipulation of
45
these. QRect also provides functions to move the rectangle relative
46
to the various coordinates. In addition there is a moveTo()
47
function that moves the rectangle, leaving its top left corner at
48
the given coordinates. Alternatively, the translate() function
49
moves the rectangle the given offset relative to the current
50
position, and the translated() function returns a translated copy
51
of this rectangle.
52
53
The size() function returns the rectangle's dimensions as a
54
QSize. The dimensions can also be retrieved separately using the
55
width() and height() functions. To manipulate the dimensions use
56
the setSize(), setWidth() or setHeight() functions. Alternatively,
57
the size can be changed by applying either of the functions
58
setting the rectangle coordinates, for example, setBottom() or
59
setRight().
60
61
The contains() function tells whether a given point is inside the
62
rectangle or not, and the intersects() function returns \c true if
63
this rectangle intersects with a given rectangle. The QRect class
64
also provides the intersected() function which returns the
65
intersection rectangle, and the united() function which returns the
66
rectangle that encloses the given rectangle and this:
67
68
\table
69
\row
70
\li \inlineimage qrect-intersect.svg {Diagram showing intersection
71
of two rectangles r and s with the overlapping area
72
highlighted. It's also showing how the width and
73
height of the highlighted area is determined with
74
r.intersect(s).width() and r.intersect(s).height().}
75
\li \inlineimage qrect-unite.svg {Diagram showing two overlapped
76
rectangles r and s and their united size which is
77
determined with r.united(s).width() and
78
r.united(s).height().}
79
\row
80
\li intersected()
81
\li united()
82
\endtable
83
84
The isEmpty() function returns \c true if left() > right() or top() >
85
bottom(). Note that an empty rectangle is not valid: The isValid()
86
function returns \c true if left() <= right() \e and top() <=
87
bottom(). A null rectangle (isNull() == true) on the other hand,
88
has both width and height set to 0.
89
90
Note that due to the way QRect and QRectF are defined, an
91
empty QRect is defined in essentially the same way as QRectF.
92
93
Finally, QRect objects can be streamed as well as compared.
94
95
\section1 Rendering
96
97
When using an \l {QPainter::Antialiasing}{anti-aliased} painter,
98
the boundary line of a QRect will be rendered symmetrically on
99
both sides of the mathematical rectangle's boundary line. But when
100
using an aliased painter (the default) other rules apply.
101
102
Then, when rendering with a one pixel wide pen the QRect's boundary
103
line will be rendered to the right and below the mathematical
104
rectangle's boundary line.
105
106
When rendering with a two pixels wide pen the boundary line will
107
be split in the middle by the mathematical rectangle. This will be
108
the case whenever the pen is set to an even number of pixels,
109
while rendering with a pen with an odd number of pixels, the spare
110
pixel will be rendered to the right and below the mathematical
111
rectangle as in the one pixel case.
112
113
\table
114
\row
115
\li \inlineimage qrect-diagram-zero.svg
116
{Rectangle showing width and height dimensions}
117
\li \inlineimage qrect-diagram-one.svg
118
{Rectangle with one-pixel pen showing corner coordinates}
119
\row
120
\li Logical representation
121
\li One pixel wide pen
122
\row
123
\li \inlineimage qrect-diagram-two.svg
124
{Rectangle with two-pixel pen showing corner coordinates}
125
\li \inlineimage qrect-diagram-three.svg
126
{Rectangle with three-pixel pen showing corner coordinates}
127
\row
128
\li Two pixel wide pen
129
\li Three pixel wide pen
130
\endtable
131
132
\section1 Coordinates
133
134
The QRect class provides a collection of functions that return the
135
various rectangle coordinates, and enable manipulation of
136
these. QRect also provides functions to move the rectangle relative
137
to the various coordinates.
138
139
For example the left(), setLeft() and moveLeft() functions as an
140
example: left() returns the x-coordinate of the rectangle's left
141
edge, setLeft() sets the left edge of the rectangle to the given x
142
coordinate (it may change the width, but will never change the
143
rectangle's right edge) and moveLeft() moves the entire rectangle
144
horizontally, leaving the rectangle's left edge at the given x
145
coordinate and its size unchanged.
146
147
\image qrect-coordinates.svg {Diagram of a rectangle showing QRect
148
methods for positions: x(), y(), center(), corners (topLeft(),
149
topRight(), bottomLeft(), bottomRight()), and edges (top(),
150
bottom(), left(), right()).}
151
152
Note that for historical reasons the values returned by the
153
bottom() and right() functions deviate from the true bottom-right
154
corner of the rectangle: The right() function returns \e { left()
155
+ width() - 1} and the bottom() function returns \e {top() +
156
height() - 1}. The same is the case for the point returned by the
157
bottomRight() convenience function. In addition, the x and y
158
coordinate of the topRight() and bottomLeft() functions,
159
respectively, contain the same deviation from the true right and
160
bottom edges.
161
162
We recommend that you use x() + width() and y() + height() to find
163
the true bottom-right corner, and avoid right() and
164
bottom(). Another solution is to use QRectF: The QRectF class
165
defines a rectangle in the plane using floating point accuracy for
166
coordinates, and the QRectF::right() and QRectF::bottom()
167
functions \e do return the right and bottom coordinates.
168
169
It is also possible to add offsets to this rectangle's coordinates
170
using the adjust() function, as well as retrieve a new rectangle
171
based on adjustments of the original one using the adjusted()
172
function. If either of the width and height is negative, use the
173
normalized() function to retrieve a rectangle where the corners
174
are swapped.
175
176
In addition, QRect provides the getCoords() function which extracts
177
the position of the rectangle's top-left and bottom-right corner,
178
and the getRect() function which extracts the rectangle's top-left
179
corner, width and height. Use the setCoords() and setRect()
180
function to manipulate the rectangle's coordinates and dimensions
181
in one go.
182
183
\section1 Constraints
184
185
QRect is limited to the minimum and maximum values for the \c int type.
186
Operations on a QRect that could potentially result in values outside this
187
range will result in undefined behavior.
188
189
\sa QRectF, QRegion
190
*/
191
192
/*****************************************************************************
193
QRect member functions
194
*****************************************************************************/
195
196
/*!
197
\fn QRect::QRect()
198
199
Constructs a null rectangle.
200
201
\sa isNull()
202
*/
203
204
/*!
205
\fn QRect::QRect(const QPoint &topLeft, const QPoint &bottomRight)
206
207
Constructs a rectangle with the given \a topLeft and \a bottomRight corners, both included.
208
209
If \a bottomRight is to higher and to the left of \a topLeft, the rectangle defined
210
is instead non-inclusive of the corners.
211
212
\note To ensure both points are included regardless of relative order, use span().
213
214
\sa setTopLeft(), setBottomRight(), span()
215
*/
216
217
218
/*!
219
\fn QRect::QRect(const QPoint &topLeft, const QSize &size)
220
221
Constructs a rectangle with the given \a topLeft corner and the
222
given \a size.
223
224
\sa setTopLeft(), setSize()
225
*/
226
227
228
/*!
229
\fn QRect::QRect(int x, int y, int width, int height)
230
231
Constructs a rectangle with (\a x, \a y) as its top-left corner
232
and the given \a width and \a height.
233
234
\sa setRect()
235
*/
236
237
238
/*!
239
\fn bool QRect::isNull() const
240
241
Returns \c true if the rectangle is a null rectangle, otherwise
242
returns \c false.
243
244
A null rectangle has both the width and the height set to 0 (i.e.,
245
right() == left() - 1 and bottom() == top() - 1). A null rectangle
246
is also empty, and hence is not valid.
247
248
\sa isEmpty(), isValid()
249
*/
250
251
/*!
252
\fn bool QRect::isEmpty() const
253
254
Returns \c true if the rectangle is empty, otherwise returns \c false.
255
256
An empty rectangle has a left() > right() or top() > bottom(). An
257
empty rectangle is not valid (i.e., isEmpty() == !isValid()).
258
259
Use the normalized() function to retrieve a rectangle where the
260
corners are swapped.
261
262
\sa isNull(), isValid(), normalized()
263
*/
264
265
/*!
266
\fn bool QRect::isValid() const
267
268
Returns \c true if the rectangle is valid, otherwise returns \c false.
269
270
A valid rectangle has a left() <= right() and top() <=
271
bottom(). Note that non-trivial operations like intersections are
272
not defined for invalid rectangles. A valid rectangle is not empty
273
(i.e., isValid() == !isEmpty()).
274
275
\sa isNull(), isEmpty(), normalized()
276
*/
277
278
279
/*!
280
Returns a normalized rectangle; i.e., a rectangle that has a
281
non-negative width and height.
282
283
If width() < 0 the function swaps the left and right corners, and
284
it swaps the top and bottom corners if height() < 0. The corners
285
are at the same time changed from being non-inclusive to inclusive.
286
287
\sa isValid(), isEmpty()
288
*/
289
290
QRect QRect::normalized()
const
noexcept
291
{
292
QRect r(*
this
);
293
if
(x2 < x1) {
// swap bad x values
294
r.x1 = x2 + 1;
295
r.x2 = x1 - 1;
296
}
297
if
(y2 < y1) {
// swap bad y values
298
r.y1 = y2 + 1;
299
r.y2 = y1 - 1;
300
}
301
return
r;
302
}
303
304
305
/*!
306
\fn int QRect::left() const
307
308
Returns the x-coordinate of the rectangle's left edge. Equivalent
309
to x().
310
311
\sa setLeft(), topLeft(), bottomLeft()
312
*/
313
314
/*!
315
\fn int QRect::top() const
316
317
Returns the y-coordinate of the rectangle's top edge.
318
Equivalent to y().
319
320
\sa setTop(), topLeft(), topRight()
321
*/
322
323
/*!
324
\fn int QRect::right() const
325
326
Returns the x-coordinate of the rectangle's right edge.
327
328
Note that for historical reasons this function returns left() +
329
width() - 1; use x() + width() to retrieve the true x-coordinate.
330
331
\sa setRight(), topRight(), bottomRight()
332
*/
333
334
/*!
335
\fn int QRect::bottom() const
336
337
Returns the y-coordinate of the rectangle's bottom edge.
338
339
Note that for historical reasons this function returns top() +
340
height() - 1; use y() + height() to retrieve the true y-coordinate.
341
342
\sa setBottom(), bottomLeft(), bottomRight()
343
*/
344
345
/*!
346
\fn int QRect::x() const
347
348
Returns the x-coordinate of the rectangle's left edge. Equivalent to left().
349
350
\sa setX(), y(), topLeft()
351
*/
352
353
/*!
354
\fn int QRect::y() const
355
356
Returns the y-coordinate of the rectangle's top edge. Equivalent to top().
357
358
\sa setY(), x(), topLeft()
359
*/
360
361
/*!
362
\fn void QRect::setLeft(int x)
363
364
Sets the left edge of the rectangle to the given \a x
365
coordinate. May change the width, but will never change the right
366
edge of the rectangle.
367
368
Equivalent to setX().
369
370
\sa left(), moveLeft()
371
*/
372
373
/*!
374
\fn void QRect::setTop(int y)
375
376
Sets the top edge of the rectangle to the given \a y
377
coordinate. May change the height, but will never change the
378
bottom edge of the rectangle.
379
380
Equivalent to setY().
381
382
\sa top(), moveTop()
383
*/
384
385
/*!
386
\fn void QRect::setRight(int x)
387
388
Sets the right edge of the rectangle to the given \a x
389
coordinate. May change the width, but will never change the left
390
edge of the rectangle.
391
392
\sa right(), moveRight()
393
*/
394
395
/*!
396
\fn void QRect::setBottom(int y)
397
398
Sets the bottom edge of the rectangle to the given \a y
399
coordinate. May change the height, but will never change the top
400
edge of the rectangle.
401
402
\sa bottom(), moveBottom(),
403
*/
404
405
/*!
406
\fn void QRect::setX(int x)
407
408
Sets the left edge of the rectangle to the given \a x
409
coordinate. May change the width, but will never change the right
410
edge of the rectangle.
411
412
Equivalent to setLeft().
413
414
\sa x(), setY(), setTopLeft()
415
*/
416
417
/*!
418
\fn void QRect::setY(int y)
419
420
Sets the top edge of the rectangle to the given \a y
421
coordinate. May change the height, but will never change the
422
bottom edge of the rectangle.
423
424
Equivalent to setTop().
425
426
\sa y(), setX(), setTopLeft()
427
*/
428
429
/*!
430
\fn void QRect::setTopLeft(const QPoint &position)
431
432
Set the top-left corner of the rectangle to the given \a
433
position. May change the size, but will never change the
434
bottom-right corner of the rectangle.
435
436
\sa topLeft(), moveTopLeft()
437
*/
438
439
/*!
440
\fn void QRect::setBottomRight(const QPoint &position)
441
442
Set the bottom-right corner of the rectangle to the given \a
443
position. May change the size, but will never change the
444
top-left corner of the rectangle.
445
446
\sa bottomRight(), moveBottomRight()
447
*/
448
449
/*!
450
\fn void QRect::setTopRight(const QPoint &position)
451
452
Set the top-right corner of the rectangle to the given \a
453
position. May change the size, but will never change the
454
bottom-left corner of the rectangle.
455
456
\sa topRight(), moveTopRight()
457
*/
458
459
/*!
460
\fn void QRect::setBottomLeft(const QPoint &position)
461
462
Set the bottom-left corner of the rectangle to the given \a
463
position. May change the size, but will never change the
464
top-right corner of the rectangle.
465
466
\sa bottomLeft(), moveBottomLeft()
467
*/
468
469
/*!
470
\fn QPoint QRect::topLeft() const
471
472
Returns the position of the rectangle's top-left corner.
473
474
\sa setTopLeft(), top(), left()
475
*/
476
477
/*!
478
\fn QPoint QRect::bottomRight() const
479
480
Returns the position of the rectangle's bottom-right corner.
481
482
Note that for historical reasons this function returns
483
QPoint(left() + width() -1, top() + height() - 1).
484
485
\sa setBottomRight(), bottom(), right()
486
*/
487
488
/*!
489
\fn QPoint QRect::topRight() const
490
491
Returns the position of the rectangle's top-right corner.
492
493
Note that for historical reasons this function returns
494
QPoint(left() + width() -1, top()).
495
496
\sa setTopRight(), top(), right()
497
*/
498
499
/*!
500
\fn QPoint QRect::bottomLeft() const
501
502
Returns the position of the rectangle's bottom-left corner. Note
503
that for historical reasons this function returns QPoint(left(),
504
top() + height() - 1).
505
506
\sa setBottomLeft(), bottom(), left()
507
*/
508
509
/*!
510
\fn QPoint QRect::center() const
511
512
Returns the center point of the rectangle.
513
514
\sa moveCenter()
515
*/
516
517
518
/*!
519
\fn void QRect::getRect(int *x, int *y, int *width, int *height) const
520
521
Extracts the position of the rectangle's top-left corner to *\a x
522
and *\a y, and its dimensions to *\a width and *\a height.
523
524
\sa setRect(), getCoords()
525
*/
526
527
528
/*!
529
\fn void QRect::getCoords(int *x1, int *y1, int *x2, int *y2) const
530
531
Extracts the position of the rectangle's top-left corner to *\a x1
532
and *\a y1, and the position of the bottom-right corner to *\a x2
533
and *\a y2.
534
535
\sa setCoords(), getRect()
536
*/
537
538
/*!
539
\fn void QRect::moveLeft(int x)
540
541
Moves the rectangle horizontally, leaving the rectangle's left
542
edge at the given \a x coordinate. The rectangle's size is
543
unchanged.
544
545
\sa left(), setLeft(), moveRight()
546
*/
547
548
/*!
549
\fn void QRect::moveTop(int y)
550
551
Moves the rectangle vertically, leaving the rectangle's top edge
552
at the given \a y coordinate. The rectangle's size is unchanged.
553
554
\sa top(), setTop(), moveBottom()
555
*/
556
557
558
/*!
559
\fn void QRect::moveRight(int x)
560
561
Moves the rectangle horizontally, leaving the rectangle's right
562
edge at the given \a x coordinate. The rectangle's size is
563
unchanged.
564
565
\sa right(), setRight(), moveLeft()
566
*/
567
568
569
/*!
570
\fn void QRect::moveBottom(int y)
571
572
Moves the rectangle vertically, leaving the rectangle's bottom
573
edge at the given \a y coordinate. The rectangle's size is
574
unchanged.
575
576
\sa bottom(), setBottom(), moveTop()
577
*/
578
579
580
/*!
581
\fn void QRect::moveTopLeft(const QPoint &position)
582
583
Moves the rectangle, leaving the top-left corner at the given \a
584
position. The rectangle's size is unchanged.
585
586
\sa setTopLeft(), moveTop(), moveLeft()
587
*/
588
589
590
/*!
591
\fn void QRect::moveBottomRight(const QPoint &position)
592
593
Moves the rectangle, leaving the bottom-right corner at the given
594
\a position. The rectangle's size is unchanged.
595
596
\sa setBottomRight(), moveRight(), moveBottom()
597
*/
598
599
600
/*!
601
\fn void QRect::moveTopRight(const QPoint &position)
602
603
Moves the rectangle, leaving the top-right corner at the given \a
604
position. The rectangle's size is unchanged.
605
606
\sa setTopRight(), moveTop(), moveRight()
607
*/
608
609
610
/*!
611
\fn void QRect::moveBottomLeft(const QPoint &position)
612
613
Moves the rectangle, leaving the bottom-left corner at the given
614
\a position. The rectangle's size is unchanged.
615
616
\sa setBottomLeft(), moveBottom(), moveLeft()
617
*/
618
619
620
/*!
621
\fn void QRect::moveCenter(const QPoint &position)
622
623
Moves the rectangle, leaving the center point at the given \a
624
position. The rectangle's size is unchanged.
625
626
\sa center()
627
*/
628
629
/*!
630
\fn void QRect::moveTo(int x, int y)
631
632
Moves the rectangle, leaving the top-left corner at the given
633
position (\a x, \a y). The rectangle's size is unchanged.
634
635
\sa translate(), moveTopLeft()
636
*/
637
638
/*!
639
\fn void QRect::moveTo(const QPoint &position)
640
641
Moves the rectangle, leaving the top-left corner at the given \a
642
position.
643
*/
644
645
/*!
646
\fn void QRect::translate(int dx, int dy)
647
648
Moves the rectangle \a dx along the x axis and \a dy along the y
649
axis, relative to the current position. Positive values move the
650
rectangle to the right and down.
651
652
\sa moveTopLeft(), moveTo(), translated()
653
*/
654
655
656
/*!
657
\fn void QRect::translate(const QPoint &offset)
658
\overload
659
660
Moves the rectangle \a{offset}.\l{QPoint::x()}{x()} along the x
661
axis and \a{offset}.\l{QPoint::y()}{y()} along the y axis,
662
relative to the current position.
663
*/
664
665
666
/*!
667
\fn QRect QRect::translated(int dx, int dy) const
668
669
Returns a copy of the rectangle that is translated \a dx along the
670
x axis and \a dy along the y axis, relative to the current
671
position. Positive values move the rectangle to the right and
672
down.
673
674
\sa translate()
675
676
*/
677
678
679
/*!
680
\fn QRect QRect::translated(const QPoint &offset) const
681
682
\overload
683
684
Returns a copy of the rectangle that is translated
685
\a{offset}.\l{QPoint::x()}{x()} along the x axis and
686
\a{offset}.\l{QPoint::y()}{y()} along the y axis, relative to the
687
current position.
688
*/
689
690
/*!
691
\fn QRect QRect::transposed() const
692
\since 5.7
693
694
Returns a copy of the rectangle that has its width and height
695
exchanged:
696
697
\snippet code/src_corelib_tools_qrect.cpp 2
698
699
\sa QSize::transposed()
700
*/
701
702
/*!
703
\fn void QRect::setRect(int x, int y, int width, int height)
704
705
Sets the coordinates of the rectangle's top-left corner to (\a{x},
706
\a{y}), and its size to the given \a width and \a height.
707
708
\sa getRect(), setCoords()
709
*/
710
711
712
/*!
713
\fn void QRect::setCoords(int x1, int y1, int x2, int y2)
714
715
Sets the coordinates of the rectangle's top-left corner to (\a x1,
716
\a y1), and the coordinates of its bottom-right corner to (\a x2,
717
\a y2).
718
719
\sa getCoords(), setRect()
720
*/
721
722
723
/*! \fn QRect QRect::adjusted(int dx1, int dy1, int dx2, int dy2) const
724
725
Returns a new rectangle with \a dx1, \a dy1, \a dx2 and \a dy2
726
added respectively to the existing coordinates of this rectangle.
727
728
\sa adjust()
729
*/
730
731
/*! \fn void QRect::adjust(int dx1, int dy1, int dx2, int dy2)
732
733
Adds \a dx1, \a dy1, \a dx2 and \a dy2 respectively to the
734
existing coordinates of the rectangle.
735
736
\sa adjusted(), setRect()
737
*/
738
739
/*!
740
\fn QSize QRect::size() const
741
742
Returns the size of the rectangle.
743
744
\sa setSize(), width(), height()
745
*/
746
747
/*!
748
\fn int QRect::width() const
749
750
Returns the width of the rectangle.
751
752
\sa setWidth(), height(), size()
753
*/
754
755
/*!
756
\fn int QRect::height() const
757
758
Returns the height of the rectangle.
759
760
\sa setHeight(), width(), size()
761
*/
762
763
/*!
764
\fn void QRect::setWidth(int width)
765
766
Sets the width of the rectangle to the given \a width. The right
767
edge is changed, but not the left one.
768
769
\sa width(), setSize()
770
*/
771
772
773
/*!
774
\fn void QRect::setHeight(int height)
775
776
Sets the height of the rectangle to the given \a height. The bottom
777
edge is changed, but not the top one.
778
779
\sa height(), setSize()
780
*/
781
782
783
/*!
784
\fn void QRect::setSize(const QSize &size)
785
786
Sets the size of the rectangle to the given \a size. The top-left
787
corner is not moved.
788
789
\sa size(), setWidth(), setHeight()
790
*/
791
792
793
/*!
794
\fn bool QRect::contains(const QPoint &point, bool proper) const
795
796
Returns \c true if the given \a point is inside or on the edge of
797
the rectangle, otherwise returns \c false. If \a proper is true, this
798
function only returns \c true if the given \a point is \e inside the
799
rectangle (i.e., not on the edge).
800
801
\sa intersects()
802
*/
803
804
bool
QRect::contains(
const
QPoint &p,
bool
proper)
const
noexcept
805
{
806
Representation l, r;
807
if
(x2 < x1 - 1) {
808
l = x2 + 1;
809
r = x1 - 1;
810
}
else
{
811
l = x1;
812
r = x2;
813
}
814
if
(proper) {
815
if
(p.x() <= l || p.x() >= r)
816
return
false
;
817
}
else
{
818
if
(p.x() < l || p.x() > r)
819
return
false
;
820
}
821
Representation t, b;
822
if
(y2 < y1 - 1) {
823
t = y2 + 1;
824
b = y1 - 1;
825
}
else
{
826
t = y1;
827
b = y2;
828
}
829
if
(proper) {
830
if
(p.y() <= t || p.y() >= b)
831
return
false
;
832
}
else
{
833
if
(p.y() < t || p.y() > b)
834
return
false
;
835
}
836
return
true
;
837
}
838
839
840
/*!
841
\fn bool QRect::contains(int x, int y, bool proper) const
842
\overload
843
844
Returns \c true if the point (\a x, \a y) is inside or on the edge of
845
the rectangle, otherwise returns \c false. If \a proper is true, this
846
function only returns \c true if the point is entirely inside the
847
rectangle(not on the edge).
848
*/
849
850
/*!
851
\fn bool QRect::contains(int x, int y) const
852
\overload
853
854
Returns \c true if the point (\a x, \a y) is inside this rectangle,
855
otherwise returns \c false.
856
*/
857
858
/*!
859
\fn bool QRect::contains(const QRect &rectangle, bool proper) const
860
\overload
861
862
Returns \c true if the given \a rectangle is inside this rectangle.
863
otherwise returns \c false. If \a proper is true, this function only
864
returns \c true if the \a rectangle is entirely inside this
865
rectangle (not on the edge).
866
*/
867
868
bool
QRect::contains(
const
QRect &r,
bool
proper)
const
noexcept
869
{
870
if
(isNull() || r.isNull())
871
return
false
;
872
873
Representation l1 = x1;
874
Representation r1 = x1 - 1;
875
if
(x2 < x1 - 1)
876
l1 = x2 + 1;
877
else
878
r1 = x2;
879
880
Representation l2 = r.x1;
881
Representation r2 = r.x1 - 1;
882
if
(r.x2 < r.x1 - 1)
883
l2 = r.x2 + 1;
884
else
885
r2 = r.x2;
886
887
if
(proper) {
888
if
(l2 <= l1 || r2 >= r1)
889
return
false
;
890
}
else
{
891
if
(l2 < l1 || r2 > r1)
892
return
false
;
893
}
894
895
Representation t1 = y1;
896
Representation b1 = y1 - 1;
897
if
(y2 < y1 - 1)
898
t1 = y2 + 1;
899
else
900
b1 = y2;
901
902
Representation t2 = r.y1;
903
Representation b2 = r.y1 - 1;
904
if
(r.y2 < r.y1 - 1)
905
t2 = r.y2 + 1;
906
else
907
b2 = r.y2;
908
909
if
(proper) {
910
if
(t2 <= t1 || b2 >= b1)
911
return
false
;
912
}
else
{
913
if
(t2 < t1 || b2 > b1)
914
return
false
;
915
}
916
917
return
true
;
918
}
919
920
/*!
921
\fn QRect& QRect::operator|=(const QRect &rectangle)
922
923
Unites this rectangle with the given \a rectangle.
924
925
\sa united(), operator|()
926
*/
927
928
/*!
929
\fn QRect& QRect::operator&=(const QRect &rectangle)
930
931
Intersects this rectangle with the given \a rectangle.
932
933
\sa intersected(), operator&()
934
*/
935
936
937
/*!
938
\fn QRect QRect::operator|(const QRect &rectangle) const
939
940
Returns the bounding rectangle of this rectangle and the given \a
941
rectangle.
942
943
\sa operator|=(), united()
944
*/
945
946
QRect QRect::operator|(
const
QRect &r)
const
noexcept
947
{
948
if
(isNull())
949
return
r;
950
if
(r.isNull())
951
return
*
this
;
952
953
Representation l1 = x1;
954
Representation r1 = x1 - 1;
955
if
(x2 < x1 - 1)
956
l1 = x2 + 1;
957
else
958
r1 = x2;
959
960
Representation l2 = r.x1;
961
Representation r2 = r.x1 - 1;
962
if
(r.x2 < r.x1 - 1)
963
l2 = r.x2 + 1;
964
else
965
r2 = r.x2;
966
967
Representation t1 = y1;
968
Representation b1 = y1 - 1;
969
if
(y2 < y1 - 1)
970
t1 = y2 + 1;
971
else
972
b1 = y2;
973
974
Representation t2 = r.y1;
975
Representation b2 = r.y1 - 1;
976
if
(r.y2 < r.y1 - 1)
977
t2 = r.y2 + 1;
978
else
979
b2 = r.y2;
980
981
QRect tmp;
982
tmp.x1 = qMin(l1, l2);
983
tmp.x2 = qMax(r1, r2);
984
tmp.y1 = qMin(t1, t2);
985
tmp.y2 = qMax(b1, b2);
986
return
tmp;
987
}
988
989
/*!
990
\fn QRect QRect::united(const QRect &rectangle) const
991
\since 4.2
992
993
Returns the bounding rectangle of this rectangle and the given \a rectangle.
994
995
\image qrect-unite.svg {Diagram showing two overlapped rectangles r and s
996
and their united size which is determined with r.united(s).width and
997
r.united(s).height().}
998
999
\sa intersected()
1000
*/
1001
1002
1003
/*!
1004
\fn QRect QRect::operator&(const QRect &rectangle) const
1005
1006
Returns the intersection of this rectangle and the given \a
1007
rectangle. Returns an empty rectangle if there is no intersection.
1008
1009
\sa operator&=(), intersected()
1010
*/
1011
1012
QRect QRect::operator&(
const
QRect &r)
const
noexcept
1013
{
1014
if
(isNull() || r.isNull())
1015
return
QRect();
1016
1017
Representation l1 = x1;
1018
Representation r1 = x2;
1019
if
(x2 < x1 - 1) {
1020
l1 = x2 + 1;
1021
r1 = x1 - 1;
1022
}
1023
1024
Representation l2 = r.x1;
1025
Representation r2 = r.x2;
1026
if
(r.x2 < r.x1 - 1) {
1027
l2 = r.x2 + 1;
1028
r2 = r.x1 - 1;
1029
}
1030
1031
if
(l1 > r2 || l2 > r1)
1032
return
QRect();
1033
1034
Representation t1 = y1;
1035
Representation b1 = y2;
1036
if
(y2 < y1 - 1) {
1037
t1 = y2 + 1;
1038
b1 = y1 - 1;
1039
}
1040
1041
Representation t2 = r.y1;
1042
Representation b2 = r.y2;
1043
if
(r.y2 < r.y1 - 1) {
1044
t2 = r.y2 + 1;
1045
b2 = r.y1 - 1;
1046
}
1047
1048
if
(t1 > b2 || t2 > b1)
1049
return
QRect();
1050
1051
QRect tmp;
1052
tmp.x1 = qMax(l1, l2);
1053
tmp.x2 = qMin(r1, r2);
1054
tmp.y1 = qMax(t1, t2);
1055
tmp.y2 = qMin(b1, b2);
1056
return
tmp;
1057
}
1058
1059
/*!
1060
\fn QRect QRect::intersected(const QRect &rectangle) const
1061
\since 4.2
1062
1063
Returns the intersection of this rectangle and the given \a
1064
rectangle. Note that \c{r.intersected(s)} is equivalent to \c{r & s}.
1065
1066
\image qrect-intersect.svg {Diagram showing intersection of two
1067
rectangles r and s with the overlapping area highlighted.
1068
It also shows how the width and height of the highlighted area
1069
is determined with r.intersect(s).width and
1070
r.intersect(s).height().}
1071
1072
\sa intersects(), united(), operator&=()
1073
*/
1074
1075
/*!
1076
\fn bool QRect::intersects(const QRect &rectangle) const
1077
1078
Returns \c true if this rectangle intersects with the given \a
1079
rectangle (i.e., there is at least one pixel that is within both
1080
rectangles), otherwise returns \c false.
1081
1082
The intersection rectangle can be retrieved using the intersected()
1083
function.
1084
1085
\sa contains()
1086
*/
1087
1088
bool
QRect::intersects(
const
QRect &r)
const
noexcept
1089
{
1090
if
(isNull() || r.isNull())
1091
return
false
;
1092
1093
Representation l1 = x1;
1094
Representation r1 = x2;
1095
if
(x2 < x1 - 1) {
1096
l1 = x2 + 1;
1097
r1 = x1 - 1;
1098
}
1099
1100
Representation l2 = r.x1;
1101
Representation r2 = r.x2;
1102
if
(r.x2 < r.x1 - 1) {
1103
l2 = r.x2 + 1;
1104
r2 = r.x1 - 1;
1105
}
1106
1107
if
(l1 > r2 || l2 > r1)
1108
return
false
;
1109
1110
Representation t1 = y1;
1111
Representation b1 = y2;
1112
if
(y2 < y1 - 1) {
1113
t1 = y2 + 1;
1114
b1 = y1 - 1;
1115
}
1116
1117
Representation t2 = r.y1;
1118
Representation b2 = r.y2;
1119
if
(r.y2 < r.y1 - 1) {
1120
t2 = r.y2 + 1;
1121
b2 = r.y1 - 1;
1122
}
1123
1124
if
(t1 > b2 || t2 > b1)
1125
return
false
;
1126
1127
return
true
;
1128
}
1129
1130
/*!
1131
\fn bool QRect::operator==(const QRect &lhs, const QRect &rhs)
1132
1133
Returns \c true if the rectangles \a lhs and \a rhs are equal,
1134
otherwise returns \c false.
1135
*/
1136
1137
1138
/*!
1139
\fn bool QRect::operator!=(const QRect &lhs, const QRect &rhs)
1140
1141
Returns \c true if the rectangles \a lhs and \a rhs are different,
1142
otherwise returns \c false.
1143
*/
1144
1145
/*!
1146
\fn QRect operator+(const QRect &rectangle, const QMargins &margins)
1147
\relates QRect
1148
1149
Returns the \a rectangle grown by the \a margins.
1150
1151
\since 5.1
1152
*/
1153
1154
/*!
1155
\fn QRect operator+(const QMargins &margins, const QRect &rectangle)
1156
\relates QRect
1157
\overload
1158
1159
Returns the \a rectangle grown by the \a margins.
1160
1161
\since 5.1
1162
*/
1163
1164
/*!
1165
\fn QRect operator-(const QRect &lhs, const QMargins &rhs)
1166
\relates QRect
1167
1168
Returns the \a lhs rectangle shrunk by the \a rhs margins.
1169
1170
\since 5.3
1171
*/
1172
1173
/*!
1174
\fn QRect QRect::marginsAdded(const QMargins &margins) const
1175
1176
Returns a rectangle grown by the \a margins.
1177
1178
\sa operator+=(), marginsRemoved(), operator-=()
1179
1180
\since 5.1
1181
*/
1182
1183
/*!
1184
\fn QRect QRect::operator+=(const QMargins &margins)
1185
1186
Adds the \a margins to the rectangle, growing it.
1187
1188
\sa marginsAdded(), marginsRemoved(), operator-=()
1189
1190
\since 5.1
1191
*/
1192
1193
/*!
1194
\fn QRect QRect::marginsRemoved(const QMargins &margins) const
1195
1196
Removes the \a margins from the rectangle, shrinking it.
1197
1198
\sa marginsAdded(), operator+=(), operator-=()
1199
1200
\since 5.1
1201
*/
1202
1203
/*!
1204
\fn QRect QRect::operator -=(const QMargins &margins)
1205
1206
Returns a rectangle shrunk by the \a margins.
1207
1208
\sa marginsRemoved(), operator+=(), marginsAdded()
1209
1210
\since 5.1
1211
*/
1212
1213
/*!
1214
\fn static QRect QRect::span(const QPoint &p1, const QPoint &p2)
1215
1216
Returns a rectangle spanning the two points \a p1 and \a p2, including both and
1217
everything in between.
1218
1219
\since 6.0
1220
*/
1221
1222
/*!
1223
\fn QRect::toRectF() const
1224
\since 6.4
1225
1226
Returns this rectangle as a rectangle with floating point accuracy.
1227
1228
\note This function, like the QRectF(QRect) constructor, preserves the
1229
size() of the rectangle, not its bottomRight() corner.
1230
1231
\sa QRectF::toRect()
1232
*/
1233
1234
/*****************************************************************************
1235
QRect stream functions
1236
*****************************************************************************/
1237
#
ifndef
QT_NO_DATASTREAM
1238
/*!
1239
\fn QDataStream &operator<<(QDataStream &stream, const QRect &rectangle)
1240
\relates QRect
1241
1242
Writes the given \a rectangle to the given \a stream, and returns
1243
a reference to the stream.
1244
1245
\sa {Serializing Qt Data Types}
1246
*/
1247
1248
QDataStream &operator<<(QDataStream &s,
const
QRect &r)
1249
{
1250
if
(s.version() == 1)
1251
s << (qint16)r.left() << (qint16)r.top()
1252
<< (qint16)r.right() << (qint16)r.bottom();
1253
else
1254
s << (qint32)r.left() << (qint32)r.top()
1255
<< (qint32)r.right() << (qint32)r.bottom();
1256
return
s;
1257
}
1258
1259
/*!
1260
\fn QDataStream &operator>>(QDataStream &stream, QRect &rectangle)
1261
\relates QRect
1262
1263
Reads a rectangle from the given \a stream into the given \a
1264
rectangle, and returns a reference to the stream.
1265
1266
\sa {Serializing Qt Data Types}
1267
*/
1268
1269
QDataStream &
operator
>>(QDataStream &s, QRect &r)
1270
{
1271
if
(s.version() == 1) {
1272
qint16 x1, y1, x2, y2;
1273
s >> x1; s >> y1; s >> x2; s >> y2;
1274
r.setCoords(x1, y1, x2, y2);
1275
}
1276
else
{
1277
qint32 x1, y1, x2, y2;
1278
s >> x1; s >> y1; s >> x2; s >> y2;
1279
r.setCoords(x1, y1, x2, y2);
1280
}
1281
return
s;
1282
}
1283
1284
#
endif
// QT_NO_DATASTREAM
1285
1286
1287
#
ifndef
QT_NO_DEBUG_STREAM
1288
QDebug
operator
<<(QDebug dbg,
const
QRect &r)
1289
{
1290
QDebugStateSaver saver(dbg);
1291
dbg.nospace();
1292
dbg <<
"QRect"
<<
'('
;
1293
QtDebugUtils::formatQRect(dbg, r);
1294
dbg <<
')'
;
1295
return
dbg;
1296
}
1297
#
endif
1298
1299
/*!
1300
\class QRectF
1301
\inmodule QtCore
1302
\ingroup painting
1303
\reentrant
1304
1305
\compares equality
1306
\compareswith equality QRect
1307
\endcompareswith
1308
1309
\brief The QRectF class defines a finite rectangle in the plane using
1310
floating point precision.
1311
1312
A rectangle is normally expressed as a top-left corner and a
1313
size. The size (width and height) of a QRectF is always equivalent
1314
to the mathematical rectangle that forms the basis for its
1315
rendering.
1316
1317
A QRectF can be constructed with a set of left, top, width and
1318
height coordinates, or from a QPointF and a QSizeF. The following
1319
code creates two identical rectangles.
1320
1321
\snippet code/src_corelib_tools_qrect.cpp 1
1322
1323
There is also a third constructor creating a QRectF from a QRect,
1324
and a corresponding toRect() function that returns a QRect object
1325
based on the values of this rectangle (note that the coordinates
1326
in the returned rectangle are rounded to the nearest integer).
1327
1328
The QRectF class provides a collection of functions that return
1329
the various rectangle coordinates, and enable manipulation of
1330
these. QRectF also provides functions to move the rectangle
1331
relative to the various coordinates. In addition there is a
1332
moveTo() function that moves the rectangle, leaving its top left
1333
corner at the given coordinates. Alternatively, the translate()
1334
function moves the rectangle the given offset relative to the
1335
current position, and the translated() function returns a
1336
translated copy of this rectangle.
1337
1338
The size() function returns the rectangle's dimensions as a
1339
QSizeF. The dimensions can also be retrieved separately using the
1340
width() and height() functions. To manipulate the dimensions use
1341
the setSize(), setWidth() or setHeight() functions. Alternatively,
1342
the size can be changed by applying either of the functions
1343
setting the rectangle coordinates, for example, setBottom() or
1344
setRight().
1345
1346
The contains() function tells whether a given point is inside the
1347
rectangle or not, and the intersects() function returns \c true if
1348
this rectangle intersects with a given rectangle (otherwise
1349
false). The QRectF class also provides the intersected() function
1350
which returns the intersection rectangle, and the united() function
1351
which returns the rectangle that encloses the given rectangle and
1352
this:
1353
1354
\table
1355
\row
1356
\li \inlineimage qrect-intersect.svg {Diagram showing intersection
1357
of two rectangles r and s with the overlapping area
1358
highlighted. It's also showing how the width and
1359
height of the highlighted area is determined with
1360
r.intersect(s).width and r.intersect(s).height().}
1361
\li \inlineimage qrect-unite.svg {Diagram showing two overlapped
1362
rectangles r and s and their united size which is
1363
determined with r.united(s).width and
1364
r.united(s).height()}
1365
\row
1366
\li intersected()
1367
\li united()
1368
\endtable
1369
1370
The isEmpty() function returns \c true if the rectangle's width or
1371
height is less than, or equal to, 0. Note that an empty rectangle
1372
is not valid: The isValid() function returns \c true if both width
1373
and height is larger than 0. A null rectangle (isNull() == true)
1374
on the other hand, has both width and height set to 0.
1375
1376
Note that due to the way QRect and QRectF are defined, an
1377
empty QRectF is defined in essentially the same way as QRect.
1378
1379
Finally, QRectF objects can be streamed as well as compared.
1380
1381
\section1 Rendering
1382
1383
When using an \l {QPainter::Antialiasing}{anti-aliased} painter,
1384
the boundary line of a QRectF will be rendered symmetrically on both
1385
sides of the mathematical rectangle's boundary line. But when
1386
using an aliased painter (the default) other rules apply.
1387
1388
Then, when rendering with a one pixel wide pen the QRectF's boundary
1389
line will be rendered to the right and below the mathematical
1390
rectangle's boundary line.
1391
1392
When rendering with a two pixels wide pen the boundary line will
1393
be split in the middle by the mathematical rectangle. This will be
1394
the case whenever the pen is set to an even number of pixels,
1395
while rendering with a pen with an odd number of pixels, the spare
1396
pixel will be rendered to the right and below the mathematical
1397
rectangle as in the one pixel case.
1398
1399
\table
1400
\row
1401
\li \inlineimage qrect-diagram-zero.svg
1402
{Rectangle showing width and height dimensions}
1403
\li \inlineimage qrectf-diagram-one.svg
1404
{Rectangle with one-pixel pen showing corner coordinates}
1405
\row
1406
\li Logical representation
1407
\li One pixel wide pen
1408
\row
1409
\li \inlineimage qrectf-diagram-two.svg
1410
{Rectangle with two-pixel pen showing corner coordinates}
1411
\li \inlineimage qrectf-diagram-three.svg
1412
{Rectangle with three-pixel pen showing corner coordinates}
1413
\row
1414
\li Two pixel wide pen
1415
\li Three pixel wide pen
1416
\endtable
1417
1418
\section1 Coordinates
1419
1420
The QRectF class provides a collection of functions that return
1421
the various rectangle coordinates, and enable manipulation of
1422
these. QRectF also provides functions to move the rectangle
1423
relative to the various coordinates.
1424
1425
For example: the bottom(), setBottom() and moveBottom() functions:
1426
bottom() returns the y-coordinate of the rectangle's bottom edge,
1427
setBottom() sets the bottom edge of the rectangle to the given y
1428
coordinate (it may change the height, but will never change the
1429
rectangle's top edge) and moveBottom() moves the entire rectangle
1430
vertically, leaving the rectangle's bottom edge at the given y
1431
coordinate and its size unchanged.
1432
1433
\image qrectf-coordinates.svg {Diagram of a rectangle showing QRect
1434
methods for positions: x(), y(), center(), corners (topLeft(),
1435
topRight(), bottomLeft(), bottomRight()), and edges (top(),
1436
bottom(), left(), right()).}
1437
1438
It is also possible to add offsets to this rectangle's coordinates
1439
using the adjust() function, as well as retrieve a new rectangle
1440
based on adjustments of the original one using the adjusted()
1441
function. If either of the width and height is negative, use the
1442
normalized() function to retrieve a rectangle where the corners
1443
are swapped.
1444
1445
In addition, QRectF provides the getCoords() function which extracts
1446
the position of the rectangle's top-left and bottom-right corner,
1447
and the getRect() function which extracts the rectangle's top-left
1448
corner, width and height. Use the setCoords() and setRect()
1449
function to manipulate the rectangle's coordinates and dimensions
1450
in one go.
1451
1452
\sa QRect, QRegion
1453
*/
1454
1455
/*****************************************************************************
1456
QRectF member functions
1457
*****************************************************************************/
1458
1459
/*!
1460
\fn QRectF::QRectF()
1461
1462
Constructs a null rectangle.
1463
1464
\sa isNull()
1465
*/
1466
1467
/*!
1468
\fn QRectF::QRectF(const QPointF &topLeft, const QSizeF &size)
1469
1470
Constructs a rectangle with the given \a topLeft corner and the given \a size.
1471
1472
\sa setTopLeft(), setSize()
1473
*/
1474
1475
/*!
1476
\fn QRectF::QRectF(const QPointF &topLeft, const QPointF &bottomRight)
1477
\since 4.3
1478
1479
Constructs a rectangle with the given \a topLeft and \a bottomRight corners.
1480
1481
\sa setTopLeft(), setBottomRight()
1482
*/
1483
1484
/*!
1485
\fn QRectF::QRectF(qreal x, qreal y, qreal width, qreal height)
1486
1487
Constructs a rectangle with (\a x, \a y) as its top-left corner and the
1488
given \a width and \a height. All parameters must be finite.
1489
1490
\sa setRect()
1491
*/
1492
1493
/*!
1494
\fn QRectF::QRectF(const QRect &rectangle)
1495
1496
Constructs a QRectF rectangle from the given QRect \a rectangle.
1497
1498
\note This function, like QRect::toRectF(), preserves the size() of
1499
\a rectangle, not its bottomRight() corner.
1500
1501
\sa toRect(), QRect::toRectF()
1502
*/
1503
1504
/*!
1505
\fn bool QRectF::isNull() const
1506
1507
Returns \c true if the rectangle is a null rectangle, otherwise returns \c false.
1508
1509
A null rectangle has both the width and the height set to 0. A
1510
null rectangle is also empty, and hence not valid.
1511
1512
\sa isEmpty(), isValid()
1513
*/
1514
1515
/*!
1516
\fn bool QRectF::isEmpty() const
1517
1518
Returns \c true if the rectangle is empty, otherwise returns \c false.
1519
1520
An empty rectangle has width() <= 0 or height() <= 0. An empty
1521
rectangle is not valid (i.e., isEmpty() == !isValid()).
1522
1523
Use the normalized() function to retrieve a rectangle where the
1524
corners are swapped.
1525
1526
\sa isNull(), isValid(), normalized()
1527
*/
1528
1529
/*!
1530
\fn bool QRectF::isValid() const
1531
1532
Returns \c true if the rectangle is valid, otherwise returns \c false.
1533
1534
A valid rectangle has a width() > 0 and height() > 0. Note that
1535
non-trivial operations like intersections are not defined for
1536
invalid rectangles. A valid rectangle is not empty (i.e., isValid()
1537
== !isEmpty()).
1538
1539
\sa isNull(), isEmpty(), normalized()
1540
*/
1541
1542
1543
/*!
1544
Returns a normalized rectangle; i.e., a rectangle that has a
1545
non-negative width and height.
1546
1547
If width() < 0 the function swaps the left and right corners, and
1548
it swaps the top and bottom corners if height() < 0.
1549
1550
\sa isValid(), isEmpty()
1551
*/
1552
1553
QRectF QRectF::normalized()
const
noexcept
1554
{
1555
QRectF r = *
this
;
1556
if
(r.w < 0) {
1557
r.xp += r.w;
1558
r.w = -r.w;
1559
}
1560
if
(r.h < 0) {
1561
r.yp += r.h;
1562
r.h = -r.h;
1563
}
1564
return
r;
1565
}
1566
1567
/*!
1568
\fn qreal QRectF::x() const
1569
1570
Returns the x-coordinate of the rectangle's left edge. Equivalent
1571
to left().
1572
1573
1574
\sa setX(), y(), topLeft()
1575
*/
1576
1577
/*!
1578
\fn qreal QRectF::y() const
1579
1580
Returns the y-coordinate of the rectangle's top edge. Equivalent
1581
to top().
1582
1583
\sa setY(), x(), topLeft()
1584
*/
1585
1586
1587
/*!
1588
\fn void QRectF::setLeft(qreal x)
1589
1590
Sets the left edge of the rectangle to the given finite \a x
1591
coordinate. May change the width, but will never change the right
1592
edge of the rectangle.
1593
1594
Equivalent to setX().
1595
1596
\sa left(), moveLeft()
1597
*/
1598
1599
/*!
1600
\fn void QRectF::setTop(qreal y)
1601
1602
Sets the top edge of the rectangle to the given finite \a y coordinate. May
1603
change the height, but will never change the bottom edge of the
1604
rectangle.
1605
1606
Equivalent to setY().
1607
1608
\sa top(), moveTop()
1609
*/
1610
1611
/*!
1612
\fn void QRectF::setRight(qreal x)
1613
1614
Sets the right edge of the rectangle to the given finite \a x
1615
coordinate. May change the width, but will never change the left
1616
edge of the rectangle.
1617
1618
\sa right(), moveRight()
1619
*/
1620
1621
/*!
1622
\fn void QRectF::setBottom(qreal y)
1623
1624
Sets the bottom edge of the rectangle to the given finite \a y
1625
coordinate. May change the height, but will never change the top
1626
edge of the rectangle.
1627
1628
\sa bottom(), moveBottom()
1629
*/
1630
1631
/*!
1632
\fn void QRectF::setX(qreal x)
1633
1634
Sets the left edge of the rectangle to the given finite \a x
1635
coordinate. May change the width, but will never change the right
1636
edge of the rectangle.
1637
1638
Equivalent to setLeft().
1639
1640
\sa x(), setY(), setTopLeft()
1641
*/
1642
1643
/*!
1644
\fn void QRectF::setY(qreal y)
1645
1646
Sets the top edge of the rectangle to the given finite \a y
1647
coordinate. May change the height, but will never change the
1648
bottom edge of the rectangle.
1649
1650
Equivalent to setTop().
1651
1652
\sa y(), setX(), setTopLeft()
1653
*/
1654
1655
/*!
1656
\fn void QRectF::setTopLeft(const QPointF &position)
1657
1658
Set the top-left corner of the rectangle to the given \a
1659
position. May change the size, but will never change the
1660
bottom-right corner of the rectangle.
1661
1662
\sa topLeft(), moveTopLeft()
1663
*/
1664
1665
/*!
1666
\fn void QRectF::setBottomRight(const QPointF &position)
1667
1668
Set the bottom-right corner of the rectangle to the given \a
1669
position. May change the size, but will never change the
1670
top-left corner of the rectangle.
1671
1672
\sa bottomRight(), moveBottomRight()
1673
*/
1674
1675
/*!
1676
\fn void QRectF::setTopRight(const QPointF &position)
1677
1678
Set the top-right corner of the rectangle to the given \a
1679
position. May change the size, but will never change the
1680
bottom-left corner of the rectangle.
1681
1682
\sa topRight(), moveTopRight()
1683
*/
1684
1685
/*!
1686
\fn void QRectF::setBottomLeft(const QPointF &position)
1687
1688
Set the bottom-left corner of the rectangle to the given \a
1689
position. May change the size, but will never change the
1690
top-right corner of the rectangle.
1691
1692
\sa bottomLeft(), moveBottomLeft()
1693
*/
1694
1695
/*!
1696
\fn QPointF QRectF::center() const
1697
1698
Returns the center point of the rectangle.
1699
1700
\sa moveCenter()
1701
*/
1702
1703
1704
/*!
1705
\fn void QRectF::getRect(qreal *x, qreal *y, qreal *width, qreal *height) const
1706
1707
Extracts the position of the rectangle's top-left corner to *\a x and
1708
*\a y, and its dimensions to *\a width and *\a height.
1709
1710
\sa setRect(), getCoords()
1711
*/
1712
1713
1714
/*!
1715
\fn void QRectF::getCoords(qreal *x1, qreal *y1, qreal *x2, qreal *y2) const
1716
1717
Extracts the position of the rectangle's top-left corner to *\a x1
1718
and *\a y1, and the position of the bottom-right corner to *\a x2 and
1719
*\a y2.
1720
1721
\sa setCoords(), getRect()
1722
*/
1723
1724
/*!
1725
\fn void QRectF::moveLeft(qreal x)
1726
1727
Moves the rectangle horizontally, leaving the rectangle's left
1728
edge at the given finite \a x coordinate. The rectangle's size is
1729
unchanged.
1730
1731
\sa left(), setLeft(), moveRight()
1732
*/
1733
1734
/*!
1735
\fn void QRectF::moveTop(qreal y)
1736
1737
Moves the rectangle vertically, leaving the rectangle's top line
1738
at the given finite \a y coordinate. The rectangle's size is unchanged.
1739
1740
\sa top(), setTop(), moveBottom()
1741
*/
1742
1743
1744
/*!
1745
\fn void QRectF::moveRight(qreal x)
1746
1747
Moves the rectangle horizontally, leaving the rectangle's right
1748
edge at the given finite \a x coordinate. The rectangle's size is
1749
unchanged.
1750
1751
\sa right(), setRight(), moveLeft()
1752
*/
1753
1754
1755
/*!
1756
\fn void QRectF::moveBottom(qreal y)
1757
1758
Moves the rectangle vertically, leaving the rectangle's bottom
1759
edge at the given finite \a y coordinate. The rectangle's size is
1760
unchanged.
1761
1762
\sa bottom(), setBottom(), moveTop()
1763
*/
1764
1765
1766
/*!
1767
\fn void QRectF::moveTopLeft(const QPointF &position)
1768
1769
Moves the rectangle, leaving the top-left corner at the given \a
1770
position. The rectangle's size is unchanged.
1771
1772
\sa setTopLeft(), moveTop(), moveLeft()
1773
*/
1774
1775
1776
/*!
1777
\fn void QRectF::moveBottomRight(const QPointF &position)
1778
1779
Moves the rectangle, leaving the bottom-right corner at the given
1780
\a position. The rectangle's size is unchanged.
1781
1782
\sa setBottomRight(), moveBottom(), moveRight()
1783
*/
1784
1785
1786
/*!
1787
\fn void QRectF::moveTopRight(const QPointF &position)
1788
1789
Moves the rectangle, leaving the top-right corner at the given
1790
\a position. The rectangle's size is unchanged.
1791
1792
\sa setTopRight(), moveTop(), moveRight()
1793
*/
1794
1795
1796
/*!
1797
\fn void QRectF::moveBottomLeft(const QPointF &position)
1798
1799
Moves the rectangle, leaving the bottom-left corner at the given
1800
\a position. The rectangle's size is unchanged.
1801
1802
\sa setBottomLeft(), moveBottom(), moveLeft()
1803
*/
1804
1805
1806
/*!
1807
\fn void QRectF::moveTo(qreal x, qreal y)
1808
1809
Moves the rectangle, leaving the top-left corner at the given position (\a
1810
x, \a y). The rectangle's size is unchanged. Both parameters must be finite.
1811
1812
\sa translate(), moveTopLeft()
1813
*/
1814
1815
/*!
1816
\fn void QRectF::moveTo(const QPointF &position)
1817
\overload
1818
1819
Moves the rectangle, leaving the top-left corner at the given \a
1820
position.
1821
*/
1822
1823
/*!
1824
\fn void QRectF::translate(qreal dx, qreal dy)
1825
1826
Moves the rectangle \a dx along the x-axis and \a dy along the y-axis,
1827
relative to the current position. Positive values move the rectangle to the
1828
right and downwards. Both parameters must be finite.
1829
1830
\sa moveTopLeft(), moveTo(), translated()
1831
*/
1832
1833
1834
/*!
1835
\fn void QRectF::translate(const QPointF &offset)
1836
\overload
1837
1838
Moves the rectangle \a{offset}.\l{QPointF::x()}{x()} along the x
1839
axis and \a{offset}.\l{QPointF::y()}{y()} along the y axis,
1840
relative to the current position.
1841
*/
1842
1843
1844
/*!
1845
\fn QRectF QRectF::translated(qreal dx, qreal dy) const
1846
1847
Returns a copy of the rectangle that is translated \a dx along the
1848
x axis and \a dy along the y axis, relative to the current
1849
position. Positive values move the rectangle to the right and
1850
down. Both parameters must be finite.
1851
1852
\sa translate()
1853
*/
1854
1855
1856
/*!
1857
\fn QRectF QRectF::translated(const QPointF &offset) const
1858
\overload
1859
1860
Returns a copy of the rectangle that is translated
1861
\a{offset}.\l{QPointF::x()}{x()} along the x axis and
1862
\a{offset}.\l{QPointF::y()}{y()} along the y axis, relative to the
1863
current position.
1864
*/
1865
1866
/*!
1867
\fn QRectF QRectF::transposed() const
1868
\since 5.7
1869
1870
Returns a copy of the rectangle that has its width and height
1871
exchanged:
1872
1873
\snippet code/src_corelib_tools_qrect.cpp 3
1874
1875
\sa QSizeF::transposed()
1876
*/
1877
1878
/*!
1879
\fn void QRectF::setRect(qreal x, qreal y, qreal width, qreal height)
1880
1881
Sets the coordinates of the rectangle's top-left corner to (\a x, \a y), and
1882
its size to the given \a width and \a height. All parameters must be finite.
1883
1884
\sa getRect(), setCoords()
1885
*/
1886
1887
1888
/*!
1889
\fn void QRectF::setCoords(qreal x1, qreal y1, qreal x2, qreal y2)
1890
1891
Sets the coordinates of the rectangle's top-left corner to (\a x1,
1892
\a y1), and the coordinates of its bottom-right corner to (\a x2,
1893
\a y2). All parameters must be finite.
1894
1895
\sa getCoords(), setRect()
1896
*/
1897
1898
/*!
1899
\fn QRectF QRectF::adjusted(qreal dx1, qreal dy1, qreal dx2, qreal dy2) const
1900
1901
Returns a new rectangle with \a dx1, \a dy1, \a dx2 and \a dy2
1902
added respectively to the existing coordinates of this rectangle.
1903
All parameters must be finite.
1904
1905
\sa adjust()
1906
*/
1907
1908
/*! \fn void QRectF::adjust(qreal dx1, qreal dy1, qreal dx2, qreal dy2)
1909
1910
Adds \a dx1, \a dy1, \a dx2 and \a dy2 respectively to the
1911
existing coordinates of the rectangle. All parameters must be finite.
1912
1913
\sa adjusted(), setRect()
1914
*/
1915
/*!
1916
\fn QSizeF QRectF::size() const
1917
1918
Returns the size of the rectangle.
1919
1920
\sa setSize(), width(), height()
1921
*/
1922
1923
/*!
1924
\fn qreal QRectF::width() const
1925
1926
Returns the width of the rectangle.
1927
1928
\sa setWidth(), height(), size()
1929
*/
1930
1931
/*!
1932
\fn qreal QRectF::height() const
1933
1934
Returns the height of the rectangle.
1935
1936
\sa setHeight(), width(), size()
1937
*/
1938
1939
/*!
1940
\fn void QRectF::setWidth(qreal width)
1941
1942
Sets the width of the rectangle to the given finite \a width. The right
1943
edge is changed, but not the left one.
1944
1945
\sa width(), setSize()
1946
*/
1947
1948
1949
/*!
1950
\fn void QRectF::setHeight(qreal height)
1951
1952
Sets the height of the rectangle to the given finite \a height. The bottom
1953
edge is changed, but not the top one.
1954
1955
\sa height(), setSize()
1956
*/
1957
1958
1959
/*!
1960
\fn void QRectF::setSize(const QSizeF &size)
1961
1962
Sets the size of the rectangle to the given finite \a size. The top-left
1963
corner is not moved.
1964
1965
\sa size(), setWidth(), setHeight()
1966
*/
1967
1968
1969
/*!
1970
\fn bool QRectF::contains(const QPointF &point) const
1971
1972
Returns \c true if the given \a point is inside or on the edge of the
1973
rectangle; otherwise returns \c false.
1974
1975
\sa intersects()
1976
*/
1977
1978
bool
QRectF::contains(
const
QPointF &p)
const
noexcept
1979
{
1980
qreal l = xp;
1981
qreal r = xp;
1982
if
(w < 0)
1983
l += w;
1984
else
1985
r += w;
1986
if
(l == r)
// null rect
1987
return
false
;
1988
1989
if
(p.x() < l || p.x() > r)
1990
return
false
;
1991
1992
qreal t = yp;
1993
qreal b = yp;
1994
if
(h < 0)
1995
t += h;
1996
else
1997
b += h;
1998
if
(t == b)
// null rect
1999
return
false
;
2000
2001
if
(p.y() < t || p.y() > b)
2002
return
false
;
2003
2004
return
true
;
2005
}
2006
2007
2008
/*!
2009
\fn bool QRectF::contains(qreal x, qreal y) const
2010
\overload
2011
2012
Returns \c true if the point (\a x, \a y) is inside or on the edge of
2013
the rectangle; otherwise returns \c false.
2014
*/
2015
2016
/*!
2017
\fn bool QRectF::contains(const QRectF &rectangle) const
2018
\overload
2019
2020
Returns \c true if the given \a rectangle is inside this rectangle;
2021
otherwise returns \c false.
2022
*/
2023
2024
bool
QRectF::contains(
const
QRectF &r)
const
noexcept
2025
{
2026
qreal l1 = xp;
2027
qreal r1 = xp;
2028
if
(w < 0)
2029
l1 += w;
2030
else
2031
r1 += w;
2032
if
(l1 == r1)
// null rect
2033
return
false
;
2034
2035
qreal l2 = r.xp;
2036
qreal r2 = r.xp;
2037
if
(r.w < 0)
2038
l2 += r.w;
2039
else
2040
r2 += r.w;
2041
if
(l2 == r2)
// null rect
2042
return
false
;
2043
2044
if
(l2 < l1 || r2 > r1)
2045
return
false
;
2046
2047
qreal t1 = yp;
2048
qreal b1 = yp;
2049
if
(h < 0)
2050
t1 += h;
2051
else
2052
b1 += h;
2053
if
(t1 == b1)
// null rect
2054
return
false
;
2055
2056
qreal t2 = r.yp;
2057
qreal b2 = r.yp;
2058
if
(r.h < 0)
2059
t2 += r.h;
2060
else
2061
b2 += r.h;
2062
if
(t2 == b2)
// null rect
2063
return
false
;
2064
2065
if
(t2 < t1 || b2 > b1)
2066
return
false
;
2067
2068
return
true
;
2069
}
2070
2071
/*!
2072
\fn qreal QRectF::left() const
2073
2074
Returns the x-coordinate of the rectangle's left edge. Equivalent
2075
to x().
2076
2077
\sa setLeft(), topLeft(), bottomLeft()
2078
*/
2079
2080
/*!
2081
\fn qreal QRectF::top() const
2082
2083
Returns the y-coordinate of the rectangle's top edge. Equivalent
2084
to y().
2085
2086
\sa setTop(), topLeft(), topRight()
2087
*/
2088
2089
/*!
2090
\fn qreal QRectF::right() const
2091
2092
Returns the x-coordinate of the rectangle's right edge.
2093
2094
\sa setRight(), topRight(), bottomRight()
2095
*/
2096
2097
/*!
2098
\fn qreal QRectF::bottom() const
2099
2100
Returns the y-coordinate of the rectangle's bottom edge.
2101
2102
\sa setBottom(), bottomLeft(), bottomRight()
2103
*/
2104
2105
/*!
2106
\fn QPointF QRectF::topLeft() const
2107
2108
Returns the position of the rectangle's top-left corner.
2109
2110
\sa setTopLeft(), top(), left()
2111
*/
2112
2113
/*!
2114
\fn QPointF QRectF::bottomRight() const
2115
2116
Returns the position of the rectangle's bottom-right corner.
2117
2118
\sa setBottomRight(), bottom(), right()
2119
*/
2120
2121
/*!
2122
\fn QPointF QRectF::topRight() const
2123
2124
Returns the position of the rectangle's top-right corner.
2125
2126
\sa setTopRight(), top(), right()
2127
*/
2128
2129
/*!
2130
\fn QPointF QRectF::bottomLeft() const
2131
2132
Returns the position of the rectangle's bottom-left corner.
2133
2134
\sa setBottomLeft(), bottom(), left()
2135
*/
2136
2137
/*!
2138
\fn QRectF& QRectF::operator|=(const QRectF &rectangle)
2139
2140
Unites this rectangle with the given \a rectangle.
2141
2142
\sa united(), operator|()
2143
*/
2144
2145
/*!
2146
\fn QRectF& QRectF::operator&=(const QRectF &rectangle)
2147
2148
Intersects this rectangle with the given \a rectangle.
2149
2150
\sa intersected(), operator&()
2151
*/
2152
2153
2154
/*!
2155
\fn QRectF QRectF::operator|(const QRectF &rectangle) const
2156
2157
Returns the bounding rectangle of this rectangle and the given \a rectangle.
2158
2159
\sa united(), operator|=()
2160
*/
2161
2162
QRectF QRectF::operator|(
const
QRectF &r)
const
noexcept
2163
{
2164
if
(isNull())
2165
return
r;
2166
if
(r.isNull())
2167
return
*
this
;
2168
2169
qreal left = xp;
2170
qreal right = xp;
2171
if
(w < 0)
2172
left += w;
2173
else
2174
right += w;
2175
2176
if
(r.w < 0) {
2177
left = qMin(left, r.xp + r.w);
2178
right = qMax(right, r.xp);
2179
}
else
{
2180
left = qMin(left, r.xp);
2181
right = qMax(right, r.xp + r.w);
2182
}
2183
2184
qreal top = yp;
2185
qreal bottom = yp;
2186
if
(h < 0)
2187
top += h;
2188
else
2189
bottom += h;
2190
2191
if
(r.h < 0) {
2192
top = qMin(top, r.yp + r.h);
2193
bottom = qMax(bottom, r.yp);
2194
}
else
{
2195
top = qMin(top, r.yp);
2196
bottom = qMax(bottom, r.yp + r.h);
2197
}
2198
2199
return
QRectF(left, top, right - left, bottom - top);
2200
}
2201
2202
/*!
2203
\fn QRectF QRectF::united(const QRectF &rectangle) const
2204
\since 4.2
2205
2206
Returns the bounding rectangle of this rectangle and the given \a
2207
rectangle.
2208
2209
\image qrect-unite.svg {Diagram showing two overlapped rectangles
2210
r and s and their united size which is determined with
2211
r.united(s).width and r.united(s).height()}
2212
2213
\sa intersected()
2214
*/
2215
2216
2217
/*!
2218
\fn QRectF QRectF::operator &(const QRectF &rectangle) const
2219
2220
Returns the intersection of this rectangle and the given \a
2221
rectangle. Returns an empty rectangle if there is no intersection.
2222
2223
\sa operator&=(), intersected()
2224
*/
2225
2226
QRectF QRectF::operator&(
const
QRectF &r)
const
noexcept
2227
{
2228
qreal l1 = xp;
2229
qreal r1 = xp;
2230
if
(w < 0)
2231
l1 += w;
2232
else
2233
r1 += w;
2234
if
(l1 == r1)
// null rect
2235
return
QRectF();
2236
2237
qreal l2 = r.xp;
2238
qreal r2 = r.xp;
2239
if
(r.w < 0)
2240
l2 += r.w;
2241
else
2242
r2 += r.w;
2243
if
(l2 == r2)
// null rect
2244
return
QRectF();
2245
2246
if
(l1 >= r2 || l2 >= r1)
2247
return
QRectF();
2248
2249
qreal t1 = yp;
2250
qreal b1 = yp;
2251
if
(h < 0)
2252
t1 += h;
2253
else
2254
b1 += h;
2255
if
(t1 == b1)
// null rect
2256
return
QRectF();
2257
2258
qreal t2 = r.yp;
2259
qreal b2 = r.yp;
2260
if
(r.h < 0)
2261
t2 += r.h;
2262
else
2263
b2 += r.h;
2264
if
(t2 == b2)
// null rect
2265
return
QRectF();
2266
2267
if
(t1 >= b2 || t2 >= b1)
2268
return
QRectF();
2269
2270
QRectF tmp;
2271
tmp.xp = qMax(l1, l2);
2272
tmp.yp = qMax(t1, t2);
2273
tmp.w = qMin(r1, r2) - tmp.xp;
2274
tmp.h = qMin(b1, b2) - tmp.yp;
2275
return
tmp;
2276
}
2277
2278
/*!
2279
\fn QRectF QRectF::intersected(const QRectF &rectangle) const
2280
\since 4.2
2281
2282
Returns the intersection of this rectangle and the given \a
2283
rectangle. Note that \c {r.intersected(s)} is equivalent to \c
2284
{r & s}.
2285
2286
\image qrect-intersect.svg {Diagram showing intersection of two
2287
rectangles r and s with the overlapping area highlighted.
2288
It's also showing how the width and height of the
2289
highlighted area is determined with r.intersect(s).width
2290
and r.intersect(s).height().}
2291
2292
\sa intersects(), united(), operator&=()
2293
*/
2294
2295
/*!
2296
\fn bool QRectF::intersects(const QRectF &rectangle) const
2297
2298
Returns \c true if this rectangle intersects with the given \a
2299
rectangle (i.e. there is a non-empty area of overlap between
2300
them), otherwise returns \c false.
2301
2302
The intersection rectangle can be retrieved using the intersected()
2303
function.
2304
2305
\sa contains()
2306
*/
2307
2308
bool
QRectF::intersects(
const
QRectF &r)
const
noexcept
2309
{
2310
qreal l1 = xp;
2311
qreal r1 = xp;
2312
if
(w < 0)
2313
l1 += w;
2314
else
2315
r1 += w;
2316
if
(l1 == r1)
// null rect
2317
return
false
;
2318
2319
qreal l2 = r.xp;
2320
qreal r2 = r.xp;
2321
if
(r.w < 0)
2322
l2 += r.w;
2323
else
2324
r2 += r.w;
2325
if
(l2 == r2)
// null rect
2326
return
false
;
2327
2328
if
(l1 >= r2 || l2 >= r1)
2329
return
false
;
2330
2331
qreal t1 = yp;
2332
qreal b1 = yp;
2333
if
(h < 0)
2334
t1 += h;
2335
else
2336
b1 += h;
2337
if
(t1 == b1)
// null rect
2338
return
false
;
2339
2340
qreal t2 = r.yp;
2341
qreal b2 = r.yp;
2342
if
(r.h < 0)
2343
t2 += r.h;
2344
else
2345
b2 += r.h;
2346
if
(t2 == b2)
// null rect
2347
return
false
;
2348
2349
if
(t1 >= b2 || t2 >= b1)
2350
return
false
;
2351
2352
return
true
;
2353
}
2354
2355
/*!
2356
\fn QRect QRectF::toRect() const
2357
2358
Returns a QRect based on the values of this rectangle. Note that the
2359
coordinates in the returned rectangle are rounded to the nearest integer.
2360
2361
\sa QRectF(), toAlignedRect(), QRect::toRectF()
2362
*/
2363
2364
/*!
2365
\fn QRect QRectF::toAlignedRect() const
2366
\since 4.3
2367
2368
Returns a QRect based on the values of this rectangle that is the
2369
smallest possible integer rectangle that completely contains this
2370
rectangle.
2371
2372
\sa toRect()
2373
*/
2374
2375
QRect QRectF::toAlignedRect()
const
noexcept
2376
{
2377
int
xmin = qFloor(xp);
2378
int
xmax = qCeil(xp + w);
2379
int
ymin = qFloor(yp);
2380
int
ymax = qCeil(yp + h);
2381
return
QRect(xmin, ymin, xmax - xmin, ymax - ymin);
2382
}
2383
2384
/*!
2385
\fn void QRectF::moveCenter(const QPointF &position)
2386
2387
Moves the rectangle, leaving the center point at the given \a
2388
position. The rectangle's size is unchanged.
2389
2390
\sa center()
2391
*/
2392
2393
/*!
2394
\fn bool QRectF::operator==(const QRectF &lhs, const QRectF &rhs)
2395
2396
Returns \c true if the rectangles \a lhs and \a rhs are \b approximately
2397
equal, otherwise returns \c false.
2398
2399
\warning This function does not check for strict equality; instead,
2400
it uses a fuzzy comparison to compare the rectangles' coordinates.
2401
2402
\sa qFuzzyCompare
2403
*/
2404
2405
2406
/*!
2407
\fn bool QRectF::operator!=(const QRectF &lhs, const QRectF &rhs)
2408
2409
Returns \c true if the rectangles \a lhs and \a rhs are sufficiently
2410
different, otherwise returns \c false.
2411
2412
\warning This function does not check for strict inequality; instead,
2413
it uses a fuzzy comparison to compare the rectangles' coordinates.
2414
*/
2415
2416
/*!
2417
\fn QRectF operator+(const QRectF &lhs, const QMarginsF &rhs)
2418
\relates QRectF
2419
\since 5.3
2420
2421
Returns the \a lhs rectangle grown by the \a rhs margins.
2422
*/
2423
2424
/*!
2425
\fn QRectF operator-(const QRectF &lhs, const QMarginsF &rhs)
2426
\relates QRectF
2427
\since 5.3
2428
2429
Returns the \a lhs rectangle shrunk by the \a rhs margins.
2430
*/
2431
2432
/*!
2433
\fn QRectF operator+(const QMarginsF &lhs, const QRectF &rhs)
2434
\relates QRectF
2435
\overload
2436
\since 5.3
2437
2438
Returns the \a lhs rectangle grown by the \a rhs margins.
2439
*/
2440
2441
/*!
2442
\fn QRectF QRectF::marginsAdded(const QMarginsF &margins) const
2443
\since 5.3
2444
2445
Returns a rectangle grown by the \a margins.
2446
2447
\sa operator+=(), marginsRemoved(), operator-=()
2448
*/
2449
2450
/*!
2451
\fn QRectF QRectF::marginsRemoved(const QMarginsF &margins) const
2452
\since 5.3
2453
2454
Removes the \a margins from the rectangle, shrinking it.
2455
2456
\sa marginsAdded(), operator+=(), operator-=()
2457
*/
2458
2459
/*!
2460
\fn QRectF QRectF::operator+=(const QMarginsF &margins)
2461
\since 5.3
2462
2463
Adds the \a margins to the rectangle, growing it.
2464
2465
\sa marginsAdded(), marginsRemoved(), operator-=()
2466
*/
2467
2468
/*!
2469
\fn QRectF QRectF::operator-=(const QMarginsF &margins)
2470
\since 5.3
2471
2472
Returns a rectangle shrunk by the \a margins.
2473
2474
\sa marginsRemoved(), operator+=(), marginsAdded()
2475
*/
2476
2477
/*!
2478
\fn bool QRectF::qFuzzyCompare(const QRectF &lhs, const QRectF &rhs)
2479
\since 6.8
2480
2481
Returns \c true if the rectangle \a lhs is approximately equal to the
2482
rectangle \a rhs; otherwise returns \c false.
2483
*/
2484
2485
/*!
2486
\fn bool QRectF::qFuzzyIsNull(const QRectF &rect)
2487
\since 6.8
2488
2489
Returns \c true if both width and height of the rectangle \a rect are
2490
approximately equal to zero; otherwise returns \c false.
2491
*/
2492
2493
/*****************************************************************************
2494
QRectF stream functions
2495
*****************************************************************************/
2496
#
ifndef
QT_NO_DATASTREAM
2497
/*!
2498
\fn QDataStream &operator<<(QDataStream &stream, const QRectF &rectangle)
2499
2500
\relates QRectF
2501
2502
Writes the \a rectangle to the \a stream, and returns a reference to the
2503
stream.
2504
2505
\sa {Serializing Qt Data Types}
2506
*/
2507
2508
QDataStream &operator<<(QDataStream &s,
const
QRectF &r)
2509
{
2510
s <<
double
(r.x()) <<
double
(r.y()) <<
double
(r.width()) <<
double
(r.height());
2511
return
s;
2512
}
2513
2514
/*!
2515
\fn QDataStream &operator>>(QDataStream &stream, QRectF &rectangle)
2516
2517
\relates QRectF
2518
2519
Reads a \a rectangle from the \a stream, and returns a reference to the
2520
stream.
2521
2522
\sa {Serializing Qt Data Types}
2523
*/
2524
2525
QDataStream &
operator
>>(QDataStream &s, QRectF &r)
2526
{
2527
double
x, y, w, h;
2528
s >> x;
2529
s >> y;
2530
s >> w;
2531
s >> h;
2532
r.setRect(qreal(x), qreal(y), qreal(w), qreal(h));
2533
return
s;
2534
}
2535
2536
#
endif
// QT_NO_DATASTREAM
2537
2538
2539
#
ifndef
QT_NO_DEBUG_STREAM
2540
QDebug
operator
<<(QDebug dbg,
const
QRectF &r)
2541
{
2542
QDebugStateSaver saver(dbg);
2543
dbg.nospace();
2544
dbg <<
"QRectF"
<<
'('
;
2545
QtDebugUtils::formatQRect(dbg, r);
2546
dbg <<
')'
;
2547
return
dbg;
2548
}
2549
#
endif
2550
2551
QT_END_NAMESPACE
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
operator>>
QDataStream & operator>>(QDataStream &s, QKeyCombination &combination)
Definition
qdatastream.h:699
operator<<
QDebug operator<<(QDebug dbg, const QFileInfo &fi)
Definition
qfileinfo.cpp:1830
operator>>
QDataStream & operator>>(QDataStream &s, QRectF &r)
Definition
qrect.cpp:2525
operator<<
QDebug operator<<(QDebug dbg, const QRectF &r)
Definition
qrect.cpp:2540
qtbase
src
corelib
tools
qrect.cpp
Generated on
for Qt by
1.18.0