1QRect(3qt)                                                          QRect(3qt)
2
3
4

NAME

6       QRect - Defines a rectangle in the plane
7

SYNOPSIS

9       #include <qrect.h>
10
11   Public Members
12       QRect ()
13       QRect ( const QPoint & topLeft, const QPoint & bottomRight )
14       QRect ( const QPoint & topLeft, const QSize & size )
15       QRect ( int left, int top, int width, int height )
16       bool isNull () const
17       bool isEmpty () const
18       bool isValid () const
19       QRect normalize () const
20       int left () const
21       int top () const
22       int right () const
23       int bottom () const
24       QCOORD & rLeft ()
25       QCOORD & rTop ()
26       QCOORD & rRight ()
27       QCOORD & rBottom ()
28       int x () const
29       int y () const
30       void setLeft ( int pos )
31       void setTop ( int pos )
32       void setRight ( int pos )
33       void setBottom ( int pos )
34       void setX ( int x )
35       void setY ( int y )
36       void setTopLeft ( const QPoint & p )
37       void setBottomRight ( const QPoint & p )
38       void setTopRight ( const QPoint & p )
39       void setBottomLeft ( const QPoint & p )
40       QPoint topLeft () const
41       QPoint bottomRight () const
42       QPoint topRight () const
43       QPoint bottomLeft () const
44       QPoint center () const
45       void rect ( int * x, int * y, int * w, int * h ) const
46       void coords ( int * xp1, int * yp1, int * xp2, int * yp2 ) const
47       void moveLeft ( int pos )
48       void moveTop ( int pos )
49       void moveRight ( int pos )
50       void moveBottom ( int pos )
51       void moveTopLeft ( const QPoint & p )
52       void moveBottomRight ( const QPoint & p )
53       void moveTopRight ( const QPoint & p )
54       void moveBottomLeft ( const QPoint & p )
55       void moveCenter ( const QPoint & p )
56       void moveBy ( int dx, int dy )
57       void setRect ( int x, int y, int w, int h )
58       void setCoords ( int xp1, int yp1, int xp2, int yp2 )
59       void addCoords ( int xp1, int yp1, int xp2, int yp2 )
60       QSize size () const
61       int width () const
62       int height () const
63       void setWidth ( int w )
64       void setHeight ( int h )
65       void setSize ( const QSize & s )
66       QRect operator| ( const QRect & r ) const
67       QRect operator& ( const QRect & r ) const
68       QRect & operator|= ( const QRect & r )
69       QRect & operator&= ( const QRect & r )
70       bool contains ( const QPoint & p, bool proper = FALSE ) const
71       bool contains ( int x, int y ) const
72       bool contains ( int x, int y, bool proper ) const
73       bool contains ( const QRect & r, bool proper = FALSE ) const
74       QRect unite ( const QRect & r ) const
75       QRect intersect ( const QRect & r ) const
76       bool intersects ( const QRect & r ) const
77
79       bool operator== ( const QRect & r1, const QRect & r2 )
80       bool operator!= ( const QRect & r1, const QRect & r2 )
81       QDataStream & operator<< ( QDataStream & s, const QRect & r )
82       QDataStream & operator>> ( QDataStream & s, QRect & r )
83

DESCRIPTION

85       The QRect class defines a rectangle in the plane.
86
87       A rectangle is internally represented as an upper-left corner and a
88       bottom-right corner, but it is normally expressed as an upper-left
89       corner and a size.
90
91       The coordinate type is QCOORD (defined in qwindowdefs.h as int). The
92       minimum value of QCOORD is QCOORD_MIN (-2147483648) and the maximum
93       value is QCOORD_MAX (2147483647).
94
95       Note that the size (width and height) of a rectangle might be different
96       from what you are used to. If the top-left corner and the bottom-right
97       corner are the same, the height and the width of the rectangle will
98       both be 1.
99
100       Generally, width = right - left + 1 and height = bottom - top + 1. We
101       designed it this way to make it correspond to rectangular spaces used
102       by drawing functions in which the width and height denote a number of
103       pixels. For example, drawing a rectangle with width and height 1 draws
104       a single pixel.
105
106       The default coordinate system has origin (0, 0) in the top-left corner.
107       The positive direction of the y axis is down, and the positive x axis
108       is from left to right.
109
110       A QRect can be constructed with a set of left, top, width and height
111       integers, from two QPoints or from a QPoint and a QSize. After creation
112       the dimensions can be changed, e.g. with setLeft(), setRight(),
113       setTop() and setBottom(), or by setting sizes, e.g. setWidth(),
114       setHeight() and setSize(). The dimensions can also be changed with the
115       move functions, e.g. moveBy(), moveCenter(), moveBottomRight(), etc.
116       You can also add coordinates to a rectangle with addCoords().
117
118       You can test to see if a QRect contains a specific point with
119       contains(). You can also test to see if two QRects intersect with
120       intersects() (see also intersect()). To get the bounding rectangle of
121       two QRects use unite().
122
123       See also QPoint, QSize, Graphics Classes, and Image Processing Classes.
124

