如何旋转drawText的文本? [英] How to rotate text for drawText?

查看:98
本文介绍了如何旋转drawText的文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将文字旋转45度吗?

I would like to rotate the text 45 degrees?

QFont font;
font.setPixelSize(12);

//grid
for(int i = 0; i < 10; i++){
    painter->drawLine(100, 100 + i * 800/9, 900, 100 + i * 800/9);
    str = QString::number((double)9 - i, 'd', 1);
    painter->setFont(font);
    painter->drawText(75, 100 + i * 800/9 - 6, 40, 40, 1, str);
}

推荐答案

painter-> drawText(75,100 + i *之前)插入 painter-> rotate(45); 800/9-6,40,40,1,str); painter-> rotate(-45); 之后(以恢复坐标系的旋转角度):

Insert painter->rotate(45); before painter->drawText(75, 100 + i * 800/9 - 6, 40, 40, 1, str); and painter->rotate(-45); after (to restore the rotation angle of the coordinate system):

painter->rotate(45);
painter->drawText(75, 100 + i * 800/9 - 6, 40, 40, 1, str);
painter->rotate(-45);

取决于您是顺时针还是逆时针45度,可能需要取消旋转角度.

Depending on if you mean 45 degrees clockwise or anti-clockwise you may need to negate the rotation angles.

旋转坐标系后,所有绘制的油漆都将被旋转,直到恢复画家为止.保存和恢复画家状态的一种简便方法是使用 QPainter :: save() QPainter :: restore().

After you rotate the coordinate system, everything you paint will be painted rotated until you restore the painter. A convenient way of saving and restoring the state of the painter is using QPainter::save() and QPainter::restore().

这篇关于如何旋转drawText的文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