Eneboo - Documentación para desarrolladores
Clases | Métodos públicos | Amigas | Funciones relacionadas
Referencia de la Clase QPen

The QPen class defines how a QPainter should draw lines and outlines of shapes. Más...

#include <qpen.h>

Diagrama de herencias de QPen
Qt Qt

Lista de todos los miembros.

Clases

struct  QPenData

Métodos públicos

 QPen ()
 QPen (PenStyle)
 QPen (const QColor &color, uint width=0, PenStyle style=SolidLine)
 QPen (const QColor &cl, uint w, PenStyle s, PenCapStyle c, PenJoinStyle j)
 QPen (const QPen &)
 ~QPen ()
QPenoperator= (const QPen &)
PenStyle style () const
void setStyle (PenStyle)
uint width () const
void setWidth (uint)
const QColorcolor () const
void setColor (const QColor &)
PenCapStyle capStyle () const
void setCapStyle (PenCapStyle)
PenJoinStyle joinStyle () const
void setJoinStyle (PenJoinStyle)
bool operator== (const QPen &p) const
bool operator!= (const QPen &p) const
 QPen ()
 QPen (PenStyle)
 QPen (const QColor &color, uint width=0, PenStyle style=SolidLine)
 QPen (const QColor &cl, uint w, PenStyle s, PenCapStyle c, PenJoinStyle j)
 QPen (const QPen &)
 ~QPen ()
QPenoperator= (const QPen &)
PenStyle style () const
void setStyle (PenStyle)
uint width () const
void setWidth (uint)
const QColorcolor () const
void setColor (const QColor &)
PenCapStyle capStyle () const
void setCapStyle (PenCapStyle)
PenJoinStyle joinStyle () const
void setJoinStyle (PenJoinStyle)
bool operator== (const QPen &p) const
bool operator!= (const QPen &p) const

Amigas

class QPainter

Funciones relacionadas

(Observar que estas no son funciones miembro.)

QDataStreamoperator<< (QDataStream &s, const QPen &p)
QDataStreamoperator>> (QDataStream &s, QPen &p)

Descripción detallada

The QPen class defines how a QPainter should draw lines and outlines of shapes.

A pen has a style, width, color, cap style and join style.

The pen style defines the line type. The default pen style is Qt::SolidLine. Setting the style to NoPen tells the painter to not draw lines or outlines.

When drawing 1 pixel wide diagonal lines you can either use a very fast algorithm (specified by a line width of 0, which is the default), or a slower but more accurate algorithm (specified by a line width of 1). For horizontal and vertical lines a line width of 0 is the same as a line width of 1. The cap and join style have no effect on 0-width lines.

The pen color defines the color of lines and text. The default line color is black. The QColor documentation lists predefined colors.

The cap style defines how the end points of lines are drawn. The join style defines how the joins between two lines are drawn when multiple connected lines are drawn (QPainter::drawPolyline() etc.). The cap and join styles only apply to wide lines, i.e. when the width is 1 or greater.

Use the QBrush class to specify fill styles.

Example:

    QPainter painter;
    QPen     pen( red, 2 );             // red solid line, 2 pixels wide
    painter.begin( &anyPaintDevice );   // paint something
    painter.setPen( pen );              // set the red, wide pen
    painter.drawRect( 40,30, 200,100 ); // draw a rectangle
    painter.setPen( blue );             // set blue pen, 0 pixel width
    painter.drawLine( 40,30, 240,130 ); // draw a diagonal in rectangle
    painter.end();                      // painting done

See the Qt::PenStyle enum type for a complete list of pen styles.

With reference to the end points of lines, for wide (non-0-width) pens it depends on the cap style whether the end point is drawn or not. QPainter will try to make sure that the end point is drawn for 0-width pens, but this cannot be absolutely guaranteed because the underlying drawing engine is free to use any (typically accelerated) algorithm for drawing 0-width lines. On all tested systems, however, the end point of at least all non-diagonal lines are drawn.

A pen's color(), width(), style(), capStyle() and joinStyle() can be set in the constructor or later with setColor(), setWidth(), setStyle(), setCapStyle() and setJoinStyle(). Pens may also be compared and streamed.

pen-styles.png Pen styles

Ver también:
QPainter, QPainter::setPen()

Documentación del constructor y destructor

QPen::QPen ( )

Constructs a default black solid line pen with 0 width, which renders lines 1 pixel wide (fast diagonals).

QPen::QPen ( PenStyle  style)

Constructs a black pen with 0 width (fast diagonals) and style style.

Ver también:
setStyle()
QPen::QPen ( const QColor color,
uint  width = 0,
PenStyle  style = SolidLine 
)

Constructs a pen with the specified color, width and style.

Ver también:
setWidth(), setStyle(), setColor()
QPen::QPen ( const QColor cl,
uint  w,
PenStyle  s,
PenCapStyle  c,
PenJoinStyle  j 
)

