{
if (event->button() == Qt::LeftButton) {
lastPoint = event->globalPos();
scribbling = true;
}
}
{
if ((event->buttons() & Qt::LeftButton) && scribbling)
drawLineTo(event->globalPos());
}
{
QRect dirtyRect
= event
->rect
();
painter.drawPixmap(dirtyRect, scaled, dirtyRect);
}
void MainWindow
::drawLineTo(const QPoint &endPoint
) {
painter.
setPen(QPen(myPenColor, myPenWidth, Qt
::SolidLine, Qt
::RoundCap,
Qt::RoundJoin));
//painter.begin(&scaled);
painter.drawLine(lastPoint, endPoint);
int rad = (myPenWidth / 2) + 2;
update
(QRect(lastPoint, endPoint
).
normalized().
adjusted(-rad,
-rad,
+rad,
+rad
));
lastPoint = endPoint;
//painter.end();
}
{
if (event->button() == Qt::LeftButton && scribbling) {
drawLineTo(event->globalPos());
scribbling = false;
}
ui->Image -> setPixmap (scaled);
}
void MainWindow::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton) {
lastPoint = event->globalPos();
scribbling = true;
}
}
void MainWindow::mouseMoveEvent(QMouseEvent *event)
{
if ((event->buttons() & Qt::LeftButton) && scribbling)
drawLineTo(event->globalPos());
}
void MainWindow::paintEvent(QPaintEvent *event)
{
QPainter painter(&scaled);
QRect dirtyRect = event->rect();
painter.drawPixmap(dirtyRect, scaled, dirtyRect);
}
void MainWindow::drawLineTo(const QPoint &endPoint)
{
QPainter painter(&scaled);
painter.setPen(QPen(myPenColor, myPenWidth, Qt::SolidLine, Qt::RoundCap,
Qt::RoundJoin));
//painter.begin(&scaled);
painter.drawLine(lastPoint, endPoint);
int rad = (myPenWidth / 2) + 2;
update(QRect(lastPoint, endPoint).normalized().adjusted(-rad, -rad, +rad, +rad));
lastPoint = endPoint;
//painter.end();
}
void MainWindow::mouseReleaseEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton && scribbling) {
drawLineTo(event->globalPos());
scribbling = false;
}
ui->Image -> setPixmap (scaled);
}
To copy to clipboard, switch view to plain text mode
Bookmarks