[Qt-interest] Painting issue with eraseRect
Murphy, Sean M.
sean.murphy at gd-ais.com
Fri Apr 10 21:50:44 CEST 2009
I don't have a specific answer to fixing the background, but when I'm
doing stuff like you're trying to do, I use a
QGraphicsView/QGraphicsScene setup. Then everything you're dealing with
are QGraphicsItem's. This allows you control each object separately, so
your grid could be formed from a bunch of QGraphicsLineItem's and you
could just set new end points of the lines to shrink them to create a
gap around an intersection, then use a QGraphicsTextItem to write your
text. The background would just be a QGraphicsPixmapItem that doesn't
get dirtied up by changes that you're making. That white spherical
thing would also be another QGraphicsPixmapItem.
Sean
-----Original Message-----
From: qt-interest-bounces at trolltech.com
[mailto:qt-interest-bounces at trolltech.com] On Behalf Of Adam Connell
Sent: Friday, April 10, 2009 3:37 PM
To: qt-interest at trolltech.com
Subject: [Qt-interest] Painting issue with eraseRect
Greetings,
I am using a tileable PNG image as the background to a QWidget. I then
draw a grid on top of the background. So far so good. Occasionally I
need to label an intersection of the grid. Here I run into a problem.
Simply drawing the text on top of of the grid leaves the text illegible,
so I perform an eraseRect() on the intersection of interest. Instead of
repainting the portion of the PNG that had occupied that area the top
corner of the PNG is painted in its stead. This causes the background in
this area not to match the background in the surrounding area (example
image attached). Is there a way paint the portion of the PNG that was
there originally?
//Redacted code
GobanWidget::GobanWidget(const DisplayData *display_data, QWidget *
parent)
: QWidget(parent)
{
//...
QPalette palette;
palette.setBrush(backgroundRole(),
QBrush(QPixmap(tr(":/resources/board.png"))));
setPalette(palette);
//...
}
//...
void GobanWidget::paintEvent(QPaintEvent *) {
//...
eraseRect(rect);
painter.drawText(rect,Qt::AlignCenter,
QString::fromStdString(i->text));
}
Regards,
Adam
More information about the Qt-interest-old
mailing list