QLine Class

QLine 类提供了使用整数精度的二维向量。更多

Header: #include <QLine>
CMake: find_package(Qt6 REQUIRED COMPONENTS Core)
target_link_libraries(mytarget PRIVATE Qt6::Core)
qmake: QT += core

该类可等价比较

该类可与QLineF 进行等价比较

公共函数

QLine()
QLine(const QPoint &p1, const QPoint &p2)
QLine(int x1, int y1, int x2, int y2)
QPoint p1() const
QPoint p2() const
int x1() const
int x2() const
int y1() const
int y2() const
QPoint center() const
int dx() const
int dy() const
bool isNull() const
void setP1(const QPoint &p1)
void setP2(const QPoint &p2)
void setLine(int x1, int y1, int x2, int y2)
void setPoints(const QPoint &p1, const QPoint &p2)
(since 6.4) QLineF toLineF() const
void translate(const QPoint &offset)
void translate(int dx, int dy)
QLine translated(const QPoint &offset) const
QLine translated(int dx, int dy) const
bool operator!=(const QLine &lhs, const QLine &rhs)
QDataStream &operator<<(QDataStream &stream, const QLine &line)
bool operator==(const QLine &lhs, const QLine &rhs)
QDataStream &operator>>(QDataStream &stream, QLine &line)

详细描述

QLine 描述二维曲面上有限长度的直线(或线段)。直线的起点和终点使用整数点坐标精度指定。使用QLineF 构造函数可获取浮点副本。

可以使用p1(),x1(),y1(),p2(),x2() 和y2() 函数获取直线起点和终点的位置。dx() 和dy() 函数返回直线的水平和垂直分量。使用isNull() 可以确定 QLine 代表有效直线还是空直线。

最后,可以使用translate() 函数将线条平移到给定的偏移量。

另请参见 QLineF,QPolygon, 和QRect

成员函数文档

[constexpr] QLine::QLine()

构造空行。

[constexpr] QLine::QLine(const QPoint &p1, const QPoint &p2)

构造一个表示p1p2 之间直线的直线对象。

[constexpr] QLine::QLine(int x1, int y1, int x2, int y2)

构建表示 (x1,y1) 和 (x2,y2) 之间直线的直线对象。

[constexpr] QPoint QLine::p1() const

返回直线的起点。

另请参阅 setP1()、x1()、y1() 和p2()。

[constexpr] QPoint QLine::p2() const

返回直线的终点。

另请参阅 setP2()、x2()、y2() 和p1()。

[constexpr] int QLine::x1() const

返回直线起点的 x 坐标。

另请参见 p1()。

[constexpr] int QLine::x2() const

返回直线终点的 x 坐标。

另请参见 p2()。

[constexpr] int QLine::y1() const

返回直线起点的 Y 坐标。

另请参见 p1()。

[constexpr] int QLine::y2() const

返回直线终点的 Y 坐标。

另请参见 p2()。

[constexpr] QPoint QLine::center() const

返回这条直线的中心点。这等同于 (p1() +p2()) / 2,但它永远不会溢出。

[constexpr] int QLine::dx() const

返回直线矢量的水平分量。

另请参见 dy()。

[constexpr] int QLine::dy() const

返回直线矢量的垂直分量。

另请参见 dx()。

[constexpr] bool QLine::isNull() const

如果直线没有明显的起点和终点,则返回true ;否则返回false

void QLine::setP1(const QPoint &p1)

将此行的起点设置为p1

另请参阅 setP2() 和p1()。

void QLine::setP2(const QPoint &p2)

将此行的终点设置为p2

另请参阅 setP1() 和p2()。

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

将此行设置为以x1,y1 为起点,以x2,y2 为终点。

另请参阅 setP1()、setP2()、p1() 和p2()。

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

将此行的起点设置为p1 ,将此行的终点设置为p2

另请参阅 setP1()、setP2()、p1() 和p2()。

[constexpr noexcept, since 6.4] QLineF QLine::toLineF() const

以浮点精度返回此行。

此函数在 Qt 6.4 中引入。

另请参阅 QLineF::toLine()。

void QLine::translate(const QPoint &offset)

用给定的offset 翻译这一行。

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

这是一个重载函数。

按照dxdy 指定的距离平移此行。

[constexpr] QLine QLine::translated(const QPoint &offset) const

Returns this line translated by the givenoffset.

[constexpr] QLine QLine::translated(int dx, int dy) const

这是一个重载函数。

dxdy 指定的距离返回该行的平移结果。

相关非会员

[constexpr noexcept] bool operator!=(const QLine &lhs, const QLine &rhs)

如果直线lhs 与直线rhs 不相同,则返回true

如果一条直线与另一条直线的起点或终点不同,或点的内部顺序不同,则该直线与另一条直线不同。

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

将给定的line 写入给定的stream ,并返回对该数据流的引用。

另请参阅 序列化 Qt 数据类型

[constexpr noexcept] bool operator==(const QLine &lhs, const QLine &rhs)

如果直线lhs 与直线rhs 相同,则返回true

如果起点和终点相同,且点的内部顺序也相同,则一条直线与另一条直线相同。

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

将一行数据从给定的stream 读入给定的line ,并返回对该数据流的引用。

另请参阅 序列化 Qt 数据类型

© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. 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.