Viadeo Twitter Google Bookmarks ! Facebook Digg del.icio.us MySpace Yahoo MyWeb Blinklist Netvouz Reddit Simpy StumbleUpon Bookmarks Windows Live Favorites 
Logo Documentation Qt ·  Page d'accueil  ·  Classes  ·  Annotées  ·  Hiérarchie  ·  Fonctions  ·  Structure  · 

QRect Class Reference


The QRect class defines a rectangle in the plane. More...

#include <qrect.h>

List of all member functions.

Public Members

  • QRect () 
  • QRect ( const QPoint & topleft, const QPoint & bottomright ) 
  • QRect ( const QPoint & topleft, const QSize & size ) 
  • QRect ( int left, int top, int width, int height ) 
  • bool isNull () const
  • bool isEmpty () const
  • bool isValid () const
  • QRect normalize () const
  • int left () const
  • int top () const
  • int right () const
  • int bottom () const
  • QCOORD& rLeft () 
  • QCOORD& rTop () 
  • QCOORD& rRight () 
  • QCOORD& rBottom () 
  • int x () const
  • int y () const
  • void setLeft ( int pos ) 
  • void setTop ( int pos ) 
  • void setRight ( int pos ) 
  • void setBottom ( int pos ) 
  • void setX ( int x ) 
  • void setY ( int y ) 
  • QPoint topLeft () const
  • QPoint bottomRight () const
  • QPoint topRight () const
  • QPoint bottomLeft () const
  • QPoint center () const
  • void rect ( int * x, int * y, int * w, int * h ) const
  • void coords ( int * x1, int * y1, int * x2, int * y2 ) const
  • void moveTopLeft ( const QPoint & p ) 
  • void moveBottomRight ( const QPoint & p ) 
  • void moveTopRight ( const QPoint & p ) 
  • void moveBottomLeft ( const QPoint & p ) 
  • void moveCenter ( const QPoint & p ) 
  • void moveBy ( int dx, int dy ) 
  • void setRect ( int x, int y, int w, int h ) 
  • void setCoords ( int x1, int y1, int x2, int y2 ) 
  • QSize size () const
  • int width () const
  • int height () const
  • void setWidth ( int w ) 
  • void setHeight ( int h ) 
  • void setSize ( const QSize & s ) 
  • QRect operator| ( const QRect & r ) const
  • QRect operator& ( const QRect & r ) const
  • QRect& operator|= ( const QRect & r ) 
  • QRect& operator&= ( const QRect & r ) 
  • bool contains ( const QPoint & p, bool proper=FALSE ) const
  • bool contains ( int x, int y, bool proper=FALSE ) const
  • bool contains ( const QRect & r, bool proper=FALSE ) const
  • QRect unite ( const QRect & r ) const
  • QRect intersect ( const QRect & r ) const
  • bool intersects ( const QRect & r ) const

Related Functions

(Note that these are not member functions.)
  • bool operator== (const QRect & r1, const QRect & r2)
  • QDataStream & operator>> (QDataStream & s, QRect & r)
  • QDataStream & operator<< (QDataStream & s, const QRect & r)
  • bool operator!= (const QRect & r1, const QRect & r2)

Detailed Description

The QRect class defines a rectangle in the plane.

A rectangle is internally represented as an upper left corner and a bottom right corner, but it is normally expressed as an upper left corner and a size.

The coordinate type is QCOORD (defined in qwindowdefs.h as int). The minimum value of QCOORD is QCOORD_MIN (-2147483648) and the maximum value is QCOORD_MAX (2147483647).

Note that the size (width and height) of a rectangle might be different from what you are used to. If the top left corner and the bottom right corner are the same, then the height and the width of the rectangle will both be 1.

Generally, width = right - left + 1 and height = bottom - top + 1. We designed it this way to make it correspond to rectangular spaces used by drawing functions, where the width and height denote a number of pixels. For example, drawing a rectangle with width and height 1 draws a single pixel.

