c++ - How to draw a line at angle in QT? -
i have co-ordinate , angle. want draw line co-ordinate upto length specified angle. how can achieve this?? can give idea?
arthur's way of computing angle correct, actually, qt provides built-in methods of drawing lines @ specific angles, in particular functions of qlinef
class in qlinef
header:
#include <qlinef> void angledemo::paintevent(qpaintevent *) { qpainter painter(this); painter.setpen(qpen(qt::black,1)); /* create line object: */ qlinef angleline; /* set origin: */ angleline.setp1(qpointf(80,80)); /* set angle , length: */ angleline.setangle(45); angleline.setlength(50); /* draw line: */ painter.drawline(angleline); }
from online documentation of setangle()
function:
sets angle of line given angle (in degrees). change position of second point of line such line has given angle.
positive values angles mean counter-clockwise while negative values mean clockwise direction.
zero degrees @ 3 o'clock position.
this function introduced in qt 4.4.
Comments
Post a Comment