Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions

TQPen Class Reference

The TQPen class defines how a TQPainter should draw lines and outlines of shapes. More...

#include <tqpen.h>

Inherits TQt.

List of all member functions.

Public Members

Related Functions


Detailed Description

The TQPen class defines how a TQPainter 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 TQt::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 TQColor 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 (TQPainter::drawPolyline() etc.). The cap and join styles only apply to wide lines, i.e. when the width is 1 or greater.

Use the TQBrush class to specify fill styles.

Example:

    TQPainter painter;
    TQPen     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 TQt::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. TQPainter 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

See also TQPainter, TQPainter::setPen(), Graphics Classes, Image Processing Classes, and Implicitly and Explicitly Shared Classes.


Member Function Documentation

TQPen::TQPen ()

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

TQPen::TQPen ( PenStyle style )

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

See also setStyle().

TQPen::TQPen ( const TQColor & color, uint width = 0, PenStyle style = SolidLine )

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

See also setWidth(), setStyle(), and setColor().

TQPen::TQPen ( const TQColor & 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.

See also setWidth(), setStyle(), and setColor().

TQPen::TQPen ( const TQPen & p )

Constructs a pen that is a copy of p.

TQPen::~TQPen ()

Destroys the pen.

PenCapStyle TQPen::capStyle () const

Returns the pen's cap style.

See also setCapStyle().

const TQColor & TQPen::color () const

Returns the pen color.

See also setColor().

Example: scribble/scribble.h.

PenJoinStyle TQPen::joinStyle () const

Returns the pen's join style.

See also setJoinStyle().

bool TQPen::operator!= ( const TQPen & p ) const

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

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

See also operator==().

TQPen & TQPen::operator= ( const TQPen & p )

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

bool TQPen::operator== ( const TQPen & 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.

See also operator!=().

void TQPen::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

Warning: On Windows 95/98 and Macintosh, the cap style setting has no effect. Wide lines are rendered as if the cap style was SquareCap.

See also capStyle().

Example: themes/wood.cpp.

void TQPen::setColor ( const TQColor & c )

Sets the pen color to c.

See also color().

Examples: progress/progress.cpp and scribble/scribble.h.

void TQPen::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

Warning: On Windows 95/98 and Macintosh, the join style setting has no effect. Wide lines are rendered as if the join style was BevelJoin.

See also joinStyle().

Example: themes/wood.cpp.

void TQPen::setStyle ( PenStyle s )

Sets the pen style to s.

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

Warning: On Mac OS X the style setting (other than NoPen and SolidLine) have no effect as they are not implemented by the underlying system.

Warning: On Windows 95/98, the style setting (other than NoPen and SolidLine) has no effect for lines with width greater than 1.

See also style().

Example: chart/chartform_canvas.cpp.

void TQPen::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.

See also width().

Examples: progress/progress.cpp, and scribble/scribble.h.

PenStyle TQPen::style () const

Returns the pen style.

See also setStyle().

uint TQPen::width () const

Returns the pen width.

See also setWidth().

Example: scribble/scribble.h.


Related Functions

TQDataStream & operator<< ( TQDataStream & s, const TQPen & p )

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

See also Format of the TQDataStream operators.

TQDataStream & operator>> ( TQDataStream & s, TQPen & p )

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

See also Format of the TQDataStream operators.


This file is part of the TQt toolkit. Copyright © 1995-2007 Trolltech. All Rights Reserved.


Copyright © 2007 TrolltechTrademarks
TQt 3.3.8