What is the purpose of this updateImage variable?
In general it should all be more or less like this:
m_pt = me->pos();
}
addLineToPixmap(m_pt, me->pos());
}
addLineToPixmap(m_pt, me->pos());
m_pt = me->pos();
}
p.drawLine(from, to);
update();
}
void X::paintEvent(...) {
p.drawPixmap(m_pixmap);
}
private:
void X::mousePressEvent(QMouseEvent *me) {
m_pt = me->pos();
}
void X::mouseReleaseEvent(QMouseEvent *me) {
addLineToPixmap(m_pt, me->pos());
m_pt = QPoint();
}
void X::mouseMoveEvent(QMouseEvent *me) {
addLineToPixmap(m_pt, me->pos());
m_pt = me->pos();
}
void X::addLineToPixmap(QPoint from, QPoint to) {
QPainter p(&m_pixmap);
p.drawLine(from, to);
update();
}
void X::paintEvent(...) {
QPainter p(this);
p.drawPixmap(m_pixmap);
}
private:
QPoint m_pt;
QPixmap m_pixmap;
To copy to clipboard, switch view to plain text mode
Bookmarks