Constructs a pen with the specified color cl and width w. The pen style is set to s, the pen cap style to c and the pen join style to j.

A line width of 0 will produce a 1 pixel wide line using a fast algorithm for diagonals. A line width of 1 will also produce a 1 pixel wide line, but uses a slower more accurate algorithm for diagonals. For horizontal and vertical lines a line width of 0 is the same as a line width of 1. The cap and join style have no effect on 0-width lines.

Ver también:
setWidth(), setStyle(), setColor()
QPen::QPen ( const QPen p)

Constructs a pen that is a copy of p.

QPen::~QPen ( )

Destroys the pen.

QPen::QPen ( )
QPen::QPen ( PenStyle  )
QPen::QPen ( const QColor color,
uint  width = 0,
PenStyle  style = SolidLine 
)
QPen::QPen ( const QColor cl,
uint  w,
PenStyle  s,
PenCapStyle  c,
PenJoinStyle  j 
)
QPen::QPen ( const QPen )
QPen::~QPen ( )

Documentación de las funciones miembro

Qt::PenCapStyle QPen::capStyle ( ) const

Returns the pen's cap style.

Ver también:
setCapStyle()
PenCapStyle QPen::capStyle ( ) const
const QColor& QPen::color ( ) const [inline]
const QColor & QPen::color ( ) const [inline]

Returns the pen color.

Ver también:
setColor()
Qt::PenJoinStyle QPen::joinStyle ( ) const

Returns the pen's join style.

Ver también:
setJoinStyle()
PenJoinStyle QPen::joinStyle ( ) const
bool QPen::operator!= ( const QPen p) const [inline]

Returns TRUE if the pen is different from p; otherwise returns FALSE.

Two pens are different if they have different styles, widths or colors.

Ver también:
operator==()
bool QPen::operator!= ( const QPen p) const [inline]
QPen & QPen::operator= ( const QPen p)

Assigns p to this pen and returns a reference to this pen.

QPen& QPen::operator= ( const QPen )
bool QPen::operator== ( const QPen p) const

Returns TRUE if the pen is equal to p; otherwise returns FALSE.

Two pens are equal if they have equal styles, widths and colors.

Ver también:
operator!=()
bool QPen::operator== ( const QPen p) const
void QPen::setCapStyle ( PenCapStyle  c)

Sets the pen's cap style to c.

The default value is FlatCap. The cap style has no effect on 0-width pens.

pen-cap-styles.png Pen Cap Styles

Atención:
On Windows 95/98 and Macintosh, the cap style setting has no effect. Wide lines are rendered as if the cap style was SquareCap.
Ver también:
capStyle()
void QPen::setCapStyle ( PenCapStyle  )
void QPen::setColor ( const QColor )
void QPen::setColor ( const QColor c)

Sets the pen color to c.

Ver también:
color()
void QPen::setJoinStyle ( PenJoinStyle  j)

Sets the pen's join style to j.

The default value is MiterJoin. The join style has no effect on 0-width pens.

pen-join-styles.png Pen Join Styles

Atención:
On Windows 95/98 and Macintosh, the join style setting has no effect. Wide lines are rendered as if the join style was BevelJoin.
Ver también:
joinStyle()
void QPen::setJoinStyle ( PenJoinStyle  )
void QPen::setStyle ( PenStyle  )
void QPen::setStyle ( PenStyle  s)

Sets the pen style to s.

See the Qt::PenStyle documentation for a list of all the styles.

Atención:
On Mac OS X the style setting (other than NoPen and SolidLine) have no effect as they are not implemented by the underlying system.
On Windows 95/98, the style setting (other than NoPen and SolidLine) has no effect for lines with width greater than 1.
Ver también:
style()
void QPen::setWidth ( uint  )
void QPen::setWidth ( uint  w)

Sets the pen width to w.

A line width of 0 will produce a 1 pixel wide line using a fast algorithm for diagonals. A line width of 1 will also produce a 1 pixel wide line, but uses a slower more accurate algorithm for diagonals. For horizontal and vertical lines a line width of 0 is the same as a line width of 1. The cap and join style have no effect on 0-width lines.

Ver también:
width()
PenStyle QPen::style ( ) const [inline]
PenStyle QPen::style ( ) const [inline]

Returns the pen style.

Ver también:
setStyle()
uint QPen::width ( ) const [inline]

Returns the pen width.

Ver también:
setWidth()
uint QPen::width ( ) const [inline]

Documentación de las funciones relacionadas y clases amigas

QDataStream & operator<< ( QDataStream s,
const QPen p 
) [related]

Writes the pen p to the stream s and returns a reference to the stream.

Ver también:
Format of the QDataStream operators
QDataStream & operator>> ( QDataStream s,
QPen p 
) [related]

Reads a pen from the stream s into p and returns a reference to the stream.

Ver también:
Format of the QDataStream operators
QPainter [friend]

La documentación para esta clase fue generada a partir de los siguientes ficheros:
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'