Why would you need a pen for that?
Why would you need a pen for that?
You take the code wysota already wrote for you, and you replace the alpha value with 0 instead of 255 in the setPixel() calls.Also, how would i construct QPen to erase the overlay ?
You seem to be confused about the difference between the virtual "pen", "eraser" and other tools you might use in a drawing application and a QPen used by QPainter. Totally unrelated concepts.
To get smooth drawing I used the following code taking reference from the Scribble example.
Qt Code:
// if (eraseFlag == true) // painter.setPen(QPen(QBrush(QColor(0, 0, 0, 0)), myPenWidth, Qt::SolidLine, Qt::RoundCap, // Qt::RoundJoin)); // else Qt::RoundJoin)); painter.drawLine(lastPoint, endPoint); int rad = (myPenWidth / 2) + 2; .adjusted(-rad, -rad, +rad, +rad)); lastPoint = endPoint;To copy to clipboard, switch view to plain text mode
where
Qt Code:
myPenWidth = 3; myPenColor = Qt::red;To copy to clipboard, switch view to plain text mode
Trying to implement erasing in this.
One more feature, sorry to extend in the same question but it's because the context has already been set.
In order to implement scaling on the wheel event I did the following:
Qt Code:
void { scaleFactor += ((float)event->delta()/1200.0); update(); }To copy to clipboard, switch view to plain text mode
and in the paintEvent:
Qt Code:
void { p.scale(scaleFactor, scaleFactor); p.drawPixmap(0, 0, m_base); p.drawImage(0, 0, m_mask); }To copy to clipboard, switch view to plain text mode
My widget hierarchy is as below:
Mainwindow
- Grid Layout
- Scrollarea
- MyCustomDrawing Canvas Widget (created just like the code wysota suggested above)
I am not getting the scrollbars on scaling the image. I realize I am drawing the scaled image again, instead of resizing the widget. I tried using resize on the widget but it didn't work. What I am doing wrong ?
Set the widgetResizable property of the scroll area to true.
Okay so for erasing I did the following, may be this will be useful to someone.
Qt Code:
To copy to clipboard, switch view to plain text mode
To understand the Composition Modes : http://doc.qt.io/qt-5/qpainter.html#...itionMode-enum
Thanks.
P.S.: Still working on the scrollarea stuff. Once done will update here.
I think it might be faster to use composition mode CLEAR. It erases whatever pixels are there.
Bookmarks