QtBase  v6.3.1
Public Types | Public Member Functions | Protected Member Functions | List of all members
QGraphicsLineItem Class Reference

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

#include <qgraphicsitem.h>

Inheritance diagram for QGraphicsLineItem:
Inheritance graph
[legend]
Collaboration diagram for QGraphicsLineItem:
Collaboration graph
[legend]

Public Types

enum  { Type = 6 }
 
- Public Types inherited from QGraphicsItem
enum  GraphicsItemFlag {
  ItemIsMovable = 0x1 , ItemIsSelectable = 0x2 , ItemIsFocusable = 0x4 , ItemClipsToShape = 0x8 ,
  ItemClipsChildrenToShape = 0x10 , ItemIgnoresTransformations = 0x20 , ItemIgnoresParentOpacity = 0x40 , ItemDoesntPropagateOpacityToChildren = 0x80 ,
  ItemStacksBehindParent = 0x100 , ItemUsesExtendedStyleOption = 0x200 , ItemHasNoContents = 0x400 , ItemSendsGeometryChanges = 0x800 ,
  ItemAcceptsInputMethod = 0x1000 , ItemNegativeZStacksBehindParent = 0x2000 , ItemIsPanel = 0x4000 , ItemIsFocusScope = 0x8000 ,
  ItemSendsScenePositionChanges = 0x10000 , ItemStopsClickFocusPropagation = 0x20000 , ItemStopsFocusHandling = 0x40000 , ItemContainsChildrenInShape = 0x80000
}
 
enum  GraphicsItemChange {
  ItemPositionChange , ItemVisibleChange = 2 , ItemEnabledChange , ItemSelectedChange ,
  ItemParentChange , ItemChildAddedChange , ItemChildRemovedChange , ItemTransformChange ,
  ItemPositionHasChanged , ItemTransformHasChanged , ItemSceneChange , ItemVisibleHasChanged ,
  ItemEnabledHasChanged , ItemSelectedHasChanged , ItemParentHasChanged , ItemSceneHasChanged ,
  ItemCursorChange , ItemCursorHasChanged , ItemToolTipChange , ItemToolTipHasChanged ,
  ItemFlagsChange , ItemFlagsHaveChanged , ItemZValueChange , ItemZValueHasChanged ,
  ItemOpacityChange , ItemOpacityHasChanged , ItemScenePositionHasChanged , ItemRotationChange ,
  ItemRotationHasChanged , ItemScaleChange , ItemScaleHasChanged , ItemTransformOriginPointChange ,
  ItemTransformOriginPointHasChanged
}
 
enum  CacheMode { NoCache , ItemCoordinateCache , DeviceCoordinateCache }
 
enum  PanelModality { NonModal , PanelModal , SceneModal }
 
enum  { Type = 1 , UserType = 65536 }
 

Public Member Functions

 QGraphicsLineItem (QGraphicsItem *parent=nullptr)
 
 QGraphicsLineItem (const QLineF &line, QGraphicsItem *parent=nullptr)
 
 QGraphicsLineItem (qreal x1, qreal y1, qreal x2, qreal y2, QGraphicsItem *parent=nullptr)
 
 ~QGraphicsLineItem ()
 
QPen pen () const
 
void setPen (const QPen &pen)
 
QLineF line () const
 
void setLine (const QLineF &line)
 
void setLine (qreal x1, qreal y1, qreal x2, qreal y2)
 
QRectF boundingRect () const override
 
QPainterPath shape () const override
 
bool contains (const QPointF &point) const override
 
void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=nullptr) override
 
bool isObscuredBy (const QGraphicsItem *item) const override
 
QPainterPath opaqueArea () const override
 
int type () const override
 
- Public Member Functions inherited from QGraphicsItem
 QGraphicsItem (QGraphicsItem *parent=nullptr)
 
virtual ~QGraphicsItem ()
 
QGraphicsScenescene () const
 
QGraphicsItemparentItem () const
 
QGraphicsItemtopLevelItem () const
 
QGraphicsObjectparentObject () const
 
QGraphicsWidgetparentWidget () const
 
QGraphicsWidgettopLevelWidget () const
 
QGraphicsWidgetwindow () const
 
QGraphicsItempanel () const
 
