Hi,
I have a strange problem. I have custom qlabel with a new paintevent function. This function will paint and connect points on a QLabel image. So far so good. This works, when I only use one label.
But if I create another label or copy the code and rename "RenderArea" to "RenderArea2", it is not working. Painting inside the first label also paints in the second label. If I raise another window, e.g. taskmanager, the application crashed. Really weired.
I hope you can understand my problem. Thanks.
class RenderArea
: public QLabel { Q_OBJECT
public:
protected:
private:
}
class RenderArea : public QLabel {
Q_OBJECT
public:
RenderArea(QWidget *parent = 0);
protected:
void paintEvent(QPaintEvent *event);
private:
}
To copy to clipboard, switch view to plain text mode
{
painter.
setRenderHint(QPainter::SmoothPixmapTransform,
true );
painter.
setRenderHint( QPainter::Antialiasing,
true);
painter.
fillRect(event
->rect
(),
QBrush(Qt
::white));
painter.translate(30, 30);
painter.save();
painter.restore();
pen.setColor(Qt::green);
pen.setWidth(4);
pen.setJoinStyle(Qt::RoundJoin);
pen.setCapStyle(Qt::RoundCap);
painter.setPen(pen);
p.setX(globalX-30);
p.setY(globalY-30);
for(int i=0; i<pValues.count();i++)
{
painter.drawPoint(pValues.at(i));
if(i > 0)
{
if(pValues.at(i).x() == pValues.at(i-1).x() && pValues.at(i).y() == pValues.at(i-1).y())
{
i++;
}
else
{
painter.drawLine(pValues.at(i-1), pValues.at(i));
}
}
}
void RenderArea::paintEvent(QPaintEvent *event)
{
QPainter painter(this);
painter.setRenderHint(QPainter::SmoothPixmapTransform, true );
painter.setRenderHint( QPainter::Antialiasing, true);
painter.fillRect(event->rect(), QBrush(Qt::white));
painter.translate(30, 30);
painter.save();
painter.restore();
QPen pen;
pen.setColor(Qt::green);
pen.setWidth(4);
pen.setJoinStyle(Qt::RoundJoin);
pen.setCapStyle(Qt::RoundCap);
painter.setPen(pen);
QPoint p;
p.setX(globalX-30);
p.setY(globalY-30);
for(int i=0; i<pValues.count();i++)
{
painter.drawPoint(pValues.at(i));
if(i > 0)
{
if(pValues.at(i).x() == pValues.at(i-1).x() && pValues.at(i).y() == pValues.at(i-1).y())
{
i++;
}
else
{
painter.drawLine(pValues.at(i-1), pValues.at(i));
}
}
}
To copy to clipboard, switch view to plain text mode
pValues just stores the painted points so I can repaint them. The strange thing is that the paintevent from label1 paints also the in label2!
I also get the error message "QWidget::repaint: Recursive repaint detected".
Bookmarks