MEMBER FUNCTION DOCUMENTATION

QRect::QRect ()

127       Constructs an invalid rectangle.
128

QRect::QRect ( const QPoint & topLeft, const QPoint & bottomRight )

130       Constructs a rectangle with topLeft as the top-left corner and
131       bottomRight as the bottom-right corner.
132

QRect::QRect ( const QPoint & topLeft, const QSize & size )

134       Constructs a rectangle with topLeft as the top-left corner and size as
135       the rectangle size.
136

QRect::QRect ( int left, int top, int width, int height )

138       Constructs a rectangle with the top, left corner and width and height.
139
140       Example (creates three identical rectangles):
141
142               QRect r1( QPoint(100,200), QPoint(110,215) );
143               QRect r2( QPoint(100,200), QSize(11,16) );
144               QRect r3( 100, 200, 11, 16 );
145

void QRect::addCoords ( int xp1, int yp1, int xp2, int yp2 )

147       Adds xp1, yp1, xp2 and yp2 respectively to the existing coordinates of
148       the rectangle.
149
150       Examples:
151

int QRect::bottom () const

153       Returns the bottom coordinate of the rectangle.
154
155       See also setBottom(), top(), bottomLeft(), and bottomRight().
156
157       Examples:
158

QPoint QRect::bottomLeft () const

160       Returns the bottom-left position of the rectangle.
161
162       See also setBottomLeft(), moveBottomLeft(), topRight(), bottom(), and
163       left().
164
165       Example: tictac/tictac.cpp.
166

QPoint QRect::bottomRight () const

168       Returns the bottom-right position of the rectangle.
169
170       See also setBottomRight(), moveBottomRight(), topLeft(), right(), and
171       bottom().
172
173       Example: tictac/tictac.cpp.
174

QPoint QRect::center () const

176       Returns the center point of the rectangle.
177
178       See also moveCenter(), topLeft(), bottomRight(), topRight(), and
179       bottomLeft().
180
181       Example: tooltip/tooltip.cpp.
182

bool QRect::contains ( const QPoint & p, bool proper = FALSE ) const

184       Returns TRUE if the point p is inside or on the edge of the rectangle;
185       otherwise returns FALSE.
186
187       If proper is TRUE, this function returns TRUE only if p is inside (not
188       on the edge).
189
190       Example: t14/cannon.cpp.
191

bool QRect::contains ( int x, int y ) const

193       This is an overloaded member function, provided for convenience. It
194       behaves essentially like the above function.
195
196       Returns TRUE if the point x, y is inside this rectangle; otherwise
197       returns FALSE.
198

bool QRect::contains ( int x, int y, bool proper ) const

200       This is an overloaded member function, provided for convenience. It
201       behaves essentially like the above function.
202
203       Returns TRUE if the point x, y is inside this rectangle; otherwise
204       returns FALSE.
205
206       If proper is TRUE, this function returns TRUE only if the point is
207       entirely inside (not on the edge).
208

bool QRect::contains ( const QRect & r, bool proper = FALSE ) const

210       This is an overloaded member function, provided for convenience. It
211       behaves essentially like the above function.
212
213       Returns TRUE if the rectangle r is inside this rectangle; otherwise
214       returns FALSE.
215
216       If proper is TRUE, this function returns TRUE only if r is entirely
217       inside (not on the edge).
218
219       See also unite(), intersect(), and intersects().
220

void QRect::coords ( int * xp1, int * yp1, int * xp2, int * yp2 ) const

222       Extracts the rectangle parameters as the top-left point *xp1, *yp1 and
223       the bottom-right point *xp2, *yp2.
224
225       See also setCoords() and rect().
226
227       Examples:
228

int QRect::height () const

230       Returns the height of the rectangle. The height includes both the top
231       and bottom edges, i.e. height = bottom - top + 1.
232
233       See also width(), size(), and setHeight().
234
235       Examples:
236

QRect QRect::intersect ( const QRect & r ) const

238       Returns the intersection of this rectangle and rectangle r.
239       r.intersect(s) is equivalent to r&s.
240