void setParentItem (QGraphicsItem *parent)
 
QList< QGraphicsItem * > childItems () const
 
bool isWidget () const
 
bool isWindow () const
 
bool isPanel () const
 
QGraphicsObjecttoGraphicsObject ()
 
const QGraphicsObjecttoGraphicsObject () const
 
QGraphicsItemGroupgroup () const
 
void setGroup (QGraphicsItemGroup *group)
 
GraphicsItemFlags flags () const
 
void setFlag (GraphicsItemFlag flag, bool enabled=true)
 
void setFlags (GraphicsItemFlags flags)
 
CacheMode cacheMode () const
 
void setCacheMode (CacheMode mode, const QSize &cacheSize=QSize())
 
PanelModality panelModality () const
 
void setPanelModality (PanelModality panelModality)
 
bool isBlockedByModalPanel (QGraphicsItem **blockingPanel=nullptr) const
 
QCursor cursor () const
 
void setCursor (const QCursor &cursor)
 
bool hasCursor () const
 
void unsetCursor ()
 
bool isVisible () const
 
bool isVisibleTo (const QGraphicsItem *parent) const
 
void setVisible (bool visible)
 
void hide ()
 
void show ()
 
bool isEnabled () const
 
void setEnabled (bool enabled)
 
bool isSelected () const
 
void setSelected (bool selected)
 
bool acceptDrops () const
 
void setAcceptDrops (bool on)
 
qreal opacity () const
 
qreal effectiveOpacity () const
 
void setOpacity (qreal opacity)
 
Qt::MouseButtons acceptedMouseButtons () const
 
void setAcceptedMouseButtons (Qt::MouseButtons buttons)
 
bool acceptHoverEvents () const
 
void setAcceptHoverEvents (bool enabled)
 
bool acceptTouchEvents () const
 
void setAcceptTouchEvents (bool enabled)
 
bool filtersChildEvents () const
 
void setFiltersChildEvents (bool enabled)
 
bool handlesChildEvents () const
 
void setHandlesChildEvents (bool enabled)
 
bool isActive () const
 
void setActive (bool active)
 
bool hasFocus () const
 
void setFocus (Qt::FocusReason focusReason=Qt::OtherFocusReason)
 
void clearFocus ()
 
QGraphicsItemfocusProxy () const
 
void setFocusProxy (QGraphicsItem *item)
 
QGraphicsItemfocusItem () const
 
QGraphicsItemfocusScopeItem () const
 
void grabMouse ()
 
void ungrabMouse ()
 
void grabKeyboard ()
 
void ungrabKeyboard ()
 
QPointF pos () const
 
qreal x () const
 
void setX (qreal x)
 
qreal y () const
 
void setY (qreal y)
 
QPointF scenePos () const
 
void setPos (const QPointF &pos)
 
void setPos (qreal x, qreal y)
 
void moveBy (qreal dx, qreal dy)
 
void ensureVisible (const QRectF &rect=QRectF(), int xmargin=50, int ymargin=50)
 
void ensureVisible (qreal x, qreal y, qreal w, qreal h, int xmargin=50, int ymargin=50)
 
QTransform transform () const
 
QTransform sceneTransform () const
 
QTransform deviceTransform (const QTransform &viewportTransform) const
 
QTransform itemTransform (const QGraphicsItem *other, bool *ok=nullptr) const
 
void setTransform (const QTransform &matrix, bool combine=false)
 
void resetTransform ()
 
void setRotation (qreal angle)
 
qreal rotation () const
 
void setScale (qreal scale)
 
qreal scale () const
 
QList< QGraphicsTransform * > transformations () const
 
void setTransformations (const QList< QGraphicsTransform * > &transformations)
 
QPointF transformOriginPoint () const
 
void setTransformOriginPoint (const QPointF &origin)
 
void setTransformOriginPoint (qreal ax, qreal ay)
 
virtual void advance (int phase)
 
qreal zValue () const
 
void setZValue (qreal z)
 
void stackBefore (const QGraphicsItem *sibling)
 
QRectF childrenBoundingRect () const
 
QRectF sceneBoundingRect () const
 
bool isClipped () const
 
QPainterPath clipPath () const
 
