StarShaper
13th February 2012, 19:31
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
pixmap = QPixmap(pixmap);
and removed fill() but this doesn't work.
Why is it possible to call
pixmap = QPixmap(size());
but not
pixmap = QPixmap(pixmap); ??
Here is the code snippet:
void ClientWindow::paintEvent(QPaintEvent * /* event */)
{
QStylePainter painter(this);
painter.drawPixmap(0, 0, pixmap);
if (hasFocus()) {
QStyleOptionFocusRect option;
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 = QPixmap(size());
pixmap.fill(this, 0, 0);
QPainter painter(&pixmap);
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 = QPixmap(size());
pixmap.fill(this, 0, 0);
QPainter painter(&pixmap);
painter.initFrom(this);
//...
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
pixmap = QPixmap(pixmap);
and removed fill() but this doesn't work.
Why is it possible to call
pixmap = QPixmap(size());
but not
pixmap = QPixmap(pixmap); ??
Here is the code snippet:
void ClientWindow::paintEvent(QPaintEvent * /* event */)
{
QStylePainter painter(this);
painter.drawPixmap(0, 0, pixmap);
if (hasFocus()) {
QStyleOptionFocusRect option;
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 = QPixmap(size());
pixmap.fill(this, 0, 0);
QPainter painter(&pixmap);
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 = QPixmap(size());
pixmap.fill(this, 0, 0);
QPainter painter(&pixmap);
painter.initFrom(this);
//...