bool QRect::intersects ( const QRect & r ) const

242       Returns TRUE if this rectangle intersects with rectangle r (there is at
243       least one pixel that is within both rectangles); otherwise returns
244       FALSE.
245
246       See also intersect() and contains().
247
248       Examples:
249

bool QRect::isEmpty () const

251       Returns TRUE if the rectangle is empty; otherwise returns FALSE.
252
253       An empty rectangle has a left() > right() or top() > bottom().
254
255       An empty rectangle is not valid. isEmpty() == !isValid()
256
257       See also isNull(), isValid(), and normalize().
258

bool QRect::isNull () const

260       Returns TRUE if the rectangle is a null rectangle; otherwise returns
261       FALSE.
262
263       A null rectangle has both the width and the height set to 0, that is
264       right() == left() - 1 and bottom() == top() - 1.
265
266       Note that if right() == left() and bottom() == top(), then the
267       rectangle has width 1 and height 1.
268
269       A null rectangle is also empty.
270
271       A null rectangle is not valid.
272
273       See also isEmpty() and isValid().
274

bool QRect::isValid () const

276       Returns TRUE if the rectangle is valid; otherwise returns FALSE.
277
278       A valid rectangle has a left() <= right() and top() <= bottom().
279
280       Note that non-trivial operations like intersections are not defined for
281       invalid rectangles.
282
283       isValid() == !isEmpty()
284
285       See also isNull(), isEmpty(), and normalize().
286
287       Examples:
288

int QRect::left () const

290       Returns the left coordinate of the rectangle. Identical to x().
291
292       See also setLeft(), right(), topLeft(), and bottomLeft().
293
294       Examples:
295

void QRect::moveBottom ( int pos )

297       Sets the bottom position of the rectangle to pos, leaving the size
298       unchanged.
299
300       See also bottom(), setBottom(), moveLeft(), moveTop(), and moveRight().
301

void QRect::moveBottomLeft ( const QPoint & p )

303       Sets the bottom-left position of the rectangle to p, leaving the size
304       unchanged.
305
306       See also bottomLeft(), setBottomLeft(), moveTopLeft(),
307       moveBottomRight(), and moveTopRight().
308
309       Example: t10/cannon.cpp.
310

void QRect::moveBottomRight ( const QPoint & p )

312       Sets the bottom-right position of the rectangle to p, leaving the size
313       unchanged.
314
315       See also bottomRight(), setBottomRight(), moveTopLeft(),
316       moveTopRight(), and moveBottomLeft().
317

void QRect::moveBy ( int dx, int dy )

319       Moves the rectangle dx along the x axis and dy along the y axis,
320       relative to the current position. Positive values move the rectangle to
321       the right and down.
322
323       See also moveTopLeft().
324
325       Examples:
326

void QRect::moveCenter ( const QPoint & p )

328       Sets the center point of the rectangle to p, leaving the size
329       unchanged.
330
331       See also center(), moveTopLeft(), moveBottomRight(), moveTopRight(),
332       and moveBottomLeft().
333
334       Examples:
335

void QRect::moveLeft ( int pos )

337       Sets the left position of the rectangle to pos, leaving the size
338       unchanged.
339
340       See also left(), setLeft(), moveTop(), moveRight(), and moveBottom().
341

void QRect::moveRight ( int pos )

343       Sets the right position of the rectangle to pos, leaving the size
344       unchanged.
345
346       See also right(), setRight(), moveLeft(), moveTop(), and moveBottom().
347

void QRect::moveTop ( int pos )

349       Sets the top position of the rectangle to pos, leaving the size
350       unchanged.
351
352       See also top(), setTop(), moveLeft(), moveRight(), and moveBottom().
353

void QRect::moveTopLeft ( const QPoint & p )

355       Sets the top-left position of the rectangle to p, leaving the size
356       unchanged.
357
358       See also topLeft(), setTopLeft(), moveBottomRight(), moveTopRight(),
359       and moveBottomLeft().
360
361       Examples:
362

void QRect::moveTopRight ( const QPoint & p )

364       Sets the top-right position of the rectangle to p, leaving the size
365       unchanged.
366
367       See also topRight(), setTopRight(), moveTopLeft(), moveBottomRight(),
368       and moveBottomLeft().
369

QRect QRect::normalize () const

371       Returns a normalized rectangle, i.e. a rectangle that has a non-
372       negative width and height.
373
374       It swaps left and right if left() > right(), and swaps top and bottom
375       if top() > bottom().
376
377       See also isValid().
378
379       Example: scribble/scribble.cpp.
380

