runable version
This commit is contained in:
1 parent
f34689b340
commit
1c819afe88
4 files changed
+30
-8
No files matched your search
@@ -31,7 +31,8 @@ SOURCES += \
|
||||
cars.cpp \
|
||||
parkinglot.cpp \
|
||||
ParkingLotWidget.cpp \
|
||||
Road.cpp
|
||||
Road.cpp \
|
||||
ParkingSpaceWidget.cpp
|
||||
|
||||
HEADERS += \
|
||||
mainwindow.h \
|
||||
@@ -39,7 +40,8 @@ HEADERS += \
|
||||
cars.h \
|
||||
parkinglot.h \
|
||||
ParkingLotWidget.h \
|
||||
Road.h
|
||||
Road.h \
|
||||
ParkingSpaceWidget.h
|
||||
|
||||
FORMS += \
|
||||
mainwindow.ui
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
@@ -4,14 +4,15 @@
|
||||
#include <QWidget>
|
||||
#include <QPixmap>
|
||||
#include <QString>
|
||||
#include <QPaintEvent>
|
||||
|
||||
class Cars : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum Color { Pink, Red, Yellow };
|
||||
explicit Cars(QWidget *parent = nullptr);
|
||||
explicit Cars(Color color, QWidget *parenet = nullptr) {}
|
||||
explicit Cars(QWidget *parent = nullptr); //Ëæ»úÑÕÉ«
|
||||
explicit Cars(Color color, QWidget *parent = nullptr);
|
||||
void paintEvent(QPaintEvent *event);
|
||||
private:
|
||||
Color m_color;
|
||||
|
||||
+1
-1
@@ -19,7 +19,7 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||
// scrollArea->resize(1800, 800);
|
||||
// monitor = new Monitor(this);
|
||||
// Cars *car = new Cars(this);
|
||||
ParkingLotWidget *pk = new ParkingLotWidget(this, "D:\\wming\\Documents\\DataStructureProject\\parkinglot_f1.xml");
|
||||
ParkingLotWidget *pk = new ParkingLotWidget(this, "parkinglot_f1.xml");
|
||||
// pk->show();
|
||||
// pk->creatMap();
|
||||
/*QLabel *label = new QLabel(this);
|
||||
|
||||
Reference in new issue
Block a user