我自己做个了一个看图程序,我想实现在图片上画线的功能,在程序中添加了
。。。。。。
。。。。。。
void MyView::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton)
{
lastPoint = event->pos();
scribbling = true;
}
}
void MyView::mouseMoveEvent(QMouseEvent *event)
{
if ((event->buttons() & Qt::LeftButton) && scribbling)
drawLineTo(event->pos());
}
void MyView::mouseReleaseEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton && scribbling)
{
drawLineTo(event->pos());
scribbling = false;
}
}
。。。。。。
。。。。。。
void MyView::drawLineTo(const QPoint &endPoint)
{
QPainter painter(this);
painter.setPen(QPen(Qt::blue, 1, Qt::SolidLine, Qt::RoundCap,
Qt::RoundJoin));
painter.drawLine(lastPoint, endPoint);
lastPoint = endPoint;
}
为什么还是不能画线呢???
QPainter painter(this);
是不是这里的问题,没有明确画的对象?
如果想实现这个功能应在有什么步骤呢??
请大家帮忙,谢谢。
[ 此贴被XChinux在2006-12-24 09:16重新编辑 ]