[][src]Struct qt_gui::QPen

#[repr(C)]pub struct QPen { /* fields omitted */ }

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

C++ class: QPen.

C++ documentation:

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

A pen has a style(), width(), brush(), capStyle() and joinStyle().

The pen style defines the line type. The brush is used to fill strokes generated with the pen. Use the QBrush class to specify fill styles. The cap style determines the line end caps that can be drawn using QPainter, while the join style describes how joins between two lines are drawn. The pen width can be specified in both integer (width()) and floating point (widthF()) 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 transformation set on the painter.

The various settings can easily be modified using the corresponding setStyle(), setWidth(), setBrush(), setCapStyle() and setJoinStyle() functions (note that the painter's pen must be reset when altering the pen's properties).

For example:

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

which is equivalent to

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 (Qt::SquareCap), and bevel join style (Qt::BevelJoin).

In addition QPen provides the color() and setColor() 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 Paint System documentation.

Methods

impl QPen[src]

pub unsafe fn brush(&self) -> CppBox<QBrush>[src]

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

Calls C++ function: QBrush QPen::brush() const.

C++ documentation:

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

See also setBrush().

pub unsafe fn cap_style(&self) -> PenCapStyle[src]

Returns the pen's cap style.

Calls C++ function: Qt::PenCapStyle QPen::capStyle() const.

C++ documentation:

Returns the pen's cap style.

See also setCapStyle() and Cap Style.

pub unsafe fn color(&self) -> CppBox<QColor>[src]

Returns the color of this pen's brush.

Calls C++ function: QColor QPen::color() const.

C++ documentation:

Returns the color of this pen's brush.

See also brush() and setColor().

pub unsafe fn copy_from(&self, pen: impl CastInto<Ref<QPen>>) -> Ref<QPen>[src]

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

Calls C++ function: QPen& QPen::operator=(const QPen& pen).

C++ documentation:

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

pub unsafe fn dash_offset(&self) -> c_double[src]

Returns the dash offset for the pen.

Calls C++ function: double QPen::dashOffset() const.

C++ documentation:

Returns the dash offset for the pen.

See also setDashOffset().

pub unsafe fn dash_pattern(&self) -> CppBox<QVectorOfDouble>[src]

Returns the dash pattern of this pen.

Calls C++ function: QVector<double> QPen::dashPattern() const.

C++ documentation:

Returns the dash pattern of this pen.

See also setDashPattern(), style(), and isSolid().

pub unsafe fn is_cosmetic(&self) -> bool[src]

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

Calls C++ function: bool QPen::isCosmetic() const.

C++ documentation:

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 QPainter 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 setCosmetic() and widthF().

pub unsafe fn is_detached(&self) -> bool[src]

Calls C++ function: bool QPen::isDetached().

pub unsafe fn is_solid(&self) -> bool[src]

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

Calls C++ function: bool QPen::isSolid() const.

C++ documentation:

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

See also style() and dashPattern().

pub unsafe fn join_style(&self) -> PenJoinStyle[src]

Returns the pen's join style.

Calls C++ function: Qt::PenJoinStyle QPen::joinStyle() const.

C++ documentation:

Returns the pen's join style.

See also setJoinStyle() and Join Style.

pub unsafe fn miter_limit(&self) -> c_double[src]

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

Calls C++ function: double QPen::miterLimit() const.

C++ documentation:

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

See also setMiterLimit() and Join Style.

pub unsafe fn new() -> CppBox<QPen>[src]

Constructs a default black solid line pen with 1 width.

Calls C++ function: [constructor] void QPen::QPen().

C++ documentation:

Constructs a default black solid line pen with 1 width.

pub unsafe fn from_pen_style(arg1: PenStyle) -> CppBox<QPen>[src]

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

Calls C++ function: [constructor] void QPen::QPen(Qt::PenStyle arg1).

C++ documentation:

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

See also setStyle().

pub unsafe fn from_q_color(color: impl CastInto<Ref<QColor>>) -> CppBox<QPen>[src]

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

Calls C++ function: [constructor] void QPen::QPen(const QColor& color).

C++ documentation:

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

See also setBrush() and setColor().

pub unsafe fn from_q_brush_double_pen_style_pen_cap_style_pen_join_style(
    brush: impl CastInto<Ref<QBrush>>,
    width: c_double,
    s: PenStyle,
    c: PenCapStyle,
    j: PenJoinStyle
) -> CppBox<QPen>
[src]

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

Calls C++ function: [constructor] void QPen::QPen(const QBrush& brush, double width, Qt::PenStyle s = …, Qt::PenCapStyle c = …, Qt::PenJoinStyle j = …).

C++ documentation:

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

See also setBrush(), setWidth(), setStyle(), setCapStyle(), and setJoinStyle().

pub unsafe fn from_q_brush_double_pen_style_pen_cap_style(
    brush: impl CastInto<Ref<QBrush>>,
    width: c_double,
    s: PenStyle,
    c: PenCapStyle
) -> CppBox<QPen>
[src]

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

Calls C++ function: [constructor] void QPen::QPen(const QBrush& brush, double width, Qt::PenStyle s = …, Qt::PenCapStyle c = …).

C++ documentation:

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

See also setBrush(), setWidth(), setStyle(), setCapStyle(), and setJoinStyle().

pub unsafe fn from_q_brush_double_pen_style(
    brush: impl CastInto<Ref<QBrush>>,
    width: c_double,
    s: PenStyle
) -> CppBox<QPen>
[src]

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

Calls C++ function: [constructor] void QPen::QPen(const QBrush& brush, double width, Qt::PenStyle s = …).

C++ documentation:

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

See also setBrush(), setWidth(), setStyle(), setCapStyle(), and setJoinStyle().