The default coordinate system has origin (0,0) in the top left corner, the positive direction of the y axis is downwards and the positive x axis is from the left to the right.

See also QPoint and QSize.

Examples: forever/forever.cpp movies/main.cpp xform/xform.cpp desktop/desktop.cpp


Member Function Documentation

QRect::QRect ()

Constructs an invalid rectangle.

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

Constructs a rectangle with topLeft as the top left corner and bottomRight as the bottom right corner.

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

Constructs a rectangle with topLeft as the top left corner and size as the rectangle size.

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

Constructs a rectangle with the top, left corner and width and height.

Example (creates three identical rectangles):

    QRect r1( QPoint(100,200), QPoint(110,215) );
    QRect r2( QPoint(100,200), QSize(11,16) );
    QRect r3( 100, 200, 11, 16 );

int QRect::bottom () const

Returns the bottom coordinate of the rectangle.

See also top(), setBottom(), bottomLeft() and bottomRight().

Examples: desktop/desktop.cpp

QPoint QRect::bottomLeft () const

Returns the bottom left position of the rectangle.

See also moveBottomLeft(), bottomRight(), topLeft(), topRight(), bottom() and left().

QPoint QRect::bottomRight () const

Returns the bottom right position of the rectangle.

See also moveBottomRight(), bottomLeft(), topLeft(), topRight(), bottom() and right().

QPoint QRect::center () const

Returns the center point of the rectangle.

See also moveCenter(), topLeft(), topRight(), bottomLeft() and bottomRight().

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

Returns TRUE if the point p is inside or on the edge of the rectangle.

If proper is TRUE, this function returns TRUE only if p is inside (not on the edge).

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

Returns TRUE if the rectangle r is inside this rectangle.

If proper is TRUE, this function returns TRUE only if r is entirely inside (not on the edge).

See also unite(), intersect() and intersects().

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

\overload bool QRect::contains( const QPoint &p, bool proper ) const.

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

Extracts the rectangle parameters as the top left point and the bottom right point.

See also setCoords() and rect().

int QRect::height () const

Returns the height of the rectangle. The height includes both the top and bottom edges, ie. height = bottom - top + 1.

See also width(), size() and setHeight().

Examples: movies/main.cpp xform/xform.cpp desktop/desktop.cpp

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

 r.intersect(s)
is equivalent to
 r&s
.

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

Returns TRUE if this rectangle intersects with r (there is at least one pixel which is within both rectangles).

See also intersect() and contains().

bool QRect::isEmpty () const

Returns TRUE if the rectangle is empty, otherwise FALSE.

An empty rectangle has a left() > right() or top() > bottom().

An empty rectangle is not valid.

 isEmpty() == !isValid()

See also isNull() and isValid().

bool QRect::isNull () const

Returns TRUE if the rectangle is a null rectangle, otherwise FALSE.

A null rectangle has both the width and the height set to 0, that is right() == left() - 1 and bottom() == top() - 1.

Remember that if right() == left() and bottom() == top(), then the rectangle has width 1 and height 1.

A null rectangle is also empty.

A null rectangle is not valid.

See also isEmpty() and isValid().

bool QRect::isValid () const

Returns TRUE if the rectangle is valid, or FALSE if it is invalid (empty).

A valid rectangle has a left() <= right() and top() <= bottom().

 isValid() == !isEmpty()

See also isNull(), isEmpty() and normalize().

int QRect::left () const

Returns the left coordinate of the rectangle. Identical to x().

See also x(), top(), right(), setLeft(), topLeft() and bottomLeft().

Examples: xform/xform.cpp desktop/desktop.cpp

void QRect::moveBottomLeft ( const QPoint & p )

Sets the bottom left position of the rectangle to p, leaving the size unchanged.

See also bottomLeft(), moveBottomRight(), moveTopLeft(), moveTopRight(), setBottom() and setLeft().

void QRect::moveBottomRight ( const QPoint & p )

Sets the bottom right position of the rectangle to p, leaving the size unchanged.

See also bottomRight(), moveBottomLeft(), moveTopLeft(), moveTopRight(), setBottom() and setRight().

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

