
Originally Posted by
wysota
Change the two QPoint members into a list or vector of points and don't null out the vector on mouse release. Then in the paint event iterate over the list and draw all the points.
SOmething like this. But unlucky
void setRasterOpTest
::mousePressEvent( QMouseEvent *e
){ m_vector<<e->pos();
}
void setRasterOpTest
::mouseMoveEvent( QMouseEvent *e
){ m_vector<<e->pos();
update();
}
void setRasterOpTest
::mouseReleaseEvent(QMouseEvent *e
){ m_vector<<e->pos();
update();
}
//... (do regular stuff here)
if( m_vector.count() <= 0 )
return;
painter.begin(this);
painter.setPen( Qt::black );
painter.drawLines ( m_vector );
painter.end();
}
void setRasterOpTest::mousePressEvent( QMouseEvent *e ){
m_vector<<e->pos();
}
void setRasterOpTest::mouseMoveEvent( QMouseEvent *e ){
m_vector<<e->pos();
update();
}
void setRasterOpTest::mouseReleaseEvent(QMouseEvent *e){
m_vector<<e->pos();
update();
}
void setRasterOpTest::paintEvent(QPaintEvent *e){
//... (do regular stuff here)
if( m_vector.count() <= 0 )
return;
QPainter painter;
painter.begin(this);
painter.setPen( Qt::black );
painter.drawLines ( m_vector );
painter.end();
}
To copy to clipboard, switch view to plain text mode
Also let me explain, I dont want a continuous flow of line as in scribble example but only straight line. I start from a point and when I release the mouse a straight line should be drawn. Then again I click on some other point and when I release the mouse another straight line should be drawn.
Thanks for your understanding
Bookmarks