virtual bool collidesWithItem (const QGraphicsItem *other, Qt::ItemSelectionMode mode=Qt::IntersectsItemShape) const
 
virtual bool collidesWithPath (const QPainterPath &path, Qt::ItemSelectionMode mode=Qt::IntersectsItemShape) const
 
QList< QGraphicsItem * > collidingItems (Qt::ItemSelectionMode mode=Qt::IntersectsItemShape) const
 
bool isObscured (const QRectF &rect=QRectF()) const
 
bool isObscured (qreal x, qreal y, qreal w, qreal h) const
 
QRegion boundingRegion (const QTransform &itemToDeviceTransform) const
 
qreal boundingRegionGranularity () const
 
void setBoundingRegionGranularity (qreal granularity)
 
void update (const QRectF &rect=QRectF())
 
void update (qreal x, qreal y, qreal width, qreal height)
 
void scroll (qreal dx, qreal dy, const QRectF &rect=QRectF())
 
QPointF mapToItem (const QGraphicsItem *item, const QPointF &point) const
 
QPointF mapToParent (const QPointF &point) const
 
QPointF mapToScene (const QPointF &point) const
 
QPolygonF mapToItem (const QGraphicsItem *item, const QRectF &rect) const
 
QPolygonF mapToParent (const QRectF &rect) const
 
QPolygonF mapToScene (const QRectF &rect) const
 
QRectF mapRectToItem (const QGraphicsItem *item, const QRectF &rect) const
 
QRectF mapRectToParent (const QRectF &rect) const
 
QRectF mapRectToScene (const QRectF &rect) const
 
QPolygonF mapToItem (const QGraphicsItem *item, const QPolygonF &polygon) const
 
QPolygonF mapToParent (const QPolygonF &polygon) const
 
QPolygonF mapToScene (const QPolygonF &polygon) const
 
QPainterPath mapToItem (const QGraphicsItem *item, const QPainterPath &path) const
 
QPainterPath mapToParent (const QPainterPath &path) const
 
QPainterPath mapToScene (const QPainterPath &path) const
 
QPointF mapFromItem (const QGraphicsItem *item, const QPointF &point) const
 
QPointF mapFromParent (const QPointF &point) const
 
QPointF mapFromScene (const QPointF &point) const
 
QPolygonF mapFromItem (const QGraphicsItem *item, const QRectF &rect) const
 
QPolygonF mapFromParent (const QRectF &rect) const
 
QPolygonF mapFromScene (const QRectF &rect) const
 
QRectF mapRectFromItem (const QGraphicsItem *item, const QRectF &rect) const
 
QRectF mapRectFromParent (const QRectF &rect) const
 
QRectF mapRectFromScene (const QRectF &rect) const
 
QPolygonF mapFromItem (const QGraphicsItem *item, const QPolygonF &polygon) const
 
QPolygonF mapFromParent (const QPolygonF &polygon) const
 
QPolygonF mapFromScene (const QPolygonF &polygon) const
 
QPainterPath mapFromItem (const QGraphicsItem *item, const QPainterPath &path) const
 
QPainterPath mapFromParent (const QPainterPath &path) const
 
QPainterPath mapFromScene (const QPainterPath &path) const
 
QPointF mapToItem (const QGraphicsItem *item, qreal x, qreal y) const
 
QPointF mapToParent (qreal x, qreal y) const
 
QPointF mapToScene (qreal x, qreal y) const
 
QPolygonF mapToItem (const QGraphicsItem *item, qreal x, qreal y, qreal w, qreal h) const
 
QPolygonF mapToParent (qreal x, qreal y, qreal w, qreal h) const
 
QPolygonF mapToScene (qreal x, qreal y, qreal w, qreal h) const
 
QRectF mapRectToItem (const QGraphicsItem *item, qreal x, qreal y, qreal w, qreal h) const
 
QRectF mapRectToParent (qreal x, qreal y, qreal w, qreal h) const
 
QRectF mapRectToScene (qreal x, qreal y, qreal w, qreal h) const
 
QPointF mapFromItem (const QGraphicsItem *item, qreal x, qreal y) const
 
QPointF mapFromParent (qreal x, qreal y) const
 
QPointF mapFromScene (qreal x, qreal y) const
 
