Arthur计算角度的方法是正确的,但实际上,QT提供了在特定角度绘制线条的内置方法,特别QLineF是QLineF标题中类的功能:
#include <QLineF>
void AngleDemo::paintEvent(QPaintEvent *)
{
QPainter painter(this);
painter.setPen(QPen(Qt::black,1));
/* Create the line object: */
QLineF angleline;
/* Set the origin: */
angleline.setP1(QPointF(80,80));
/* Set the angle and length: */
angleline.setAngle(45);
angleline.setLength(50);
/* Draw the line: */
painter.drawLine(angleline);
}
Run Code Online (Sandbox Code Playgroud)
将线的角度设置为给定角度(以度为单位).这将改变线的第二点的位置,使得线具有给定的角度.
角度的正值表示逆时针,而负值表示顺时针方向.
零度位于3点钟位置.
该功能在Qt 4.4中引入.
| 归档时间: |
|
| 查看次数: |
4599 次 |
| 最近记录: |