PDA

View Full Version : How to rotate only line and not the text?



sanujas
12th January 2013, 12:26
Hi All,
i want to rotate a line.and in front of line letter say 's' is there.
i want to keep angle for text 's' as 0(i.e. do not want to rotate it and only line to be rotated with letter 's' in front of it).how to do it?
if we use Q painter's rotate property when line is rotating letter 's' is also rotating





Thanks,
sanujas

wysota
12th January 2013, 12:30
Reverse the rotation transformation before painting the letter. You can also use QPainter::save() and QPainter::restore() to help revert the painter to previously saved state.

sanujas
12th January 2013, 12:48
Means do you want to say
i should add following lines before painting text?
painter.save;
painter.rotate(-angle)//angle is int
painter.drawText(50, 0, "s");//for e.g.
painter.restore;
i was tried to use painter.save and painter.restore as above
ok let me try 2nd line which i was not done.


Thanks,
sanujas

wysota
12th January 2013, 13:08
Well... either do this:


painter.rotate(angle);
painter.drawLine(...);
painter.rotate(-angle);
painter.drawText(...);

or


painter.save();
painter.rotate(angle);
painter.drawLine(...);
painter.restore();
painter.drawText(...);

sanujas
15th January 2013, 10:12
Using first option given by you i could able to stop rotating letter.now i am trying to write text infront of line which rotates from 0 to 360 deg. i used the formula for points on circumference of a circle(x=origin+radius*cos(angle),y=origin+radius* sin(angle)).but it is getting some offset and line and text are not synchronised.e.g. if line is in 1st quadrant the letter will be in any other quadrant.so how to nullify that offset?

wysota
15th January 2013, 12:38
It's pure math, there isn't much I can help you here with. You just need to correct your calculations.

sanujas
15th January 2013, 15:36
yah you are right,it was related to maths calculation only, i was thinking something yet remained to do in QT.My problem got solved.

Thank,
sanujas