QPolygonF mapFromItem (const QGraphicsItem *item, qreal x, qreal y, qreal w, qreal h) const
 
QPolygonF mapFromParent (qreal x, qreal y, qreal w, qreal h) const
 
QPolygonF mapFromScene (qreal x, qreal y, qreal w, qreal h) const
 
QRectF mapRectFromItem (const QGraphicsItem *item, qreal x, qreal y, qreal w, qreal h) const
 
QRectF mapRectFromParent (qreal x, qreal y, qreal w, qreal h) const
 
QRectF mapRectFromScene (qreal x, qreal y, qreal w, qreal h) const
 
bool isAncestorOf (const QGraphicsItem *child) const
 
QGraphicsItemcommonAncestorItem (const QGraphicsItem *other) const
 
bool isUnderMouse () const
 
QVariant data (int key) const
 
void setData (int key, const QVariant &value)
 
Qt::InputMethodHints inputMethodHints () const
 
void setInputMethodHints (Qt::InputMethodHints hints)
 
void installSceneEventFilter (QGraphicsItem *filterItem)
 
void removeSceneEventFilter (QGraphicsItem *filterItem)
 

Protected Member Functions

bool supportsExtension (Extension extension) const override
 
void setExtension (Extension extension, const QVariant &variant) override
 
QVariant extension (const QVariant &variant) const override
 
- Protected Member Functions inherited from QGraphicsItem
void updateMicroFocus ()
 
virtual bool sceneEventFilter (QGraphicsItem *watched, QEvent *event)
 
virtual bool sceneEvent (QEvent *event)
 
virtual void contextMenuEvent (QGraphicsSceneContextMenuEvent *event)
 
virtual void dragEnterEvent (QGraphicsSceneDragDropEvent *event)
 
virtual void dragLeaveEvent (QGraphicsSceneDragDropEvent *event)
 
virtual void dragMoveEvent (QGraphicsSceneDragDropEvent *event)
 
virtual void dropEvent (QGraphicsSceneDragDropEvent *event)
 
virtual void focusInEvent (QFocusEvent *event)
 
virtual void focusOutEvent (QFocusEvent *event)
 
virtual void hoverEnterEvent (QGraphicsSceneHoverEvent *event)
 
virtual void hoverMoveEvent (QGraphicsSceneHoverEvent *event)
 
virtual void hoverLeaveEvent (QGraphicsSceneHoverEvent *event)
 
virtual void keyPressEvent (QKeyEvent *event)
 
virtual void keyReleaseEvent (QKeyEvent *event)
 
virtual void mousePressEvent (QGraphicsSceneMouseEvent *event)
 
virtual void mouseMoveEvent (QGraphicsSceneMouseEvent *event)
 
virtual void mouseReleaseEvent (QGraphicsSceneMouseEvent *event)
 
virtual void mouseDoubleClickEvent (QGraphicsSceneMouseEvent *event)
 
virtual void wheelEvent (QGraphicsSceneWheelEvent *event)
 
virtual void inputMethodEvent (QInputMethodEvent *event)
 
virtual QVariant inputMethodQuery (Qt::InputMethodQuery query) const
 
virtual QVariant itemChange (GraphicsItemChange change, const QVariant &value)
 
 QGraphicsItem (QGraphicsItemPrivate &dd, QGraphicsItem *parent)
 
void addToIndex ()
 
void removeFromIndex ()
 
void prepareGeometryChange ()
 

Additional Inherited Members

- Protected Types inherited from QGraphicsItem
enum  Extension { UserExtension = 0x80000000 }
 
- Protected Attributes inherited from QGraphicsItem
QScopedPointer< QGraphicsItemPrivated_ptr
 

Detailed Description

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

Since
4.2

\inmodule QtWidgets

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().

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, {Graphics View Framework}

Definition at line 764 of file qgraphicsitem.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
Type 

Definition at line 789 of file qgraphicsitem.h.

Constructor & Destructor Documentation

◆ QGraphicsLineItem() [1/3]

QGraphicsLineItem::QGraphicsLineItem ( QGraphicsItem parent = nullptr)
explicit

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

See also
QGraphicsScene::addItem()

Definition at line 9171 of file qgraphicsitem.cpp.

◆ QGraphicsLineItem() [2/3]

