Hi all, I am trying to paint with QLabel derived widget and still get widgets frame to be visible. When there is a frame without a drawing function, the frame is shown correctly. The problem is that when I reimplement paintEvent method, the frame is not shown anymore.
class GameArea
: public QLabel {public:
~GameArea();
protected:
};
class GameArea: public QLabel {
public:
GameArea(QWidget *parent = 0);
~GameArea();
protected:
void paintEvent(QPaintEvent *event);
};
To copy to clipboard, switch view to plain text mode
label = new GameArea(Exercise2Class);
label
->setFrameShape
(QFrame::StyledPanel);
label = new GameArea(Exercise2Class);
label->setFrameShape(QFrame::StyledPanel);
To copy to clipboard, switch view to plain text mode
{
pen.setColor(Qt::red);
brush.setStyle(Qt::SolidPattern);
brush.setColor(Qt::red);
painter.setPen(pen);
painter.setBrush(brush);
painter.drawEllipse(rect().center(), 20, 20);
}
void GameArea::paintEvent(QPaintEvent * /* event */)
{
QPainter painter(this);
QPen pen;
QBrush brush;
pen.setColor(Qt::red);
brush.setStyle(Qt::SolidPattern);
brush.setColor(Qt::red);
painter.setPen(pen);
painter.setBrush(brush);
painter.drawEllipse(rect().center(), 20, 20);
}
To copy to clipboard, switch view to plain text mode
Bookmarks