[SOLVED] Drawing bezier curve using four segments

Issue

I am trying to draw a bezier curve which uses 4 control points to draw a curve. However when I run my program, after 4 clicks with mouse I only see one pixel being drawn, am I missing something in my code? How can I get this to work properly?


void MyWindow::mousePressEvent(QMouseEvent *event)
{
    if(event->button() == Qt::LeftButton)
    {
        x0 = event->x();
        y0 = event->y();

        point.setX(x0);
        point.setY(y0);
        std::vector<QPoint> myv;
        myv.push_back(point);
        counter+=1;
        std::cout<<counter<<std::endl;

        if(counter%4==0) {
            drawBezier(myv[0], myv[1], myv[2], myv[3]);
        }
      
    }

    update();

}

enter image description here

Solution

myv is local variable and you dont save its state to the new mousePressEvent
Get some "debug" info and see what you receive in drawBezier function.

Answered By – Kaktuts

Answer Checked By – Gilberto Lyons (BugsFixing Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *