IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)

QPen Class

The https:// class defines how a https:// should draw lines and outlines of shapes.

Article lu   fois.

L'auteur

Liens sociaux

Viadeo Twitter Facebook Share on Google+   

QPen Class▲

  • Header: QPen

  • CMake:

    find_package(Qt6 REQUIRED COMPONENTS Gui)

    target_link_libraries(mytarget PRIVATE Qt6::Gui)

  • qmake: QT += gui

  • Group: QPen is part of https://, shared

Detailed Description▲

A pen has a https://(), https://(), https://(), https://() and https://().

The pen style defines the line type. The brush is used to fill strokes generated with the pen. Use the https:// class to specify fill styles. The cap style determines the line end caps that can be drawn using https://, while the join style describes how joins between two lines are drawn. The pen width can be specified in both integer (https://()) and floating point (https://()) precision. A line width of zero indicates a cosmetic pen. This means that the pen width is always drawn one pixel wide, independent of the https:// set on the painter.

The various settings can easily be modified using the corresponding https://(), https://(), https://(), https://() and https://() functions (note that the painter's pen must be reset when altering the pen's properties).

For example:

 
Sélectionnez
QPainter painter(this);
QPen pen(Qt::green, 3, Qt::DashDotLine, Qt::RoundCap, Qt::RoundJoin);
painter.setPen(pen);

which is equivalent to

 
Sélectionnez
QPainter painter(this);
QPen pen;  // creates a default pen

pen.setStyle(Qt::DashDotLine);
pen.setWidth(3);
pen.setBrush(Qt::green);
pen.setCapStyle(Qt::RoundCap);
pen.setJoinStyle(Qt::RoundJoin);

painter.setPen(pen);

