{
paintFlag = 0;
if(ev->button()==Qt::LeftButton)
{
this->x = ev->x();
this->y = ev->y();
//store 1st point
if(firstClick)
{
this->x = ev->x();
this->y = ev->y();
x1 = x;
y1 = y;
emit Mouse_Pressed();
firstClick = false;
}
//Mouse Pressed Again! 2nd point
if(firstClick)
{
x2 = x;
y2 = y;
emit Mouse_Pressed();
firstClick = true;
}
paintFlag = 1;
//calculateAngle(x, y, x1, y2);
}
}
void my_qlabel::mousePressEvent(QMouseEvent *ev)
{
paintFlag = 0;
if(ev->button()==Qt::LeftButton)
{
this->x = ev->x();
this->y = ev->y();
//store 1st point
if(firstClick)
{
this->x = ev->x();
this->y = ev->y();
x1 = x;
y1 = y;
emit Mouse_Pressed();
firstClick = false;
}
//Mouse Pressed Again! 2nd point
if(firstClick)
{
x2 = x;
y2 = y;
emit Mouse_Pressed();
firstClick = true;
}
paintFlag = 1;
//calculateAngle(x, y, x1, y2);
}
}
To copy to clipboard, switch view to plain text mode
paint event:
{
if(paintFlag == 1)
{
paintpen.setWidth(4);
linepen.setWidth(4);
p1.setX(x1);
p1.setY(y1);
painter.setPen(paintpen);
painter.drawPoint(p1);
p2.setX(x2);
p2.setY(y2);
painter.setPen(paintpen);
painter.drawPoint(p2);
painter.setPen(linepen);
painter.drawLine(p1, p2);
}
update();
}
void my_qlabel::paintEvent(QPaintEvent *e)
{
if(paintFlag == 1)
{
QPainter painter(this);
QPen paintpen(Qt::red);
paintpen.setWidth(4);
QPen linepen(Qt::black);
linepen.setWidth(4);
QPoint p1;
p1.setX(x1);
p1.setY(y1);
painter.setPen(paintpen);
painter.drawPoint(p1);
QPoint p2;
p2.setX(x2);
p2.setY(y2);
painter.setPen(paintpen);
painter.drawPoint(p2);
painter.setPen(linepen);
painter.drawLine(p1, p2);
}
update();
}
To copy to clipboard, switch view to plain text mode
It starts from point(0, 0) instead of where user clicks
when user does click it creates an end point & a line from the (0, 0)
Goal: user must click start point, click end point, line to be drawn between 2 points, and points must be saved for later calculations
I know moreOrLess how to do it, just cant seem to get my head around this mouse clicking
Kind Regards
Bookmarks