paintEvent and Pixmap - not deleting old content!
Hi,
I would like to paint on a widget, but every time I call another function, it deletes the old widget content.
I already tried to create an instance of Pixmap with
and removed fill() but this doesn't work.
Why is it possible to call
but not
Here is the code snippet:
Code:
void ClientWindow
::paintEvent(QPaintEvent * /* event */) {
painter.drawPixmap(0, 0, pixmap);
if (hasFocus()) {
option.initFrom(this);
option.backgroundColor = palette().dark().color();
//painter.drawPrimitive(QStyle::PE_FrameFocusRect, option);
}
}
void ClientWindow::drawCircle(int x, int y, int width, int height)
{
pixmap.fill(this, 0, 0);
painter.initFrom(this);
pen.setStyle(Qt::SolidLine);
pen.setWidth(3);
pen.setBrush(Qt::green);
pen.setCapStyle(Qt::RoundCap);
pen.setJoinStyle(Qt::RoundJoin);
brush.setStyle(Qt::SolidPattern);
painter.setPen(pen);
//painter.setBrush(brush);
if (antialiased)
painter.
setRenderHint(QPainter::Antialiasing,
true);
painter.drawEllipse(x, y, width, height);
update();
}
void ClientWindow::drawLine(int x1, int y1, int x2, int y2)
{
pixmap.fill(this, 0, 0);
painter.initFrom(this);
//...
Re: paintEvent and Pixmap - not deleting old content!
I'm bit confused what you're trying to do here.
Why you are drawing widget to pixmap?
Why you are drawing in each function?
Can't you cache the widget image once and then draw on top of it multiple times?
If the content of the widget changes often, there's no point caching it.
If the content doesn't change but your drawing do - then create separate cache for widget and separate for drawings and draw second on top of the first one.
Like I said - I'm bit confused so you need to explain what you're trying to achieve bit better.