QRect QRect::operator& ( const QRect & r ) const

382       Returns the intersection of this rectangle and rectangle r.
383
384       Returns an empty rectangle if there is no intersection.
385
386       See also operator&=(), operator|(), isEmpty(), intersects(), and
387       contains().
388

QRect & QRect::operator&= ( const QRect & r )

390       Intersects this rectangle with rectangle r.
391

QRect QRect::operator| ( const QRect & r ) const

393       Returns the bounding rectangle of this rectangle and rectangle r.
394
395       The bounding rectangle of a nonempty rectangle and an empty or invalid
396       rectangle is defined to be the nonempty rectangle.
397
398       See also operator|=(), operator&(), intersects(), and contains().
399

QRect & QRect::operator|= ( const QRect & r )

401       Unites this rectangle with rectangle r.
402

QCOORD & QRect::rBottom ()

404       Returns a reference to the bottom coordinate of the rectangle.
405
406       See also rLeft(), rTop(), and rRight().
407

QCOORD & QRect::rLeft ()

409       Returns a reference to the left coordinate of the rectangle.
410
411       See also rTop(), rRight(), and rBottom().
412

QCOORD & QRect::rRight ()

414       Returns a reference to the right coordinate of the rectangle.
415
416       See also rLeft(), rTop(), and rBottom().
417

QCOORD & QRect::rTop ()

419       Returns a reference to the top coordinate of the rectangle.
420
421       See also rLeft(), rRight(), and rBottom().
422

void QRect::rect ( int * x, int * y, int * w, int * h ) const

424       Extracts the rectangle parameters as the position *x, *y and width *w
425       and height *h.
426
427       See also setRect() and coords().
428
429       Examples:
430

int QRect::right () const

432       Returns the right coordinate of the rectangle.
433
434       See also setRight(), left(), topRight(), and bottomRight().
435
436       Examples:
437

void QRect::setBottom ( int pos )

439       Sets the bottom edge of the rectangle to pos. May change the height,
440       but will never change the top edge of the rectangle.
441
442       See also bottom(), setTop(), and setHeight().
443
444       Example: scribble/scribble.cpp.
445

void QRect::setBottomLeft ( const QPoint & p )

447       Set the bottom-left corner of the rectangle to p. May change the size,
448       but will the never change the top-right corner of the rectangle.
449
450       See also bottomLeft(), moveBottomLeft(), setTopLeft(),
451       setBottomRight(), and setTopRight().
452

void QRect::setBottomRight ( const QPoint & p )

454       Set the bottom-right corner of the rectangle to p. May change the size,
455       but will the never change the top-left corner of the rectangle.
456
457       See also bottomRight(), moveBottomRight(), setTopLeft(), setTopRight(),
458       and setBottomLeft().
459

void QRect::setCoords ( int xp1, int yp1, int xp2, int yp2 )

461       Sets the coordinates of the rectangle's top-left corner to (xp1, yp1),
462       and the coordinates of its bottom-right corner to (xp2, yp2).
463
464       See also coords() and setRect().
465

void QRect::setHeight ( int h )

467       Sets the height of the rectangle to h. The top edge is not moved, but
468       the bottom edge may be moved.
469
470       See also height(), setTop(), setBottom(), and setSize().
471
472       Example: desktop/desktop.cpp.
473

void QRect::setLeft ( int pos )

475       Sets the left edge of the rectangle to pos. May change the width, but
476       will never change the right edge of the rectangle.
477
478       Identical to setX().
479
480       See also left(), setTop(), and setWidth().
481
482       Example: scribble/scribble.cpp.
483

void QRect::setRect ( int x, int y, int w, int h )

485       Sets the coordinates of the rectangle's top-left corner to (x, y), and
486       its size to (w, h).
487
488       See also rect() and setCoords().
489
490       Example: themes/wood.cpp.
491

void QRect::setRight ( int pos )

493       Sets the right edge of the rectangle to pos. May change the width, but
494       will never change the left edge of the rectangle.
495
496       See also right(), setLeft(), and setWidth().
497
498       Example: scribble/scribble.cpp.
499

void QRect::setSize ( const QSize & s )

501       Sets the size of the rectangle to s. The top-left corner is not moved.
502
503       See also size(), setWidth(), and setHeight().
504
505       Example: xform/xform.cpp.
506

void QRect::setTop ( int pos )

508       Sets the top edge of the rectangle to pos. May change the height, but
509       will never change the bottom edge of the rectangle.
510
511       Identical to setY().
512
513       See also top(), setBottom(), and setHeight().
514
515       Example: scribble/scribble.cpp.
516

void QRect::setTopLeft ( const QPoint & p )

518       Set the top-left corner of the rectangle to p. May change the size, but
519       will the never change the bottom-right corner of the rectangle.
520
521       See also topLeft(), moveTopLeft(), setBottomRight(), setTopRight(), and
522       setBottomLeft().
523

void QRect::setTopRight ( const QPoint & p )

525       Set the top-right corner of the rectangle to p. May change the size,
526       but will the never change the bottom-left corner of the rectangle.
527
528       See also topRight(), moveTopRight(), setTopLeft(), setBottomRight(),
529       and setBottomLeft().
530

void QRect::setWidth ( int w )

532       Sets the width of the rectangle to w. The right edge is changed, but
533       not the left edge.
534
535       See also width(), setLeft(), setRight(), and setSize().
536
537       Example: desktop/desktop.cpp.
538

void QRect::setX ( int x )

540       Sets the x position of the rectangle (its left end) to x. May change
541       the width, but will never change the right edge of the rectangle.
542
543       Identical to setLeft().
544
545       See also x() and setY().
546

void QRect::setY ( int y )

548       Sets the y position of the rectangle (its top) to y. May change the
549       height, but will never change the bottom edge of the rectangle.
550
551       Identical to setTop().
552
553       See also y() and setX().
554

QSize QRect::size () const

556       Returns the size of the rectangle.
557
558       See also width() and height().
559
560       Examples:
561

int QRect::top () const

563       Returns the top coordinate of the rectangle. Identical to y().
564
565       See also setTop(), bottom(), topLeft(), and topRight().
566
567       Examples:
568

QPoint QRect::topLeft () const

570       Returns the top-left position of the rectangle.
571
572       See also setTopLeft(), moveTopLeft(), bottomRight(), left(), and top().
573
574       Examples:
575

QPoint QRect::topRight () const

577       Returns the top-right position of the rectangle.
578
579       See also setTopRight(), moveTopRight(), bottomLeft(), top(), and
580       right().
581
582       Example: tictac/tictac.cpp.
583

QRect QRect::unite ( const QRect & r ) const

585       Returns the bounding rectangle of this rectangle and rectangle r.
586       r.unite(s) is equivalent to r|s.
587
588       Examples:
589

int QRect::width () const

591       Returns the width of the rectangle. The width includes both the left
592       and right edges, i.e. width = right - left + 1.
593
594       See also height(), size(), and setHeight().
595
596       Examples:
597

int QRect::x () const

599       Returns the left coordinate of the rectangle. Identical to left().
600
601       See also left(), y(), and setX().
602
603       Examples:
604

int QRect::y () const

606       Returns the top coordinate of the rectangle. Identical to top().
607
608       See also top(), x(), and setY().
609
610       Examples:
611

bool operator!= ( const QRect & r1, const QRect & r2 )

614       Returns TRUE if r1 and r2 are different; otherwise returns FALSE.
615

QDataStream & operator<< ( QDataStream & s, const QRect & r )

617       Writes the QRect, r, to the stream s, and returns a reference to the
618       stream.
619
620       See also Format of the QDataStream operators.
621

bool operator== ( const QRect & r1, const QRect & r2 )

623       Returns TRUE if r1 and r2 are equal; otherwise returns FALSE.
624

QDataStream & operator>> ( QDataStream & s, QRect & r )

626       Reads a QRect from the stream s into rect r and returns a reference to
627       the stream.
628
629       See also Format of the QDataStream operators.
630
631

SEE ALSO

633       http://doc.trolltech.com/qrect.html
634       http://www.trolltech.com/faq/tech.html
635
637       Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com.  See the
638       license file included in the distribution for a complete license
639       statement.
640

AUTHOR

642       Generated automatically from the source code.
643

BUGS

645       If you find a bug in Qt, please report it as described in
646       http://doc.trolltech.com/bughowto.html.  Good bug reports help us to
647       help you. Thank you.
648
649       The definitive Qt documentation is provided in HTML format; it is
650       located at $QTDIR/doc/html and can be read using Qt Assistant or with a
651       web browser. This man page is provided as a convenience for those users
652       who prefer man pages, although this format is not officially supported
653       by Trolltech.
654
655       If you find errors in this manual page, please report them to qt-
656       bugs@trolltech.com.  Please include the name of the manual page
657       (qrect.3qt) and the Qt version (3.3.8).
658
659
660
661Trolltech AS                    2 February 2007                     QRect(3qt)
Impressum