QPen Class Reference


The QPen class defines how the QPainter should draw lines and outlines of shapes. (details) (complete member list)

#include <qpen.h>

Public Members

Related Functions

(Note that these are not member functions.)

Detailed Description

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

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

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

The pen width defines the line width. The default line width is 0, which draws a 1-pixel line very fast, but not so accurate. Setting the line width to 1 or more draws lines that are precise, but drawing is slower.

The line color defines the color of lines and text. The default line color is black. The QColor documentation contains a list of standard colors.

Use the QBrush class for specifying fill styles.

Example of how to use a pen:

  QPainter painter;
  QPen     pen( red );                  // red solid line, 0 width
  painter.begin( &anyPaintDevice );     // paint widget, pixmap etc.
  painter.setPen( pen );                // sets the red pen
  painter.drawRect( 40,30, 200,100 );   // draw 200x100 rect at (40,30)
  painter.pen().setColor( blue );       // change pen color to blue
  painter.drawLine( 40,30, 240,130 );   // draw diagonal in rectangle
  painter.end();                        // painting done

The setStyle() function has a list of pen styles.


Member Function Documentation

QPen::QPen ()

Constructs a default black solid line pen with 0 width.

QPen::QPen (PenStyle style)

Constructs a pen black with 0 width and a specified style.

See also: setStyle().

QPen::QPen (const QColor &color, uint width=0, PenStyle style=SolidLine)

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

QPen::QPen (const QPen &p)

Constructs a pen which is a shallow copy of p.

QPen::~QPen ()

Destroys the pen.

QColor QPen::color () const

Returns the pen color.

See also: setColor().

QPen QPen::copy () const

Returns a deep copy of the pen.

void QPen::detach ()

Detaches from shared pen data to makes sure that this pen is the only one referring the data.

If multiple pens share common data, this pen dereferences the data and gets a copy of the data. Nothing will be done if there is just a single reference.

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

Returns TRUE if the pen is different from p, or FALSE if the pens are equal.

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

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

Assigns a shallow copy of p to the pen and returns a reference to this pen.

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

Returns TRUE if the pen is equal to p, or FALSE if the pens are different.

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

PenStyle QPen::style () const

Returns the pen style.

See also: setStyle().

uint QPen::width () const

Returns the pen width.

See also: setWidth().


Related Functions

QDataStream & operator<< (QDataStream &s, const QPen &p)

Writes a pen to the stream.

QDataStream & operator>> (QDataStream &s, QPen &p)

Reads a pen from the stream.


This file is part of the Qt toolkit, copyright 1995 Troll Tech, all rights reserved.

It was generated from the following files:


Generated at 04:27, 1995/05/20 by the webmaster at Troll Tech