<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <!-- qline.cpp --> <title>QLine Class | Qt Core 5.12.6</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.12</td><td ><a href="qtcore-index.html">Qt Core</a></td><td ><a href="qtcore-module.html">C++ Classes</a></td><td >QLine</td></tr></table><table class="buildversion"><tr> <td id="buildversion" width="100%" align="right"><a href="qtcore-index.html">Qt 5.12.6 Reference Documentation</a></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="#related-non-members">Related Non-Members</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">QLine Class</h1> <!-- $$$QLine-brief --> <p>The <a href="qline.html">QLine</a> class provides a two-dimensional vector using integer precision. <a href="#details">More...</a></p> <!-- @@@QLine --> <div class="table"><table class="alignedsummary"> <tr><td class="memItemLeft rightAlign topAlign"> Header:</td><td class="memItemRight bottomAlign"> <span class="preprocessor">#include <QLine></span> </td></tr><tr><td class="memItemLeft rightAlign topAlign"> qmake:</td><td class="memItemRight bottomAlign"> QT += core</td></tr></table></div><ul> <li><a href="qline-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="qline.html#QLine">QLine</a></b>()</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qline.html#QLine-1">QLine</a></b>(const QPoint &<i>p1</i>, const QPoint &<i>p2</i>)</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qline.html#QLine-2">QLine</a></b>(int <i>x1</i>, int <i>y1</i>, int <i>x2</i>, int <i>y2</i>)</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> QPoint </td><td class="memItemRight bottomAlign"><b><a href="qline.html#p1">p1</a></b>() const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> QPoint </td><td class="memItemRight bottomAlign"><b><a href="qline.html#p2">p2</a></b>() const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> int </td><td class="memItemRight bottomAlign"><b><a href="qline.html#x1">x1</a></b>() const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> int </td><td class="memItemRight bottomAlign"><b><a href="qline.html#x2">x2</a></b>() const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> int </td><td class="memItemRight bottomAlign"><b><a href="qline.html#y1">y1</a></b>() const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> int </td><td class="memItemRight bottomAlign"><b><a href="qline.html#y2">y2</a></b>() const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> QPoint </td><td class="memItemRight bottomAlign"><b><a href="qline.html#center">center</a></b>() const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> int </td><td class="memItemRight bottomAlign"><b><a href="qline.html#dx">dx</a></b>() const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> int </td><td class="memItemRight bottomAlign"><b><a href="qline.html#dy">dy</a></b>() const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qline.html#isNull">isNull</a></b>() const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qline.html#setP1">setP1</a></b>(const QPoint &<i>p1</i>)</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qline.html#setP2">setP2</a></b>(const QPoint &<i>p2</i>)</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qline.html#setLine">setLine</a></b>(int <i>x1</i>, int <i>y1</i>, int <i>x2</i>, int <i>y2</i>)</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qline.html#setPoints">setPoints</a></b>(const QPoint &<i>p1</i>, const QPoint &<i>p2</i>)</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qline.html#translate">translate</a></b>(const QPoint &<i>offset</i>)</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qline.html#translate-1">translate</a></b>(int <i>dx</i>, int <i>dy</i>)</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> QLine </td><td class="memItemRight bottomAlign"><b><a href="qline.html#translated">translated</a></b>(const QPoint &<i>offset</i>) const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> QLine </td><td class="memItemRight bottomAlign"><b><a href="qline.html#translated-1">translated</a></b>(int <i>dx</i>, int <i>dy</i>) const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qline.html#operator-not-eq">operator!=</a></b>(const QLine &<i>line</i>) const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qline.html#operator-eq-eq">operator==</a></b>(const QLine &<i>line</i>) const</td></tr> </table></div> <a name="related-non-members"></a> <h2 id="related-non-members">Related Non-Members</h2> <div class="table"><table class="alignedsummary"> <tr><td class="memItemLeft rightAlign topAlign"> QDataStream &</td><td class="memItemRight bottomAlign"><b><a href="qline.html#operator-lt-lt">operator<<</a></b>(QDataStream &<i>stream</i>, const QLine &<i>line</i>)</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> QDataStream &</td><td class="memItemRight bottomAlign"><b><a href="qline.html#operator-gt-gt">operator>></a></b>(QDataStream &<i>stream</i>, QLine &<i>line</i>)</td></tr> </table></div> <a name="details"></a> <!-- $$$QLine-description --> <div class="descr"> <h2 id="details">Detailed Description</h2> <p>The <a href="qline.html">QLine</a> class provides a two-dimensional vector using integer precision.</p> <p>A <a href="qline.html">QLine</a> describes a finite length line (or a line segment) on a two-dimensional surface. The start and end points of the line are specified using integer point accuracy for coordinates. Use the <a href="qlinef.html">QLineF</a> constructor to retrieve a floating point copy.</p> <div class="table"><table class="generic"> <tr valign="top" class="odd"><td ><img src="images/qline-point.png" alt="" /></td><td ><img src="images/qline-coordinates.png" alt="" /></td></tr> </table></div> <p>The positions of the line's start and end points can be retrieved using the <a href="qline.html#p1">p1</a>(), <a href="qline.html#x1">x1</a>(), <a href="qline.html#y1">y1</a>(), <a href="qline.html#p2">p2</a>(), <a href="qline.html#x2">x2</a>(), and <a href="qline.html#y2">y2</a>() functions. The <a href="qline.html#dx">dx</a>() and <a href="qline.html#dy">dy</a>() functions return the horizontal and vertical components of the line. Use <a href="qline.html#isNull">isNull</a>() to determine whether the <a href="qline.html">QLine</a> represents a valid line or a null line.</p> <p>Finally, the line can be translated a given offset using the <a href="qline.html#translate">translate</a>() function.</p> </div> <p><b>See also </b><a href="qlinef.html">QLineF</a>, <a href="../qtgui/qpolygon.html">QPolygon</a>, and <a href="qrect.html">QRect</a>.</p> <!-- @@@QLine --> <div class="func"> <h2>Member Function Documentation</h2> <!-- $$$QLine[overload1]$$$QLine --> <h3 class="fn" id="QLine"><a name="QLine"></a>QLine::<span class="name">QLine</span>()</h3> <p>Constructs a null line.</p> <!-- @@@QLine --> <!-- $$$QLine$$$QLineconstQPoint&constQPoint& --> <h3 class="fn" id="QLine-1"><a name="QLine-1"></a>QLine::<span class="name">QLine</span>(const <span class="type"><a href="qpoint.html">QPoint</a></span> &<i>p1</i>, const <span class="type"><a href="qpoint.html">QPoint</a></span> &<i>p2</i>)</h3> <p>Constructs a line object that represents the line between <i>p1</i> and <i>p2</i>.</p> <!-- @@@QLine --> <!-- $$$QLine$$$QLineintintintint --> <h3 class="fn" id="QLine-2"><a name="QLine-2"></a>QLine::<span class="name">QLine</span>(<span class="type">int</span> <i>x1</i>, <span class="type">int</span> <i>y1</i>, <span class="type">int</span> <i>x2</i>, <span class="type">int</span> <i>y2</i>)</h3> <p>Constructs a line object that represents the line between (<i>x1</i>, <i>y1</i>) and (<i>x2</i>, <i>y2</i>).</p> <!-- @@@QLine --> <!-- $$$p1[overload1]$$$p1 --> <h3 class="fn" id="p1"><a name="p1"></a><span class="type"><a href="qpoint.html">QPoint</a></span> QLine::<span class="name">p1</span>() const</h3> <p>Returns the line's start point.</p> <p><b>See also </b><a href="qline.html#setP1">setP1</a>(), <a href="qline.html#x1">x1</a>(), <a href="qline.html#y1">y1</a>(), and <a href="qline.html#p2">p2</a>().</p> <!-- @@@p1 --> <!-- $$$p2[overload1]$$$p2 --> <h3 class="fn" id="p2"><a name="p2"></a><span class="type"><a href="qpoint.html">QPoint</a></span> QLine::<span class="name">p2</span>() const</h3> <p>Returns the line's end point.</p> <p><b>See also </b><a href="qline.html#setP2">setP2</a>(), <a href="qline.html#x2">x2</a>(), <a href="qline.html#y2">y2</a>(), and <a href="qline.html#p1">p1</a>().</p> <!-- @@@p2 --> <!-- $$$x1[overload1]$$$x1 --> <h3 class="fn" id="x1"><a name="x1"></a><span class="type">int</span> QLine::<span class="name">x1</span>() const</h3> <p>Returns the x-coordinate of the line's start point.</p> <p><b>See also </b><a href="qline.html#p1">p1</a>().</p> <!-- @@@x1 --> <!-- $$$x2[overload1]$$$x2 --> <h3 class="fn" id="x2"><a name="x2"></a><span class="type">int</span> QLine::<span class="name">x2</span>() const</h3> <p>Returns the x-coordinate of the line's end point.</p> <p><b>See also </b><a href="qline.html#p2">p2</a>().</p> <!-- @@@x2 --> <!-- $$$y1[overload1]$$$y1 --> <h3 class="fn" id="y1"><a name="y1"></a><span class="type">int</span> QLine::<span class="name">y1</span>() const</h3> <p>Returns the y-coordinate of the line's start point.</p> <p><b>See also </b><a href="qline.html#p1">p1</a>().</p> <!-- @@@y1 --> <!-- $$$y2[overload1]$$$y2 --> <h3 class="fn" id="y2"><a name="y2"></a><span class="type">int</span> QLine::<span class="name">y2</span>() const</h3> <p>Returns the y-coordinate of the line's end point.</p> <p><b>See also </b><a href="qline.html#p2">p2</a>().</p> <!-- @@@y2 --> <!-- $$$center[overload1]$$$center --> <h3 class="fn" id="center"><a name="center"></a><span class="type"><a href="qpoint.html">QPoint</a></span> QLine::<span class="name">center</span>() const</h3> <p>Returns the center point of this line. This is equivalent to (<a href="qline.html#p1">p1</a>() + <a href="qline.html#p2">p2</a>()) / 2, except it will never overflow.</p> <p>This function was introduced in Qt 5.8.</p> <!-- @@@center --> <!-- $$$dx[overload1]$$$dx --> <h3 class="fn" id="dx"><a name="dx"></a><span class="type">int</span> QLine::<span class="name">dx</span>() const</h3> <p>Returns the horizontal component of the line's vector.</p> <p><b>See also </b><a href="qline.html#dy">dy</a>().</p> <!-- @@@dx --> <!-- $$$dy[overload1]$$$dy --> <h3 class="fn" id="dy"><a name="dy"></a><span class="type">int</span> QLine::<span class="name">dy</span>() const</h3> <p>Returns the vertical component of the line's vector.</p> <p><b>See also </b><a href="qline.html#dx">dx</a>().</p> <!-- @@@dy --> <!-- $$$isNull[overload1]$$$isNull --> <h3 class="fn" id="isNull"><a name="isNull"></a><span class="type">bool</span> QLine::<span class="name">isNull</span>() const</h3> <p>Returns <code>true</code> if the line is not set up with valid start and end point; otherwise returns <code>false</code>.</p> <!-- @@@isNull --> <!-- $$$setP1[overload1]$$$setP1constQPoint& --> <h3 class="fn" id="setP1"><a name="setP1"></a><span class="type">void</span> QLine::<span class="name">setP1</span>(const <span class="type"><a href="qpoint.html">QPoint</a></span> &<i>p1</i>)</h3> <p>Sets the starting point of this line to <i>p1</i>.</p> <p>This function was introduced in Qt 4.4.</p> <p><b>See also </b><a href="qline.html#setP2">setP2</a>() and <a href="qline.html#p1">p1</a>().</p> <!-- @@@setP1 --> <!-- $$$setP2[overload1]$$$setP2constQPoint& --> <h3 class="fn" id="setP2"><a name="setP2"></a><span class="type">void</span> QLine::<span class="name">setP2</span>(const <span class="type"><a href="qpoint.html">QPoint</a></span> &<i>p2</i>)</h3> <p>Sets the end point of this line to <i>p2</i>.</p> <p>This function was introduced in Qt 4.4.</p> <p><b>See also </b><a href="qline.html#setP1">setP1</a>() and <a href="qline.html#p2">p2</a>().</p> <!-- @@@setP2 --> <!-- $$$setLine[overload1]$$$setLineintintintint --> <h3 class="fn" id="setLine"><a name="setLine"></a><span class="type">void</span> QLine::<span class="name">setLine</span>(<span class="type">int</span> <i>x1</i>, <span class="type">int</span> <i>y1</i>, <span class="type">int</span> <i>x2</i>, <span class="type">int</span> <i>y2</i>)</h3> <p>Sets this line to the start in <i>x1</i>, <i>y1</i> and end in <i>x2</i>, <i>y2</i>.</p> <p>This function was introduced in Qt 4.4.</p> <p><b>See also </b><a href="qline.html#setP1">setP1</a>(), <a href="qline.html#setP2">setP2</a>(), <a href="qline.html#p1">p1</a>(), and <a href="qline.html#p2">p2</a>().</p> <!-- @@@setLine --> <!-- $$$setPoints[overload1]$$$setPointsconstQPoint&constQPoint& --> <h3 class="fn" id="setPoints"><a name="setPoints"></a><span class="type">void</span> QLine::<span class="name">setPoints</span>(const <span class="type"><a href="qpoint.html">QPoint</a></span> &<i>p1</i>, const <span class="type"><a href="qpoint.html">QPoint</a></span> &<i>p2</i>)</h3> <p>Sets the start point of this line to <i>p1</i> and the end point of this line to <i>p2</i>.</p> <p>This function was introduced in Qt 4.4.</p> <p><b>See also </b><a href="qline.html#setP1">setP1</a>(), <a href="qline.html#setP2">setP2</a>(), <a href="qline.html#p1">p1</a>(), and <a href="qline.html#p2">p2</a>().</p> <!-- @@@setPoints --> <!-- $$$translate[overload1]$$$translateconstQPoint& --> <h3 class="fn" id="translate"><a name="translate"></a><span class="type">void</span> QLine::<span class="name">translate</span>(const <span class="type"><a href="qpoint.html">QPoint</a></span> &<i>offset</i>)</h3> <p>Translates this line by the given <i>offset</i>.</p> <!-- @@@translate --> <!-- $$$translate$$$translateintint --> <h3 class="fn" id="translate-1"><a name="translate-1"></a><span class="type">void</span> QLine::<span class="name">translate</span>(<span class="type">int</span> <i>dx</i>, <span class="type">int</span> <i>dy</i>)</h3> <p>This is an overloaded function.</p> <p>Translates this line the distance specified by <i>dx</i> and <i>dy</i>.</p> <!-- @@@translate --> <!-- $$$translated[overload1]$$$translatedconstQPoint& --> <h3 class="fn" id="translated"><a name="translated"></a><span class="type"><a href="qline.html#QLine">QLine</a></span> QLine::<span class="name">translated</span>(const <span class="type"><a href="qpoint.html">QPoint</a></span> &<i>offset</i>) const</h3> <p>Returns this line translated by the given <i>offset</i>.</p> <p>This function was introduced in Qt 4.4.</p> <!-- @@@translated --> <!-- $$$translated$$$translatedintint --> <h3 class="fn" id="translated-1"><a name="translated-1"></a><span class="type"><a href="qline.html#QLine">QLine</a></span> QLine::<span class="name">translated</span>(<span class="type">int</span> <i>dx</i>, <span class="type">int</span> <i>dy</i>) const</h3> <p>This is an overloaded function.</p> <p>Returns this line translated the distance specified by <i>dx</i> and <i>dy</i>.</p> <p>This function was introduced in Qt 4.4.</p> <!-- @@@translated --> <!-- $$$operator!=[overload1]$$$operator!=constQLine& --> <h3 class="fn" id="operator-not-eq"><a name="operator-not-eq"></a><span class="type">bool</span> QLine::<span class="name">operator!=</span>(const <span class="type"><a href="qline.html#QLine">QLine</a></span> &<i>line</i>) const</h3> <p>Returns <code>true</code> if the given <i>line</i> is not the same as <i>this</i> line.</p> <p>A line is different from another line if any of their start or end points differ, or the internal order of the points is different.</p> <!-- @@@operator!= --> <!-- $$$operator==[overload1]$$$operator==constQLine& --> <h3 class="fn" id="operator-eq-eq"><a name="operator-eq-eq"></a><span class="type">bool</span> QLine::<span class="name">operator==</span>(const <span class="type"><a href="qline.html#QLine">QLine</a></span> &<i>line</i>) const</h3> <p>Returns <code>true</code> if the given <i>line</i> is the same as <i>this</i> line.</p> <p>A line is identical to another line if the start and end points are identical, and the internal order of the points is the same.</p> <!-- @@@operator== --> </div> <div class="relnonmem"> <h2>Related Non-Members</h2> <!-- $$$operator<<[overload1]$$$operator<<QDataStream&constQLine& --> <h3 class="fn" id="operator-lt-lt"><a name="operator-lt-lt"></a><span class="type"><a href="qdatastream.html">QDataStream</a></span> &<span class="name">operator<<</span>(<span class="type"><a href="qdatastream.html">QDataStream</a></span> &<i>stream</i>, const <span class="type"><a href="qline.html#QLine">QLine</a></span> &<i>line</i>)</h3> <p>Writes the given <i>line</i> to the given <i>stream</i> and returns a reference to the stream.</p> <p><b>See also </b><a href="datastreamformat.html">Serializing Qt Data Types</a>.</p> <!-- @@@operator<< --> <!-- $$$operator>>[overload1]$$$operator>>QDataStream&QLine& --> <h3 class="fn" id="operator-gt-gt"><a name="operator-gt-gt"></a><span class="type"><a href="qdatastream.html">QDataStream</a></span> &<span class="name">operator>></span>(<span class="type"><a href="qdatastream.html">QDataStream</a></span> &<i>stream</i>, <span class="type"><a href="qline.html#QLine">QLine</a></span> &<i>line</i>)</h3> <p>Reads a line from the given <i>stream</i> into the given <i>line</i> and returns a reference to the stream.</p> <p><b>See also </b><a href="datastreamformat.html">Serializing Qt Data Types</a>.</p> <!-- @@@operator>> --> </div> </div> </div> </div> </div> </div> <div class="footer"> <p> <acronym title="Copyright">©</acronym> 2019 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>