How to rotate text for drawText?

喜欢而已 提交于 2019-12-01 17:52:27

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);

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

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().

painter->save(); // saves current painter state
// painter->rotate(45); clockwise rotation 
// painter->rotate(-45); counter clockwise rotation
painter->restore(); // restores painter state

In order to rotate your text (and any other drawable object) drawn by painter just call

painter->rotate(yourAngle);

before

painter->drawText();

If you wish to return to previous state call rotate again.

painter->rotate(-yourAngle);
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!