|  | Home · All Classes · Main Classes · Grouped Classes · Modules · Functions |

# QGraphicsLineItem Class Reference
[QtGui module]

The QGraphicsLineItem class provides a line item that you can add to a QGraphicsScene. More...

    #include <QGraphicsLineItem>

Inherits QGraphicsItem.

This class was introduced in Qt 4.2.

- List of all members, including inherited members

### Public Functions

- QGraphicsLineItem ( QGraphicsItem * parent = 0, QGraphicsScene * scene = 0 )
- QGraphicsLineItem ( const QLineF & line, QGraphicsItem * parent = 0, QGraphicsScene * scene = 0 )
- QGraphicsLineItem ( qreal x1, qreal y1, qreal x2, qreal y2, QGraphicsItem * parent = 0, QGraphicsScene * scene = 0 )
- ~QGraphicsLineItem ()
- QLineF line () const
- QPen pen () const
- void setLine ( const QLineF & line )
- void setLine ( qreal x1, qreal y1, qreal x2, qreal y2 )
- void setPen ( const QPen & pen )

- 105 public functions inherited from QGraphicsItem

### Additional Inherited Members

- 1 static public member inherited from QGraphicsItem
- 23 protected functions inherited from QGraphicsItem

## Detailed Description

The QGraphicsLineItem class provides a line item that you can add to a QGraphicsScene.

To set the item's line, pass a QLineF to QGraphicsLineItem's constructor, or call setLine(). line() returns the current line. By default the line is black with a width of 1.0, but you can change this by calling setPen().

QGraphicsLineItem uses the line and the pen width to provide a reasonable implementation of boundingRect(), shape(), and contains(). The paint() function draws the line using the item's associated pen.

See also QGraphicsPathItem, QGraphicsRectItem, QGraphicsEllipseItem, QGraphicsTextItem, QGraphicsPolygonItem, QGraphicsPixmapItem, and The Graphics View Framework.

## Member Function Documentation

### QGraphicsLineItem::QGraphicsLineItem ( QGraphicsItem * parent = 0, QGraphicsScene * scene = 0 )

Constructs a QGraphicsLineItem. parent and scene are passed to QGraphicsItem's constructor.

### QGraphicsLineItem::QGraphicsLineItem ( const QLineF & line, QGraphicsItem * parent = 0, QGraphicsScene * scene = 0 )

Constructs a QGraphicsLineItem, using line as the default line. parent and scene are passed to QGraphicsItem's constructor.

### QGraphicsLineItem::QGraphicsLineItem ( qreal x1, qreal y1, qreal x2, qreal y2, QGraphicsItem * parent = 0, QGraphicsScene * scene = 0 )

Constructs a QGraphicsLineItem, using x1 y1 - x2 y2 as the default line. parent and scene are passed to QGraphicsItem's constructor.

### QGraphicsLineItem::~QGraphicsLineItem ()

Destroys the QGraphicsLineItem.

### QLineF QGraphicsLineItem::line () const

Returns the item's line, or QLineF() if no line has been set.

See also setLine().

### QPen QGraphicsLineItem::pen () const

Returns the item's pen, or a QPen() with a width of 1.0 if no pen has been set.

See also setPen().

### void QGraphicsLineItem::setLine ( const QLineF & line )

Sets the item's line to line.

See also line().

### void QGraphicsLineItem::setLine ( qreal x1, qreal y1, qreal x2, qreal y2 )

This is an overloaded member function, provided for convenience.

This is the same as calling setLine(QLineF(x1, y1, x2, y2)).

### void QGraphicsLineItem::setPen ( const QPen & pen )

Sets the item's pen to pen. If no pen is set, the line will be painted using a black solid 0-width line.

See also pen().