Moves the rectangle dx along the X axis and dy along the Y axis, relative to the current position. (Positive values moves the rectangle rightwards and/or downwards.).

Examples: xform/xform.cpp

void QRect::moveCenter ( const QPoint & p )

Sets the center point of the rectangle to p, leaving the size unchanged.

See also center(), moveTopLeft(), moveTopRight(), moveBottomLeft() and moveBottomRight().

void QRect::moveTopLeft ( const QPoint & p )

Sets the top left position of the rectangle to p, leaving the size unchanged.

See also topLeft(), moveTopRight(), moveBottomLeft(), moveBottomRight(), setTop() and setLeft().

Examples: xform/xform.cpp

void QRect::moveTopRight ( const QPoint & p )

Sets the top right position of the rectangle to p, leaving the size unchanged.

See also topRight(), moveTopLeft(), moveBottomLeft(), moveBottomRight(), setTop() and setRight().

QRect QRect::normalize () const

Returns a normalized rectangle, i.e. one that has a non-negative width and height.

It swaps left and right if left() > right(), and swaps top and bottom if top() > bottom().

See also isValid().

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

Returns the intersection of this rectangle and r.

Returns an empty rectangle if there is no intersection.

See also operator&=(), operator|(), isEmpty(), intersects() and contains().

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

Intersects this rectangle with r.

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

Returns the bounding rectangle of this and r.

The bounding rectangle of a nonempty rectangle and an empty or invalid rectangle is defined to be the nonempty rectangle.

See also operator|=(), operator&(), intersects() and contains().

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

Unites this rectangle with r.

QCOORD & QRect::rBottom ()

Returns the reference to the bottom coordinate of the rectangle.

See also rLeft(), rTop() and rRight().

QCOORD & QRect::rLeft ()

Returns the reference to the left coordinate of the rectangle.

See also rTop(), rRight() and rBottom().

QCOORD & QRect::rRight ()

Returns the reference to the right coordinate of the rectangle.

See also rLeft(), rTop() and rBottom().

QCOORD & QRect::rTop ()

Returns the reference to the top coordinate of the rectangle.

See also rLeft(), rRight() and rBottom().

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

Extracts the rectangle parameters as the position and the size.

See also setRect() and coords().

int QRect::right () const

Returns the right coordinate of the rectangle.

See also left(), setRight(), topRight() and bottomRight().

Examples: desktop/desktop.cpp

void QRect::setBottom ( int pos )

Sets the bottom edge of the rectangle. May change the height, but will never change the top edge of the rectangle.

See also bottom(), setTop() and setHeight().

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

Sets the coordinates of the rectangle's top left corner to (xp1,yp1), and the coordinates of its bottom right corner to (xp2,yp2).

See also coords() and setRect().

void QRect::setHeight ( int h )

Sets the height of the rectangle to h. The top edge is not moved, but the bottom edge may be moved.

See also height(), setTop(), setBottom() and setSize().

Examples: desktop/desktop.cpp

void QRect::setLeft ( int pos )

Sets the left edge of the rectangle. May change the width, but will never change the right edge of the rectangle.

Identical to setX().

See also left(), setTop() and setWidth().

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

Sets the coordinates of the rectangle's top left corner to (x,y), and its size to (w,h).

See also rect() and setCoords().

void QRect::setRight ( int pos )

Sets the right edge of the rectangle. May change the width, but will never change the left edge of the rectangle.

See also right(), setLeft() and setWidth().

void QRect::setSize ( const QSize & s )

Sets the size of the rectangle to s. The top left corner is not moved.

See also size(), setWidth() and setHeight().

Examples: xform/xform.cpp

void QRect::setTop ( int pos )

Sets the top edge of the rectangle. May change the height, but will never change the bottom edge of the rectangle.

Identical to setY().

See also top(), setBottom() and setHeight().

void QRect::setWidth ( int w )

Sets the width of the rectangle to w. The right edge is changed, but not the left edge.

