QT开发中文网

QPainter绘制的矩形,旋转之后的四个顶点坐标怎么获取

在使用QPainter绘制矩形并旋转之后,可以通过QTransform类来获取旋转后的矩形四个顶点的坐标。下面是一个示例代码片段:

// 创建QPainterPath对象
QPainterPath path;
path.addRect(rect); // 这里的rect是原始矩形

// 创建QTransform对象,并进行旋转操作
QTransform transform;
transform.rotate(angle); // 这里的angle是旋转角度

// 应用变换到路径上
path = transform.map(path);

// 获取四个顶点的坐标
QPointF topLeft = path.boundingRect().topLeft();
QPointF topRight = path.boundingRect().topRight();
QPointF bottomLeft = path.boundingRect().bottomLeft();
QPointF bottomRight = path.boundingRect().bottomRight();

// 打印结果
qDebug() << "Top Left: " << topLeft;
qDebug() << "Top Right: " << topRight;
qDebug() << "Bottom Left: " << bottomLeft;
qDebug() << "Bottom Right: " << bottomRight;

请注意,这里假设你已经创建了合适的rectangle变量,并且使用了正确的坐标系。根据实际情况,你可能需要进行一些调整或适应。


内容由零声教学AI助手提供,问题来源于学员提问

本站部分文章来源于网络,版权归原作者所有,如有侵权请联系站长删除。
转载请注明出处:https://qt.0voice.com/?id=8839

分享:
扫描分享到社交APP
上一篇
下一篇
发表列表
游客 游客
此处应有掌声~
评论列表

还没有评论,快来说点什么吧~

联系我们

在线咨询: 点击这里给我发消息

微信号:3007537140

上班时间: 10:30-22:30

关注我们
x

注册

已经有帐号?