QGraphicsLineItem::QGraphicsLineItem ( const QLineF line,
QGraphicsItem parent = nullptr 
)
explicit

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

See also
QGraphicsScene::addItem()

Definition at line 9144 of file qgraphicsitem.cpp.

Here is the call graph for this function:

◆ QGraphicsLineItem() [3/3]

QGraphicsLineItem::QGraphicsLineItem ( qreal  x1,
qreal  y1,
qreal  x2,
qreal  y2,
QGraphicsItem parent = nullptr 
)
explicit

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
QGraphicsScene::addItem()

Definition at line 9157 of file qgraphicsitem.cpp.

Here is the call graph for this function:

◆ ~QGraphicsLineItem()

QGraphicsLineItem::~QGraphicsLineItem ( )

Destroys the QGraphicsLineItem.

Definition at line 9179 of file qgraphicsitem.cpp.

Member Function Documentation

◆ boundingRect()

QRectF QGraphicsLineItem::boundingRect ( ) const
overridevirtual

\reimp

Implements QGraphicsItem.

Definition at line 9250 of file qgraphicsitem.cpp.

◆ contains()

bool QGraphicsLineItem::contains ( const QPointF point) const
overridevirtual

\reimp

Reimplemented from QGraphicsItem.

Definition at line 9285 of file qgraphicsitem.cpp.

Here is the call graph for this function:

◆ extension()

QVariant QGraphicsLineItem::extension ( const QVariant variant) const
overrideprotectedvirtual

Reimplemented from QGraphicsItem.

Definition at line 9349 of file qgraphicsitem.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isObscuredBy()

bool QGraphicsLineItem::isObscuredBy ( const QGraphicsItem item) const
overridevirtual

\reimp

Reimplemented from QGraphicsItem.

Definition at line 9307 of file qgraphicsitem.cpp.

Here is the call graph for this function:

◆ line()

QLineF QGraphicsLineItem::line ( ) const

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

See also
setLine()

Definition at line 9216 of file qgraphicsitem.cpp.

Here is the caller graph for this function:

◆ opaqueArea()

QPainterPath QGraphicsLineItem::opaqueArea ( ) const
overridevirtual

\reimp

Reimplemented from QGraphicsItem.

Definition at line 9315 of file qgraphicsitem.cpp.

Here is the call graph for this function:

◆ paint()

void QGraphicsLineItem::paint ( QPainter painter,
const QStyleOptionGraphicsItem option,
QWidget widget = nullptr 
)
overridevirtual

\reimp

Implements QGraphicsItem.

Definition at line 9293 of file qgraphicsitem.cpp.

Here is the call graph for this function:

◆ pen()

QPen QGraphicsLineItem::pen ( ) const

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

See also
setPen()

Definition at line 9189 of file qgraphicsitem.cpp.

Here is the caller graph for this function:

◆ setExtension()

void QGraphicsLineItem::setExtension ( Extension  extension,
const QVariant variant 
)
overrideprotectedvirtual

Reimplemented from QGraphicsItem.

Definition at line 9340 of file qgraphicsitem.cpp.

Here is the call graph for this function:

◆ setLine() [1/2]

void QGraphicsLineItem::setLine ( const QLineF line)

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

See also
line()

Definition at line 9227 of file qgraphicsitem.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setLine() [2/2]

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

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

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))}.

Definition at line 777 of file qgraphicsitem.h.

◆ setPen()

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 pen.

See also
pen()

Definition at line 9201 of file qgraphicsitem.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ shape()

QPainterPath QGraphicsLineItem::shape ( ) const
overridevirtual

\reimp

Reimplemented from QGraphicsItem.

Definition at line 9270 of file qgraphicsitem.cpp.

Here is the caller graph for this function:

◆ supportsExtension()

bool QGraphicsLineItem::supportsExtension ( Extension  extension) const
overrideprotectedvirtual

Reimplemented from QGraphicsItem.

Definition at line 9331 of file qgraphicsitem.cpp.

Here is the call graph for this function:

◆ type()

int QGraphicsLineItem::type ( ) const
overridevirtual

\reimp

Reimplemented from QGraphicsItem.

Definition at line 9323 of file qgraphicsitem.cpp.


The documentation for this class was generated from the following files: