Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
QLine Class Reference

\inmodule QtCore More...

#include <qline.h>

+ Collaboration diagram for QLine:

Public Member Functions

constexpr QLine ()
 Constructs a null line.
 
constexpr QLine (const QPoint &pt1, const QPoint &pt2)
 Constructs a line object that represents the line between p1 and p2.
 
constexpr QLine (int x1, int y1, int x2, int y2)
 Constructs a line object that represents the line between (x1, y1) and (x2, y2).
 
constexpr bool isNull () const
 Returns true if the line does not have distinct start and end points; otherwise returns false.
 
constexpr QPoint p1 () const
 Returns the line's start point.
 
constexpr QPoint p2 () const
 Returns the line's end point.
 
constexpr int x1 () const
 Returns the x-coordinate of the line's start point.
 
constexpr int y1 () const
 Returns the y-coordinate of the line's start point.
 
constexpr int x2 () const
 Returns the x-coordinate of the line's end point.
 
constexpr int y2 () const
 Returns the y-coordinate of the line's end point.
 
constexpr int dx () const
 Returns the horizontal component of the line's vector.
 
constexpr int dy () const
 Returns the vertical component of the line's vector.
 
void translate (const QPoint &p)
 Translates this line by the given offset.
 
void translate (int dx, int dy)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Translates this line the distance specified by dx and dy.
 
constexpr QLine translated (const QPoint &p) const
 
constexpr QLine translated (int dx, int dy) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
constexpr QPoint center () const
 
void setP1 (const QPoint &p1)
 
void setP2 (const QPoint &p2)
 
void setPoints (const QPoint &p1, const QPoint &p2)
 
void setLine (int x1, int y1, int x2, int y2)
 
constexpr bool operator== (const QLine &d) const noexcept
 Returns true if the given line is the same as this line.
 
constexpr bool operator!= (const QLine &d) const noexcept
 Returns true if the given line is not the same as this line.
 
constexpr QLineF toLineF () const noexcept
 

Related Symbols

(Note that these are not member symbols.)

QDataStreamoperator<< (QDataStream &stream, const QLine &line)
 Writes the given line to the given stream and returns a reference to the stream.
 
QDataStreamoperator>> (QDataStream &stream, QLine &line)
 Reads a line from the given stream into the given line and returns a reference to the stream.
 

Detailed Description

\inmodule QtCore

The QLine class provides a two-dimensional vector using integer precision.

A QLine 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 QLineF constructor to retrieve a floating point copy.

\table \row

  • \inlineimage qline-point.png
  • \inlineimage qline-coordinates.png \endtable

The positions of the line's start and end points can be retrieved using the p1(), x1(), y1(), p2(), x2(), and y2() functions. The dx() and dy() functions return the horizontal and vertical components of the line. Use isNull() to determine whether the QLine represents a valid line or a null line.

Finally, the line can be translated a given offset using the translate() function.

See also
QLineF, QPolygon, QRect

Definition at line 17 of file qline.h.

Constructor & Destructor Documentation

◆ QLine() [1/3]

constexpr QLine::QLine ( )
inlineconstexpr

Constructs a null line.

Definition at line 65 of file qline.h.

Referenced by translated().

+ Here is the caller graph for this function:

◆ QLine() [2/3]

constexpr QLine::QLine ( const QPoint & pt1,
const QPoint & pt2 )
inlineconstexpr

Constructs a line object that represents the line between p1 and p2.

Definition at line 67 of file qline.h.

◆ QLine() [3/3]

constexpr QLine::QLine ( int x1,
int y1,
int x2,
int y2 )
inlineconstexpr

Constructs a line object that represents the line between (x1, y1) and (x2, y2).

Definition at line 69 of file qline.h.

Member Function Documentation

◆ center()

constexpr QPoint QLine::center ( ) const
inlineconstexpr
Since
5.8

Returns the center point of this line. This is equivalent to (p1() + p2()) / 2, except it will never overflow.

Definition at line 137 of file qline.h.

References QPoint::x(), and QPoint::y().

+ Here is the call graph for this function:

◆ dx()

constexpr int QLine::dx ( ) const
inlineconstexpr

Returns the horizontal component of the line's vector.

See also
dy()

Definition at line 106 of file qline.h.

References QPoint::x().

+ Here is the call graph for this function:

◆ dy()

constexpr int QLine::dy ( ) const
inlineconstexpr

Returns the vertical component of the line's vector.

See also
dx()

Definition at line 111 of file qline.h.

References QPoint::y().

+ Here is the call graph for this function:

◆ isNull()

constexpr bool QLine::isNull ( ) const
inlineconstexpr

Returns true if the line does not have distinct start and end points; otherwise returns false.

Definition at line 71 of file qline.h.

◆ operator!=()

bool QLine::operator!= ( const QLine & line) const
inlineconstexprnoexcept

Returns true if the given line is not the same as this line.

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.