The default pen is a solid black brush with 1 width, square cap style (https://), and bevel join style (https://).

In addition https:// provides the https://() and https://() convenience functions to extract and set the color of the pen's brush, respectively. Pens may also be compared and streamed.

For more information about painting in general, see the https:// documentation.

Pen Style▲

Qt provides several built-in styles represented by the https:// enum:

Image non disponible

Image non disponible

Image non disponible

https://

https://

https://

Image non disponible

Image non disponible

Image non disponible

https://

https://

https://

Simply use the https://() function to convert the pen style to either of the built-in styles, except the https:// style which we will come back to shortly. Setting the style to https:// tells the painter to not draw lines or outlines. The default pen style is https://.

Since Qt 4.1 it is also possible to specify a custom dash pattern using the https://() function which implicitly converts the style of the pen to https://. The pattern argument, a https://, must be specified as an even number of https:// entries where the entries 1, 3, 5... are the dashes and 2, 4, 6... are the spaces. For example, the custom pattern shown above is created using the following code:

 
Sélectionnez
QPen pen;
QList<qreal> dashes;
qreal space = 4;

dashes << 1 << space << 3 << space << 9 << space
           << 27 << space << 9 << space;

pen.setDashPattern(dashes);

Note that the dash pattern is specified in units of the pens width, e.g. a dash of length 5 in width 10 is 50 pixels long.

The currently set dash pattern can be retrieved using the https://() function. Use the https://() function to determine whether the pen has a solid fill, or not.

Cap Style▲

The cap style defines how the end points of lines are drawn using https://. The cap style only apply to wide lines, i.e. when the width is 1 or greater. The https:// enum provides the following styles:

Image non disponible

Image non disponible

Image non disponible

https://

https://

https://

The https:// style is a square line end that covers the end point and extends beyond it by half the line width. The https:// style is a square line end that does not cover the end point of the line. And the https:// style is a rounded line end covering the end point.

The default is https://.

Whether or not end points are drawn when the pen width is 0 or 1 depends on the cap style. Using https:// or https:// they are drawn, using https:// they are not drawn.

Join Style▲

The join style defines how joins between two connected lines can be drawn using https://. The join style only apply to wide lines, i.e. when the width is 1 or greater. The https:// enum provides the following styles:

Image non disponible

Image non disponible

Image non disponible

https://

https://

https://

The https:// style fills the triangular notch between the two lines. The https:// style extends the lines to meet at an angle. And the https:// style fills a circular arc between the two lines.

The default is https://.

Image non disponible

When the https:// style is applied, it is possible to use the https://() function to specify how far the miter join can extend from the join point. The https://() is used to reduce artifacts between line joins where the lines are close to parallel.

The https://() must be specified in units of the pens width, e.g. a miter limit of 5 in width 10 is 50 pixels long. The default miter limit is 2, i.e. twice the pen width in pixels.

Image non disponible

The Path Stroking Example

The Path Stroking example shows Qt's built-in dash patterns and shows how custom patterns can be used to extend the range of available patterns.

See Also▲

See also https://, https://, Path Stroking Example, Scribble Example

Member Function Documentation▲

 

QPen::QPen()▲

Constructs a default black solid line pen with 1 width.

QPen::QPen(Qt::PenStyle style)▲

Constructs a black pen with 1 width and the given style.

See Also▲

See also https://()

QPen::QPen(const QColor &color)▲

Constructs a solid line pen with 1 width and the given color.

See Also▲

See also https://(), https://()

QPen::QPen(const QBrush &brush, qreal width, Qt::PenStyle style = Qt::SolidLine, Qt::PenCapStyle cap = Qt::SquareCap, Qt::PenJoinStyle join = Qt::BevelJoin)▲

Constructs a pen with the specified brush, width, pen style, cap style and join style.

See Also▲

See also https://(), https://(), https://(), https://(), https://()

QPen::QPen(const QPen &pen)▲

Constructs a pen that is a copy of the given pen.

[since 5.4] QPen::QPen(QPen &&pen)▲

Constructs a pen that is moved from the given pen.

The moved-from pen can only be assigned to, copied, or destroyed. Any other operation (prior to assignment) leads to undefined behavior.

This function was introduced in Qt 5.4.

QPen::~QPen()▲

Destroys the pen.

QBrush QPen::brush() const▲

Returns the brush used to fill strokes generated with this pen.

See Also▲

See also https://()

Qt::PenCapStyle QPen::capStyle() const▲

Returns the pen's cap style.

See Also▲

See also https://(), https://

QColor QPen::color() const▲

Returns the color of this pen's brush.

See Also▲

See also https://(), https://()

qreal QPen::dashOffset() const▲

Returns the dash offset for the pen.

See Also▲

See also https://()

QList<qreal> QPen::dashPattern() const▲

Returns the dash pattern of this pen.

See Also▲

See also https://(), https://(), https://()

bool QPen::isCosmetic() const▲

Returns true if the pen is cosmetic; otherwise returns false.

Cosmetic pens are used to draw strokes that have a constant width regardless of any transformations applied to the https:// they are used with. Drawing a shape with a cosmetic pen ensures that its outline will have the same thickness at different scale factors.

A zero width pen is cosmetic by default.

See Also▲

See also https://(), https://()

bool QPen::isSolid() const▲

Returns true if the pen has a solid fill, otherwise false.

See Also▲

See also https://(), https://()

Qt::PenJoinStyle QPen::joinStyle() const▲

Returns the pen's join style.

See Also▲

See also https://(), https://

qreal QPen::miterLimit() const▲

Returns the miter limit of the pen. The miter limit is only relevant when the join style is set to https://.

See Also▲

See also https://(), https://

void QPen::setBrush(const QBrush &brush)▲

Sets the brush used to fill strokes generated with this pen to the given brush.

See Also▲

See also https://(), https://()

void QPen::setCapStyle(Qt::PenCapStyle style)▲

Sets the pen's cap style to the given style. The default value is https://.

See Also▲

See also https://(), https://

void QPen::setColor(const QColor &color)▲

Sets the color of this pen's brush to the given color.

See Also▲

See also https://(), https://()

void QPen::setCosmetic(bool cosmetic)▲

Sets this pen to cosmetic or non-cosmetic, depending on the value of cosmetic.

See Also▲

See also https://()

void QPen::setDashOffset(qreal offset)▲

Sets the dash offset (the starting point on the dash pattern) for this pen to the offset specified. The offset is measured in terms of the units used to specify the dash pattern.

Image non disponible

For example, a pattern where each stroke is four units long, followed by a gap of two units, will begin with the stroke when drawn as a line.

However, if the dash offset is set to 4.0, any line drawn will begin with the gap. Values of the offset up to 4.0 will cause part of the stroke to be drawn first, and values of the offset between 4.0 and 6.0 will cause the line to begin with part of the gap.

This implicitly converts the style of the pen to https://.

See Also▲

See also https://()

void QPen::setDashPattern(const QList<qreal> &pattern)▲

Sets the dash pattern for this pen to the given pattern. This implicitly converts the style of the pen to https://.

The pattern must be specified as an even number of positive entries where the entries 1, 3, 5... are the dashes and 2, 4, 6... are the spaces. For example:

Image non disponible

 
Sélectionnez
QPen pen;
QList&lt;qreal&gt; dashes;
qreal space = 4;
dashes &lt;&lt; 1 &lt;&lt; space &lt;&lt; 3 &lt;&lt; space &lt;&lt; 9 &lt;&lt; space
           &lt;&lt; 27 &lt;&lt; space &lt;&lt; 9 &lt;&lt; space;
pen.setDashPattern(dashes);

The dash pattern is specified in units of the pens width; e.g. a dash of length 5 in width 10 is 50 pixels long. Note that a pen with zero width is equivalent to a cosmetic pen with a width of 1 pixel.

Each dash is also subject to cap styles so a dash of 1 with square cap set will extend 0.5 pixels out in each direction resulting in a total width of 2.

Note that the default cap style is https://, meaning that a square line end covers the end point and extends beyond it by half the line width.

See Also▲

See also https://(), https://(), https://(), https://()

void QPen::setJoinStyle(Qt::PenJoinStyle style)▲

Sets the pen's join style to the given style. The default value is https://.

See Also▲

See also https://(), https://

void QPen::setMiterLimit(qreal limit)▲

Sets the miter limit of this pen to the given limit.

Image non disponible

The miter limit describes how far a miter join can extend from the join point. This is used to reduce artifacts between line joins where the lines are close to parallel.

This value does only have effect when the pen style is set to https://. The value is specified in units of the pen's width, e.g. a miter limit of 5 in width 10 is 50 pixels long. The default miter limit is 2, i.e. twice the pen width in pixels.

See Also▲

See also https://(), https://(), https://

void QPen::setStyle(Qt::PenStyle style)▲

Sets the pen style to the given style.

See the https:// documentation for a list of the available styles. Since Qt 4.1 it is also possible to specify a custom dash pattern using the https://() function which implicitly converts the style of the pen to https://.

This function resets the dash offset to zero.

See Also▲

See also https://(), https://

void QPen::setWidth(int width)▲

Sets the pen width to the given width in pixels with integer precision.

A line width of zero indicates a cosmetic pen. This means that the pen width is always drawn one pixel wide, independent of the https:// set on the painter.

Setting a pen width with a negative value is not supported.

See Also▲

See also https://(), https://()

void QPen::setWidthF(qreal width)▲

Sets the pen width to the given width in pixels with floating point precision.

A line width of zero indicates a cosmetic pen. This means that the pen width is always drawn one pixel wide, independent of the https:// on the painter.

Setting a pen width with a negative value is not supported.

See Also▲

See also https://(), https://()

Qt::PenStyle QPen::style() const▲

Returns the pen style.

See Also▲

See also https://(), https://

void QPen::swap(QPen &other)▲

Swaps pen other with this pen. This operation is very fast and never fails.

int QPen::width() const▲

Returns the pen width with integer precision.

See Also▲

See also https://(), https://()

qreal QPen::widthF() const▲

Returns the pen width with floating point precision.

See Also▲

See also https://(), https://()

QVariant QPen::operator QVariant() const▲

Returns the pen as a https://.

bool QPen::operator!=(const QPen &pen) const▲

Returns true if the pen is different from the given pen; otherwise false. Two pens are different if they have different styles, widths or colors.

See Also▲

See also https://()

QPen &QPen::operator=(const QPen &pen)▲

Assigns the given pen to this pen and returns a reference to this pen.

[since 5.2] QPen &QPen::operator=(QPen &&other)▲

Move-assigns other to this https:// instance.

This function was introduced in Qt 5.2.

bool QPen::operator==(const QPen &pen) const▲

Returns true if the pen is equal to the given pen; otherwise false. Two pens are equal if they have equal styles, widths and colors.

See Also▲

See also https://()

Related Non-Members▲

 

QDataStream &operator<<(QDataStream &stream, const QPen &pen)▲

Writes the given pen to the given stream and returns a reference to the stream.

See Also▲

See also https://

QDataStream &operator>>(QDataStream &stream, QPen &pen)▲

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

See Also▲

See also https://

Vous avez aimé ce tutoriel ? Alors partagez-le en cliquant sur les boutons suivants : Viadeo Twitter Facebook Share on Google+   

Ce document est disponible sous la licence https:// telle que publiée par la Free Software Foundation.