pub unsafe fn from_q_brush_double(
    brush: impl CastInto<Ref<QBrush>>,
    width: c_double
) -> CppBox<QPen>
[src]

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

Calls C++ function: [constructor] void QPen::QPen(const QBrush& brush, double width).

C++ documentation:

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

See also setBrush(), setWidth(), setStyle(), setCapStyle(), and setJoinStyle().

pub unsafe fn new_copy(pen: impl CastInto<Ref<QPen>>) -> CppBox<QPen>[src]

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

Calls C++ function: [constructor] void QPen::QPen(const QPen& pen).

C++ documentation:

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

pub unsafe fn set_brush(&self, brush: impl CastInto<Ref<QBrush>>)[src]

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

Calls C++ function: void QPen::setBrush(const QBrush& brush).

C++ documentation:

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

See also brush() and setColor().

pub unsafe fn set_cap_style(&self, pcs: PenCapStyle)[src]

Sets the pen's cap style to the given style. The default value is Qt::SquareCap.

Calls C++ function: void QPen::setCapStyle(Qt::PenCapStyle pcs).

C++ documentation:

Sets the pen's cap style to the given style. The default value is Qt::SquareCap.

See also capStyle() and Cap Style.

pub unsafe fn set_color(&self, color: impl CastInto<Ref<QColor>>)[src]

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

Calls C++ function: void QPen::setColor(const QColor& color).

C++ documentation:

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

See also setBrush() and color().

pub unsafe fn set_cosmetic(&self, cosmetic: bool)[src]

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

Calls C++ function: void QPen::setCosmetic(bool cosmetic).

C++ documentation:

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

See also isCosmetic().

pub unsafe fn set_dash_offset(&self, doffset: c_double)[src]

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.

Calls C++ function: void QPen::setDashOffset(double doffset).

C++ documentation:

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.

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.

Note: This implicitly converts the style of the pen to Qt::CustomDashLine.

See also dashOffset().

pub unsafe fn set_dash_pattern(
    &self,
    pattern: impl CastInto<Ref<QVectorOfDouble>>
)
[src]

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

Calls C++ function: void QPen::setDashPattern(const QVector<double>& pattern).

C++ documentation:

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

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:

QPen pen; QVector<qreal> dashes; qreal space = 4; dashes << 1 << space << 3 << space << 9 << space << 27 << space << 9 << 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 Qt::SquareCap, meaning that a square line end covers the end point and extends beyond it by half the line width.

See also setStyle(), dashPattern(), setCapStyle(), and setCosmetic().

pub unsafe fn set_join_style(&self, pcs: PenJoinStyle)[src]

Sets the pen's join style to the given style. The default value is Qt::BevelJoin.

Calls C++ function: void QPen::setJoinStyle(Qt::PenJoinStyle pcs).

C++ documentation:

Sets the pen's join style to the given style. The default value is Qt::BevelJoin.

See also joinStyle() and Join Style.

pub unsafe fn set_miter_limit(&self, limit: c_double)[src]

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

Calls C++ function: void QPen::setMiterLimit(double limit).

C++ documentation:

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

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 Qt::MiterJoin. 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 miterLimit(), setJoinStyle(), and Join Style.

pub unsafe fn set_style(&self, arg1: PenStyle)[src]

Sets the pen style to the given style.

Calls C++ function: void QPen::setStyle(Qt::PenStyle arg1).

C++ documentation:

Sets the pen style to the given style.

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

Note: This function resets the dash offset to zero.

See also style() and Pen Style.

pub unsafe fn set_width(&self, width: c_int)[src]

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

Calls C++ function: void QPen::setWidth(int width).

C++ documentation:

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 transformation set on the painter.

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

See also setWidthF() and width().

pub unsafe fn set_width_f(&self, width: c_double)[src]

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

Calls C++ function: void QPen::setWidthF(double width).

C++ documentation:

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 transformation on the painter.

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

See also setWidth() and widthF().

pub unsafe fn style(&self) -> PenStyle[src]

Returns the pen style.

Calls C++ function: Qt::PenStyle QPen::style() const.

C++ documentation:

Returns the pen style.

See also setStyle() and Pen Style.

pub unsafe fn swap(&self, other: impl CastInto<Ref<QPen>>)[src]

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

Calls C++ function: void QPen::swap(QPen& other).

C++ documentation:

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

This function was introduced in Qt 4.8.

pub unsafe fn to_q_variant(&self) -> CppBox<QVariant>[src]

Returns the pen as a QVariant.

Calls C++ function: QVariant QPen::operator QVariant() const.

C++ documentation:

Returns the pen as a QVariant.

pub unsafe fn width(&self) -> c_int[src]

Returns the pen width with integer precision.

Calls C++ function: int QPen::width() const.

C++ documentation:

Returns the pen width with integer precision.

See also setWidth() and widthF().

pub unsafe fn width_f(&self) -> c_double[src]

Returns the pen width with floating point precision.

Calls C++ function: double QPen::widthF() const.

C++ documentation:

Returns the pen width with floating point precision.

See also setWidthF() and width().

Trait Implementations

impl CppDeletable for QPen[src]

unsafe fn delete(&self)[src]

Destroys the pen.

Calls C++ function: [destructor] void QPen::~QPen().

C++ documentation:

Destroys the pen.

impl PartialEq<Ref<QPen>> for QPen[src]

fn eq(&self, p: &Ref<QPen>) -> bool[src]

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.

Calls C++ function: bool QPen::operator==(const QPen& p) const.

C++ documentation:

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 operator!=().

Auto Trait Implementations

impl RefUnwindSafe for QPen

impl Send for QPen

impl Sync for QPen

impl Unpin for QPen

impl UnwindSafe for QPen

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T, U> CastInto<U> for T where
    U: CastFrom<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> StaticUpcast<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.