class QGraphicsLineItem#

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

Inheritance diagram of PySide6.QtWidgets.QGraphicsLineItem

Synopsis#

Methods#

Note

This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE

Detailed Description#

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

../../_images/graphicsview-lineitem.png

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.

__init__([parent=None])#
Parameters:

parentQGraphicsItem

Constructs a QGraphicsLineItem . parent is passed to QGraphicsItem ‘s constructor.

See also

addItem()

__init__(line[, parent=None])
Parameters:

Constructs a QGraphicsLineItem , using line as the default line. parent is passed to QGraphicsItem ‘s constructor.

See also

addItem()

__init__(x1, y1, x2, y2[, parent=None])
Parameters:
  • x1 – float

  • y1 – float

  • x2 – float

  • y2 – float

  • parentQGraphicsItem

Constructs a QGraphicsLineItem , using the line between (x1, y1) and (x2, y2) as the default line. parent is passed to QGraphicsItem ‘s constructor.

See also

addItem()

line()#
Return type:

QLineF

Returns the item’s line, or a null line if no line has been set.

See also

setLine()

pen()#
Return type:

QPen

Returns the item’s pen, or a black solid 0-width pen if no pen has been set.

See also

setPen()

setLine(line)#
Parameters:

lineQLineF

Sets the item’s line to be the given line.

See also

line()

setLine(x1, y1, x2, y2)
Parameters:
  • x1 – float

  • y1 – float

  • x2 – float

  • y2 – float

This is an overloaded function.

Sets the item’s line to be the line between (x1, y1) and (x2, y2).

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

setPen(pen)#
Parameters:

penQPen

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

See also

pen()