使用四段绘制贝塞尔曲线
我正在尝试绘制一条贝塞尔曲线,它使用 4 个控制点来绘制曲线。然而,当我运行我的程序时,用鼠标点击 4 次后,我只看到绘制了一个像素,我的代码中是否遗漏了某些内容?我怎样才能让它正常工作?
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();
}
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();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
myv
是局部变量,您不会将其状态保存到新的mousePressEvent
获取一些“调试”信息并查看在
drawBezier
函数中收到的内容。myv
is local variable and you dont save its state to the newmousePressEvent
Get some "debug" info and see what you receive in
drawBezier
function.