runable version
This commit is contained in:
1 parent
f34689b340
commit
1c819afe88
4 files changed
+30
-8
No files matched your search
@@ -4,14 +4,33 @@
|
||||
|
||||
Cars::Cars(QWidget *parent) : QWidget(parent)
|
||||
{
|
||||
m_color = Color(rand() % 3);
|
||||
Cars(Color(rand() % 3), parent);
|
||||
}
|
||||
|
||||
Cars::Cars(Cars::Color color, QWidget *parent) : QWidget(parent)
|
||||
{
|
||||
m_color = color;
|
||||
resize(200, 130);
|
||||
switch (m_color) {
|
||||
case Pink:
|
||||
m_pixmap = QPixmap(":/cars/pink");
|
||||
break;
|
||||
case Red:
|
||||
m_pixmap = QPixmap(":/cars/red");
|
||||
break;
|
||||
case Yellow:
|
||||
m_pixmap = QPixmap(":/cars/yellow");
|
||||
break;
|
||||
default:
|
||||
m_pixmap = QPixmap(":/cars/red");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Cars::paintEvent(QPaintEvent *event) {
|
||||
QPainter painter(this);
|
||||
QPixmap pix(":/cars/yellow");
|
||||
painter.drawPixmap(0, 0, 200, 130, pix);
|
||||
painter.drawPixmap(0, 0, 200, 130, m_pixmap);
|
||||
painter.setPen(QPen(Qt::red, 5));
|
||||
painter.drawRect(0, 0, 200, 130);
|
||||
event->ignore();
|
||||
}
|
||||
Reference in new issue
Block a user