Definition at line 52 of file qline.h.

References d.

◆ operator==()

constexpr bool QLine::operator== ( const QLine & line) const
inlineconstexprnoexcept

Returns true if the given line is the same as this line.

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.

Definition at line 164 of file qline.h.

References d.

◆ p1()

constexpr QPoint QLine::p1 ( ) const
inlineconstexpr

Returns the line's start point.

See also
x1(), y1(), p2()

Definition at line 96 of file qline.h.

Referenced by clipStraightLine(), QRasterPaintEngine::drawLines(), and QX11PaintEngine::drawRects().

+ Here is the caller graph for this function:

◆ p2()

constexpr QPoint QLine::p2 ( ) const
inlineconstexpr

Returns the line's end point.

See also
x2(), y2(), p1()

Definition at line 101 of file qline.h.

Referenced by clipStraightLine(), QRasterPaintEngine::drawLines(), and QX11PaintEngine::drawRects().

+ Here is the caller graph for this function:

◆ setLine()

void QLine::setLine ( int x1,
int y1,
int x2,
int y2 )
inline
Since
4.4

Sets this line to the start in x1, y1 and end in x2, y2.

See also
setP1(), setP2(), p1(), p2()

Definition at line 158 of file qline.h.

◆ setP1()

void QLine::setP1 ( const QPoint & p1)
inline
Since
4.4

Sets the starting point of this line to p1.

See also
setP2(), p1()

Definition at line 142 of file qline.h.

◆ setP2()

void QLine::setP2 ( const QPoint & p2)
inline
Since
4.4

Sets the end point of this line to p2.

See also
setP1(), p2()

Definition at line 147 of file qline.h.

◆ setPoints()

void QLine::setPoints ( const QPoint & p1,
const QPoint & p2 )
inline
Since
4.4

Sets the start point of this line to p1 and the end point of this line to p2.

See also
setP1(), setP2(), p1(), p2()

Definition at line 152 of file qline.h.

◆ toLineF()

constexpr QLineF QLine::toLineF ( ) const
inlineconstexprnoexcept
Since
6.4

Returns this line as a line with floating point accuracy.

See also
QLineF::toLine()

Definition at line 356 of file qline.h.

◆ translate() [1/2]

void QLine::translate ( const QPoint & p)
inline

Translates this line by the given offset.

Definition at line 116 of file qline.h.

Referenced by translate().

+ Here is the caller graph for this function:

◆ translate() [2/2]

void QLine::translate ( int dx,
int dy )
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Translates this line the distance specified by dx and dy.

Definition at line 122 of file qline.h.

References translate().

+ Here is the call graph for this function:

◆ translated() [1/2]

constexpr QLine QLine::translated ( const QPoint & offset) const
inlineconstexpr
Since
4.4

Returns this line translated by the given offset.

Definition at line 127 of file qline.h.

References QLine().

Referenced by translated().

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

◆ translated() [2/2]

constexpr QLine QLine::translated ( int dx,
int dy ) const
inlineconstexpr

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

Since
4.4

Returns this line translated the distance specified by dx and dy.

Definition at line 132 of file qline.h.

References translated().

+ Here is the call graph for this function:

◆ x1()

constexpr int QLine::x1 ( ) const
inlineconstexpr

Returns the x-coordinate of the line's start point.

See also
p1()

Definition at line 76 of file qline.h.

References QPoint::x().

Referenced by QPaintEngine::drawLines(), and QTransform::map().

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

◆ x2()

constexpr int QLine::x2 ( ) const
inlineconstexpr

Returns the x-coordinate of the line's end point.

See also
p2()

Definition at line 86 of file qline.h.

References QPoint::x().

Referenced by QPaintEngine::drawLines(), and QTransform::map().

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

◆ y1()

constexpr int QLine::y1 ( ) const
inlineconstexpr

Returns the y-coordinate of the line's start point.

See also
p1()

Definition at line 81 of file qline.h.

References QPoint::y().

Referenced by QPaintEngine::drawLines(), and QTransform::map().

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

◆ y2()

constexpr int QLine::y2 ( ) const
inlineconstexpr

Returns the y-coordinate of the line's end point.

See also
p2()

Definition at line 91 of file qline.h.

References QPoint::y().

Referenced by QPaintEngine::drawLines(), and QTransform::map().

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

Friends And Related Symbol Documentation

◆ operator<<()

QDataStream & operator<< ( QDataStream & stream,
const QLine & line )
related

Writes the given line to the given stream and returns a reference to the stream.

See also
{Serializing Qt Data Types}

Definition at line 260 of file qline.cpp.

References line.

◆ operator>>()

QDataStream & operator>> ( QDataStream & stream,
QLine & line )
related

Reads a line from the given stream into the given line and returns a reference to the stream.

See also
{Serializing Qt Data Types}

Definition at line 275 of file qline.cpp.

References line, p1, and p2.


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