<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <!-- qgraphicsitem.cpp --> <title>QGraphicsLineItem Class | Qt Widgets 5.9</title> <link rel="stylesheet" type="text/css" href="style/offline-simple.css" /> <script type="text/javascript"> document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css"); // loading style sheet breaks anchors that were jumped to before // so force jumping to anchor again setTimeout(function() { var anchor = location.hash; // need to jump to different anchor first (e.g. none) location.hash = "#"; setTimeout(function() { location.hash = anchor; }, 0); }, 0); </script> </head> <body> <div class="header" id="qtdocheader"> <div class="main"> <div class="main-rounded"> <div class="navigationbar"> <table><tr> <td >Qt 5.9</td><td ><a href="qtwidgets-index.html">Qt Widgets</a></td><td ><a href="qtwidgets-module.html">C++ Classes</a></td><td >QGraphicsLineItem</td></tr></table><table class="buildversion"><tr> <td id="buildversion" width="100%" align="right">Qt 5.9.4 Reference Documentation</td> </tr></table> </div> </div> <div class="content"> <div class="line"> <div class="content mainContent"> <div class="sidebar"> <div class="toc"> <h3><a name="toc">Contents</a></h3> <ul> <li class="level1"><a href="#public-functions">Public Functions</a></li> <li class="level1"><a href="#reimplemented-public-functions">Reimplemented Public Functions</a></li> <li class="level1"><a href="#details">Detailed Description</a></li> </ul> </div> <div class="sidebar-content" id="sidebar-content"></div></div> <h1 class="title">QGraphicsLineItem Class</h1> <!-- $$$QGraphicsLineItem-brief --> <p>The <a href="qgraphicslineitem.html">QGraphicsLineItem</a> class provides a line item that you can add to a <a href="qgraphicsscene.html">QGraphicsScene</a>. <a href="#details">More...</a></p> <!-- @@@QGraphicsLineItem --> <div class="table"><table class="alignedsummary"> <tr><td class="memItemLeft rightAlign topAlign"> Header:</td><td class="memItemRight bottomAlign"> <span class="preprocessor">#include <QGraphicsLineItem></span> </td></tr><tr><td class="memItemLeft rightAlign topAlign"> qmake:</td><td class="memItemRight bottomAlign"> QT += widgets</td></tr><tr><td class="memItemLeft rightAlign topAlign"> Since:</td><td class="memItemRight bottomAlign"> Qt 4.2</td></tr><tr><td class="memItemLeft rightAlign topAlign"> Inherits:</td><td class="memItemRight bottomAlign"> <a href="qgraphicsitem.html">QGraphicsItem</a></td></tr></table></div><ul> <li><a href="qgraphicslineitem-members.html">List of all members, including inherited members</a></li> </ul> <a name="public-functions"></a> <h2 id="public-functions">Public Functions</h2> <div class="table"><table class="alignedsummary"> <tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qgraphicslineitem.html#QGraphicsLineItem">QGraphicsLineItem</a></b>(QGraphicsItem *<i>parent</i> = Q_NULLPTR)</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qgraphicslineitem.html#QGraphicsLineItem-1">QGraphicsLineItem</a></b>(const QLineF &<i>line</i>, QGraphicsItem *<i>parent</i> = Q_NULLPTR)</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qgraphicslineitem.html#QGraphicsLineItem-2">QGraphicsLineItem</a></b>(qreal <i>x1</i>, qreal <i>y1</i>, qreal <i>x2</i>, qreal <i>y2</i>, QGraphicsItem *<i>parent</i> = Q_NULLPTR)</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qgraphicslineitem.html#dtor.QGraphicsLineItem">~QGraphicsLineItem</a></b>()</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> QLineF </td><td class="memItemRight bottomAlign"><b><a href="qgraphicslineitem.html#line">line</a></b>() const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> QPen </td><td class="memItemRight bottomAlign"><b><a href="qgraphicslineitem.html#pen">pen</a></b>() const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qgraphicslineitem.html#setLine">setLine</a></b>(const QLineF &<i>line</i>)</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qgraphicslineitem.html#setLine-1">setLine</a></b>(qreal <i>x1</i>, qreal <i>y1</i>, qreal <i>x2</i>, qreal <i>y2</i>)</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qgraphicslineitem.html#setPen">setPen</a></b>(const QPen &<i>pen</i>)</td></tr> </table></div> <a name="reimplemented-public-functions"></a> <h2 id="reimplemented-public-functions">Reimplemented Public Functions</h2> <div class="table"><table class="alignedsummary"> <tr><td class="memItemLeft rightAlign topAlign"> virtual QRectF </td><td class="memItemRight bottomAlign"><b><a href="qgraphicslineitem.html#boundingRect">boundingRect</a></b>() const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> virtual bool </td><td class="memItemRight bottomAlign"><b><a href="qgraphicslineitem.html#contains">contains</a></b>(const QPointF &<i>point</i>) const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> virtual bool </td><td class="memItemRight bottomAlign"><b><a href="qgraphicslineitem.html#isObscuredBy">isObscuredBy</a></b>(const QGraphicsItem *<i>item</i>) const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> virtual QPainterPath </td><td class="memItemRight bottomAlign"><b><a href="qgraphicslineitem.html#opaqueArea">opaqueArea</a></b>() const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> virtual void </td><td class="memItemRight bottomAlign"><b><a href="qgraphicslineitem.html#paint">paint</a></b>(QPainter *<i>painter</i>, const QStyleOptionGraphicsItem *<i>option</i>, QWidget *<i>widget</i> = Q_NULLPTR)</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> virtual QPainterPath </td><td class="memItemRight bottomAlign"><b><a href="qgraphicslineitem.html#shape">shape</a></b>() const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> virtual int </td><td class="memItemRight bottomAlign"><b><a href="qgraphicslineitem.html#type">type</a></b>() const</td></tr> </table></div> <ul> <li class="fn">176 public functions inherited from <a href="qgraphicsitem.html#public-functions">QGraphicsItem</a></li> </ul> <h3>Additional Inherited Members</h3> <ul> <li class="fn">2 static public members inherited from <a href="qgraphicsitem.html#static-public-members">QGraphicsItem</a></li> <li class="fn">24 protected functions inherited from <a href="qgraphicsitem.html#protected-functions">QGraphicsItem</a></li> </ul> <a name="details"></a> <!-- $$$QGraphicsLineItem-description --> <div class="descr"> <h2 id="details">Detailed Description</h2> <p>The <a href="qgraphicslineitem.html">QGraphicsLineItem</a> class provides a line item that you can add to a <a href="qgraphicsscene.html">QGraphicsScene</a>.</p> <p>To set the item's line, pass a <a href="../qtcore/qlinef.html">QLineF</a> to <a href="qgraphicslineitem.html">QGraphicsLineItem</a>'s constructor, or call the <a href="qgraphicslineitem.html#setLine">setLine</a>() function. The <a href="qgraphicslineitem.html#line">line</a>() function returns the current line. By default the line is black with a width of 0, but you can change this by calling <a href="qgraphicslineitem.html#setPen">setPen</a>().</p> <p class="centerAlign"><img src="images/graphicsview-lineitem.png" alt="" /></p><p><a href="qgraphicslineitem.html">QGraphicsLineItem</a> uses the line and the pen width to provide a reasonable implementation of <a href="qgraphicslineitem.html#boundingRect">boundingRect</a>(), <a href="qgraphicslineitem.html#shape">shape</a>(), and <a href="qgraphicslineitem.html#contains">contains</a>(). The <a href="qgraphicslineitem.html#paint">paint</a>() function draws the line using the item's associated pen.</p> </div> <p><b>See also </b><a href="qgraphicspathitem.html">QGraphicsPathItem</a>, <a href="qgraphicsrectitem.html">QGraphicsRectItem</a>, <a href="qgraphicsellipseitem.html">QGraphicsEllipseItem</a>, <a href="qgraphicstextitem.html">QGraphicsTextItem</a>, <a href="qgraphicspolygonitem.html">QGraphicsPolygonItem</a>, <a href="qgraphicspixmapitem.html">QGraphicsPixmapItem</a>, and <a href="graphicsview.html">Graphics View Framework</a>.</p> <!-- @@@QGraphicsLineItem --> <div class="func"> <h2>Member Function Documentation</h2> <!-- $$$QGraphicsLineItem[overload1]$$$QGraphicsLineItemQGraphicsItem* --> <h3 class="fn" id="QGraphicsLineItem"><a name="QGraphicsLineItem"></a>QGraphicsLineItem::<span class="name">QGraphicsLineItem</span>(<span class="type"><a href="qgraphicsitem.html#QGraphicsItem">QGraphicsItem</a></span> *<i>parent</i> = Q_NULLPTR)</h3> <p>Constructs a <a href="qgraphicslineitem.html">QGraphicsLineItem</a>. <i>parent</i> is passed to <a href="qgraphicsitem.html">QGraphicsItem</a>'s constructor.</p> <p><b>See also </b><a href="qgraphicsscene.html#addItem">QGraphicsScene::addItem</a>().</p> <!-- @@@QGraphicsLineItem --> <!-- $$$QGraphicsLineItem$$$QGraphicsLineItemconstQLineF&QGraphicsItem* --> <h3 class="fn" id="QGraphicsLineItem-1"><a name="QGraphicsLineItem-1"></a>QGraphicsLineItem::<span class="name">QGraphicsLineItem</span>(const <span class="type"><a href="../qtcore/qlinef.html">QLineF</a></span> &<i>line</i>, <span class="type"><a href="qgraphicsitem.html#QGraphicsItem">QGraphicsItem</a></span> *<i>parent</i> = Q_NULLPTR)</h3> <p>Constructs a <a href="qgraphicslineitem.html">QGraphicsLineItem</a>, using <i>line</i> as the default line. <i>parent</i> is passed to <a href="qgraphicsitem.html">QGraphicsItem</a>'s constructor.</p> <p><b>See also </b><a href="qgraphicsscene.html#addItem">QGraphicsScene::addItem</a>().</p> <!-- @@@QGraphicsLineItem --> <!-- $$$QGraphicsLineItem$$$QGraphicsLineItemqrealqrealqrealqrealQGraphicsItem* --> <h3 class="fn" id="QGraphicsLineItem-2"><a name="QGraphicsLineItem-2"></a>QGraphicsLineItem::<span class="name">QGraphicsLineItem</span>(<span class="type"><a href="../qtcore/qtglobal.html#qreal-typedef">qreal</a></span> <i>x1</i>, <span class="type"><a href="../qtcore/qtglobal.html#qreal-typedef">qreal</a></span> <i>y1</i>, <span class="type"><a href="../qtcore/qtglobal.html#qreal-typedef">qreal</a></span> <i>x2</i>, <span class="type"><a href="../qtcore/qtglobal.html#qreal-typedef">qreal</a></span> <i>y2</i>, <span class="type"><a href="qgraphicsitem.html#QGraphicsItem">QGraphicsItem</a></span> *<i>parent</i> = Q_NULLPTR)</h3> <p>Constructs a <a href="qgraphicslineitem.html">QGraphicsLineItem</a>, using the line between (<i>x1</i>, <i>y1</i>) and (<i>x2</i>, <i>y2</i>) as the default line. <i>parent</i> is passed to <a href="qgraphicsitem.html">QGraphicsItem</a>'s constructor.</p> <p><b>See also </b><a href="qgraphicsscene.html#addItem">QGraphicsScene::addItem</a>().</p> <!-- @@@QGraphicsLineItem --> <!-- $$$~QGraphicsLineItem[overload1]$$$~QGraphicsLineItem --> <h3 class="fn" id="dtor.QGraphicsLineItem"><a name="dtor.QGraphicsLineItem"></a>QGraphicsLineItem::<span class="name">~QGraphicsLineItem</span>()</h3> <p>Destroys the <a href="qgraphicslineitem.html">QGraphicsLineItem</a>.</p> <!-- @@@~QGraphicsLineItem --> <!-- $$$boundingRect[overload1]$$$boundingRect --> <h3 class="fn" id="boundingRect"><a name="boundingRect"></a><code>[virtual] </code><span class="type"><a href="../qtcore/qrectf.html">QRectF</a></span> QGraphicsLineItem::<span class="name">boundingRect</span>() const</h3> <p>Reimplemented from <a href="qgraphicsitem.html#boundingRect">QGraphicsItem::boundingRect</a>().</p> <!-- @@@boundingRect --> <!-- $$$contains[overload1]$$$containsconstQPointF& --> <h3 class="fn" id="contains"><a name="contains"></a><code>[virtual] </code><span class="type">bool</span> QGraphicsLineItem::<span class="name">contains</span>(const <span class="type"><a href="../qtcore/qpointf.html">QPointF</a></span> &<i>point</i>) const</h3> <p>Reimplemented from <a href="qgraphicsitem.html#contains">QGraphicsItem::contains</a>().</p> <!-- @@@contains --> <!-- $$$isObscuredBy[overload1]$$$isObscuredByconstQGraphicsItem* --> <h3 class="fn" id="isObscuredBy"><a name="isObscuredBy"></a><code>[virtual] </code><span class="type">bool</span> QGraphicsLineItem::<span class="name">isObscuredBy</span>(const <span class="type"><a href="qgraphicsitem.html#QGraphicsItem">QGraphicsItem</a></span> *<i>item</i>) const</h3> <p>Reimplemented from <a href="qgraphicsitem.html#isObscuredBy">QGraphicsItem::isObscuredBy</a>().</p> <!-- @@@isObscuredBy --> <!-- $$$line[overload1]$$$line --> <h3 class="fn" id="line"><a name="line"></a><span class="type"><a href="../qtcore/qlinef.html">QLineF</a></span> QGraphicsLineItem::<span class="name">line</span>() const</h3> <p>Returns the item's line, or a null line if no line has been set.</p> <p><b>See also </b><a href="qgraphicslineitem.html#setLine">setLine</a>().</p> <!-- @@@line --> <!-- $$$opaqueArea[overload1]$$$opaqueArea --> <h3 class="fn" id="opaqueArea"><a name="opaqueArea"></a><code>[virtual] </code><span class="type"><a href="../qtgui/qpainterpath.html">QPainterPath</a></span> QGraphicsLineItem::<span class="name">opaqueArea</span>() const</h3> <p>Reimplemented from <a href="qgraphicsitem.html#opaqueArea">QGraphicsItem::opaqueArea</a>().</p> <!-- @@@opaqueArea --> <!-- $$$paint[overload1]$$$paintQPainter*constQStyleOptionGraphicsItem*QWidget* --> <h3 class="fn" id="paint"><a name="paint"></a><code>[virtual] </code><span class="type">void</span> QGraphicsLineItem::<span class="name">paint</span>(<span class="type"><a href="../qtgui/qpainter.html">QPainter</a></span> *<i>painter</i>, const <span class="type"><a href="qstyleoptiongraphicsitem.html">QStyleOptionGraphicsItem</a></span> *<i>option</i>, <span class="type"><a href="qwidget.html">QWidget</a></span> *<i>widget</i> = Q_NULLPTR)</h3> <p>Reimplemented from <a href="qgraphicsitem.html#paint">QGraphicsItem::paint</a>().</p> <!-- @@@paint --> <!-- $$$pen[overload1]$$$pen --> <h3 class="fn" id="pen"><a name="pen"></a><span class="type"><a href="../qtgui/qpen.html">QPen</a></span> QGraphicsLineItem::<span class="name">pen</span>() const</h3> <p>Returns the item's pen, or a black solid 0-width pen if no pen has been set.</p> <p><b>See also </b><a href="qgraphicslineitem.html#setPen">setPen</a>().</p> <!-- @@@pen --> <!-- $$$setLine[overload1]$$$setLineconstQLineF& --> <h3 class="fn" id="setLine"><a name="setLine"></a><span class="type">void</span> QGraphicsLineItem::<span class="name">setLine</span>(const <span class="type"><a href="../qtcore/qlinef.html">QLineF</a></span> &<i>line</i>)</h3> <p>Sets the item's line to be the given <i>line</i>.</p> <p><b>See also </b><a href="qgraphicslineitem.html#line">line</a>().</p> <!-- @@@setLine --> <!-- $$$setLine$$$setLineqrealqrealqrealqreal --> <h3 class="fn" id="setLine-1"><a name="setLine-1"></a><span class="type">void</span> QGraphicsLineItem::<span class="name">setLine</span>(<span class="type"><a href="../qtcore/qtglobal.html#qreal-typedef">qreal</a></span> <i>x1</i>, <span class="type"><a href="../qtcore/qtglobal.html#qreal-typedef">qreal</a></span> <i>y1</i>, <span class="type"><a href="../qtcore/qtglobal.html#qreal-typedef">qreal</a></span> <i>x2</i>, <span class="type"><a href="../qtcore/qtglobal.html#qreal-typedef">qreal</a></span> <i>y2</i>)</h3> <p>This is an overloaded function.</p> <p>Sets the item's line to be the line between (<i>x1</i>, <i>y1</i>) and (<i>x2</i>, <i>y2</i>).</p> <p>This is the same as calling <code>setLine(QLineF(x1, y1, x2, y2))</code>.</p> <!-- @@@setLine --> <!-- $$$setPen[overload1]$$$setPenconstQPen& --> <h3 class="fn" id="setPen"><a name="setPen"></a><span class="type">void</span> QGraphicsLineItem::<span class="name">setPen</span>(const <span class="type"><a href="../qtgui/qpen.html">QPen</a></span> &<i>pen</i>)</h3> <p>Sets the item's pen to <i>pen</i>. If no pen is set, the line will be painted using a black solid 0-width pen.</p> <p><b>See also </b><a href="qgraphicslineitem.html#pen">pen</a>().</p> <!-- @@@setPen --> <!-- $$$shape[overload1]$$$shape --> <h3 class="fn" id="shape"><a name="shape"></a><code>[virtual] </code><span class="type"><a href="../qtgui/qpainterpath.html">QPainterPath</a></span> QGraphicsLineItem::<span class="name">shape</span>() const</h3> <p>Reimplemented from <a href="qgraphicsitem.html#shape">QGraphicsItem::shape</a>().</p> <!-- @@@shape --> <!-- $$$type[overload1]$$$type --> <h3 class="fn" id="type"><a name="type"></a><code>[virtual] </code><span class="type">int</span> QGraphicsLineItem::<span class="name">type</span>() const</h3> <p>Reimplemented from <a href="qgraphicsitem.html#type">QGraphicsItem::type</a>().</p> <!-- @@@type --> </div> </div> </div> </div> </div> </div> <div class="footer"> <p> <acronym title="Copyright">©</acronym> 2017 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners.<br> The documentation provided herein is licensed under the terms of the <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation License version 1.3</a> as published by the Free Software Foundation.<br> Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners. </p> </div> </body> </html>