See also width(), setLeft(), setRight() and setSize().

Examples: desktop/desktop.cpp

void QRect::setX ( int x )

Sets the x position of the rectangle (its left end). May change the width, but will never change the right edge of the rectangle.

Identical to setLeft().

See also x() and setY().

void QRect::setY ( int y )

Sets the y position of the rectangle (its top). May change the height, but will never change the bottom edge of the rectangle.

Identical to setTop().

See also y() and setX().

QSize QRect::size () const

Returns the size of the rectangle.

See also width() and height().

Examples: movies/main.cpp desktop/desktop.cpp

int QRect::top () const

Returns the top coordinate of the rectangle. Identical to y().

See also y(), left(), bottom(), setTop(), topLeft() and topRight().

Examples: xform/xform.cpp desktop/desktop.cpp

QPoint QRect::topLeft () const

Returns the top left position of the rectangle.

See also moveTopLeft(), topRight(), bottomLeft(), bottomRight(), left() and top().

QPoint QRect::topRight () const

Returns the top right position of the rectangle.

See also moveTopRight(), topLeft(), bottomLeft(), bottomRight(), top() and right().

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

 r.unite(s)
is equivalent to
 r|s
.

Examples: xform/xform.cpp

int QRect::width () const

Returns the width of the rectangle. The width includes both the left and right edges, ie. width = right - left + 1.

See also height(), size() and setHeight().

Examples: movies/main.cpp xform/xform.cpp desktop/desktop.cpp

int QRect::x () const

Returns the left coordinate of the rectangle. Identical to left().

See also left(), y() and setX().

Examples: movies/main.cpp xform/xform.cpp desktop/desktop.cpp

int QRect::y () const

Returns the top coordinate of the rectangle. Identical to top().

See also top(), x() and setY().

Examples: movies/main.cpp xform/xform.cpp desktop/desktop.cpp


Related Functions

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

Returns TRUE if r1 and r2 are equal, or FALSE if they are different.

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

Reads a QRect from the stream and returns a reference to the stream.

See also Format of the QDataStream operators

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

Writes a QRect to the stream and returns a reference to the stream.

See also Format of the QDataStream operators

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

Returns TRUE if r1 and r2 are different, or FALSE if they are equal.


Search the documentation, FAQ, qt-interest archive and more (uses www.trolltech.com):


This file is part of the Qt toolkit, copyright © 1995-2005 Trolltech, all rights reserved.

Publicité

Best Of

Actualités les plus lues

Semaine
Mois
Année
  1. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 94
  2. Apercevoir la troisième dimension ou l'utilisation multithreadée d'OpenGL dans Qt, un article des Qt Quarterly traduit par Guillaume Belz 0
  3. Les développeurs ignorent-ils trop les failles découvertes dans leur code ? Prenez-vous en compte les remarques des autres ? 17
  4. Pourquoi les programmeurs sont-ils moins payés que les gestionnaires de programmes ? Manquent-ils de pouvoir de négociation ? 42
  5. Quelles nouveautés de C++11 Visual C++ doit-il rapidement intégrer ? Donnez-nous votre avis 10
  6. Adieu qmake, bienvenue qbs : Qt Building Suite, un outil déclaratif et extensible pour la compilation de projets Qt 17
  7. 2017 : un quinquennat pour une nouvelle version du C++ ? Possible, selon Herb Sutter 6
Page suivante

Le Qt Quarterly au hasard

Logo

Requêtes sérieuses avec XQuery

Qt Quarterly est la revue trimestrielle proposée par Nokia et à destination des développeurs Qt. Ces articles d'une grande qualité technique sont rédigés par des experts Qt. Lire l'article.

Communauté

Ressources

Liens utiles

Contact

  • Vous souhaitez rejoindre la rédaction ou proposer un tutoriel, une traduction, une question... ? Postez dans le forum Contribuez ou contactez-nous par MP ou par email (voir en bas de page).

Qt dans le magazine

Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. Qt 2.3
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD.
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP !
 
 
 
 
Partenaires

Hébergement Web