成功显示了公交车的图片
This commit is contained in:
		| @@ -1,8 +1,8 @@ | |||||||
| <RCC> | <RCC> | ||||||
|     <qresource prefix="/stop_pic"> |     <qresource prefix="/"> | ||||||
|         <file>picture/stop.png</file> |         <file>picture/stop.png</file> | ||||||
|     </qresource> |     </qresource> | ||||||
|     <qresource prefix="/bus_pic"> |     <qresource prefix="/"> | ||||||
|         <file>picture/bus.png</file> |         <file>picture/bus.png</file> | ||||||
|     </qresource> |     </qresource> | ||||||
| </RCC> | </RCC> | ||||||
							
								
								
									
										34
									
								
								include/mainScene.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								include/mainScene.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,34 @@ | |||||||
|  | // | ||||||
|  | // Created by ricardo on 2022/6/11. | ||||||
|  | // | ||||||
|  |  | ||||||
|  | #ifndef AUTO_BUS_GUI_MAIN_SCENE_H | ||||||
|  | #define AUTO_BUS_GUI_MAIN_SCENE_H | ||||||
|  |  | ||||||
|  | #include "QGraphicsScene" | ||||||
|  | #include "QGraphicsPixmapItem" | ||||||
|  | #include "railsModel.h" | ||||||
|  |  | ||||||
|  | class SceneManager | ||||||
|  | { | ||||||
|  | public: | ||||||
|  |     QGraphicsScene *scene; | ||||||
|  |  | ||||||
|  |     ~SceneManager(); | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * 初始化绘制场景 | ||||||
|  |      */ | ||||||
|  |     void init(); | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * 初始化场景中的站点 | ||||||
|  |      * @param rail_head 轨道的头节点 | ||||||
|  |      */ | ||||||
|  |     void initBusStop(rail_node_t *rail_head); | ||||||
|  |  | ||||||
|  | private: | ||||||
|  |     QGraphicsPixmapItem *pixmap_items; | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | #endif //AUTO_BUS_GUI_MAIN_SCENE_H | ||||||
| @@ -6,15 +6,22 @@ | |||||||
|  |  | ||||||
| #include "header/moc_centralwidget.cpp" | #include "header/moc_centralwidget.cpp" | ||||||
| #include "form/ui_CentralWidget.h" | #include "form/ui_CentralWidget.h" | ||||||
|  | #include "centralwidget.h" | ||||||
|  |  | ||||||
|  |  | ||||||
| CentralWidget::CentralWidget(QWidget *parent) : | CentralWidget::CentralWidget(QWidget *parent) : QWidget(parent), ui(new Ui::CentralWidget) | ||||||
|         QWidget(parent), ui(new Ui::CentralWidget) |  | ||||||
| { | { | ||||||
|     ui->setupUi(this); |     ui->setupUi(this); | ||||||
|  |  | ||||||
|  |     scene_manager = new SceneManager; | ||||||
|  |     scene_manager->init(); | ||||||
|  |     scene_manager->initBusStop(nullptr); | ||||||
|  |  | ||||||
|  |     ui->main_canva->setScene(scene_manager->scene); | ||||||
| } | } | ||||||
|  |  | ||||||
| CentralWidget::~CentralWidget() | CentralWidget::~CentralWidget() | ||||||
| { | { | ||||||
|     delete ui; |     delete ui; | ||||||
|  |     delete scene_manager; | ||||||
| } | } | ||||||
|   | |||||||
| @@ -6,20 +6,26 @@ | |||||||
|    <rect> |    <rect> | ||||||
|     <x>0</x> |     <x>0</x> | ||||||
|     <y>0</y> |     <y>0</y> | ||||||
|     <width>865</width> |     <width>900</width> | ||||||
|     <height>635</height> |     <height>600</height> | ||||||
|    </rect> |    </rect> | ||||||
|   </property> |   </property> | ||||||
|  |   <property name="minimumSize"> | ||||||
|  |    <size> | ||||||
|  |     <width>900</width> | ||||||
|  |     <height>600</height> | ||||||
|  |    </size> | ||||||
|  |   </property> | ||||||
|   <property name="windowTitle"> |   <property name="windowTitle"> | ||||||
|    <string>CentralWidget</string> |    <string>CentralWidget</string> | ||||||
|   </property> |   </property> | ||||||
|   <widget class="QGraphicsView" name="graphicsView"> |   <widget class="QGraphicsView" name="main_canva"> | ||||||
|    <property name="geometry"> |    <property name="geometry"> | ||||||
|     <rect> |     <rect> | ||||||
|      <x>0</x> |      <x>0</x> | ||||||
|      <y>0</y> |      <y>0</y> | ||||||
|      <width>661</width> |      <width>600</width> | ||||||
|      <height>421</height> |      <height>400</height> | ||||||
|     </rect> |     </rect> | ||||||
|    </property> |    </property> | ||||||
|   </widget> |   </widget> | ||||||
| @@ -29,10 +35,17 @@ | |||||||
|      <x>659</x> |      <x>659</x> | ||||||
|      <y>-1</y> |      <y>-1</y> | ||||||
|      <width>201</width> |      <width>201</width> | ||||||
|      <height>421</height> |      <height>411</height> | ||||||
|     </rect> |     </rect> | ||||||
|    </property> |    </property> | ||||||
|    <layout class="QVBoxLayout" name="verticalLayout"> |    <layout class="QVBoxLayout" name="verticalLayout"> | ||||||
|  |     <item> | ||||||
|  |      <widget class="QPushButton" name="test_button"> | ||||||
|  |       <property name="text"> | ||||||
|  |        <string>测试输出</string> | ||||||
|  |       </property> | ||||||
|  |      </widget> | ||||||
|  |     </item> | ||||||
|     <item> |     <item> | ||||||
|      <widget class="QLabel" name="label"> |      <widget class="QLabel" name="label"> | ||||||
|       <property name="text"> |       <property name="text"> | ||||||
| @@ -42,28 +55,28 @@ | |||||||
|     </item> |     </item> | ||||||
|    </layout> |    </layout> | ||||||
|   </widget> |   </widget> | ||||||
|   <widget class="QScrollArea" name="scrollArea"> |   <widget class="QTextEdit" name="text_output"> | ||||||
|    <property name="geometry"> |    <property name="geometry"> | ||||||
|     <rect> |     <rect> | ||||||
|      <x>0</x> |      <x>0</x> | ||||||
|      <y>420</y> |      <y>400</y> | ||||||
|      <width>861</width> |      <width>900</width> | ||||||
|      <height>221</height> |      <height>190</height> | ||||||
|     </rect> |     </rect> | ||||||
|    </property> |    </property> | ||||||
|    <property name="widgetResizable"> |   </widget> | ||||||
|     <bool>true</bool> |   <widget class="Line" name="line"> | ||||||
|  |    <property name="geometry"> | ||||||
|  |     <rect> | ||||||
|  |      <x>0</x> | ||||||
|  |      <y>400</y> | ||||||
|  |      <width>900</width> | ||||||
|  |      <height>10</height> | ||||||
|  |     </rect> | ||||||
|  |    </property> | ||||||
|  |    <property name="orientation"> | ||||||
|  |     <enum>Qt::Horizontal</enum> | ||||||
|    </property> |    </property> | ||||||
|    <widget class="QWidget" name="scrollAreaWidgetContents"> |  | ||||||
|     <property name="geometry"> |  | ||||||
|      <rect> |  | ||||||
|       <x>0</x> |  | ||||||
|       <y>0</y> |  | ||||||
|       <width>859</width> |  | ||||||
|       <height>219</height> |  | ||||||
|      </rect> |  | ||||||
|     </property> |  | ||||||
|    </widget> |  | ||||||
|   </widget> |   </widget> | ||||||
|  </widget> |  </widget> | ||||||
|  <resources/> |  <resources/> | ||||||
|   | |||||||
| @@ -7,9 +7,21 @@ | |||||||
|     <x>0</x> |     <x>0</x> | ||||||
|     <y>0</y> |     <y>0</y> | ||||||
|     <width>900</width> |     <width>900</width> | ||||||
|     <height>600</height> |     <height>622</height> | ||||||
|    </rect> |    </rect> | ||||||
|   </property> |   </property> | ||||||
|  |   <property name="minimumSize"> | ||||||
|  |    <size> | ||||||
|  |     <width>900</width> | ||||||
|  |     <height>622</height> | ||||||
|  |    </size> | ||||||
|  |   </property> | ||||||
|  |   <property name="maximumSize"> | ||||||
|  |    <size> | ||||||
|  |     <width>900</width> | ||||||
|  |     <height>622</height> | ||||||
|  |    </size> | ||||||
|  |   </property> | ||||||
|   <property name="windowTitle"> |   <property name="windowTitle"> | ||||||
|    <string>MainWindow</string> |    <string>MainWindow</string> | ||||||
|   </property> |   </property> | ||||||
|   | |||||||
| @@ -2,11 +2,12 @@ | |||||||
| // Created by ricardo on 2022/6/10. | // Created by ricardo on 2022/6/10. | ||||||
| // | // | ||||||
|  |  | ||||||
| #ifndef AUTO_BUS_GUI_CENTRALWIDGET_H | #ifndef AUTO_BUS_GUI_CENTRAL_WIDGET_H | ||||||
| #define AUTO_BUS_GUI_CENTRALWIDGET_H | #define AUTO_BUS_GUI_CENTRAL_WIDGET_H | ||||||
|  |  | ||||||
| #include <QWidget> | #include <QWidget> | ||||||
|  | #include "string" | ||||||
|  | #include "mainScene.h" | ||||||
|  |  | ||||||
| QT_BEGIN_NAMESPACE | QT_BEGIN_NAMESPACE | ||||||
| namespace Ui | namespace Ui | ||||||
| @@ -24,9 +25,13 @@ public: | |||||||
|  |  | ||||||
|     ~CentralWidget() override; |     ~CentralWidget() override; | ||||||
|  |  | ||||||
|  | public slots: | ||||||
|  |  | ||||||
|  |  | ||||||
| private: | private: | ||||||
|     Ui::CentralWidget *ui; |     Ui::CentralWidget *ui; | ||||||
|  |     SceneManager *scene_manager; | ||||||
| }; | }; | ||||||
|  |  | ||||||
|  |  | ||||||
| #endif //AUTO_BUS_GUI_CENTRALWIDGET_H | #endif //AUTO_BUS_GUI_CENTRAL_WIDGET_H | ||||||
|   | |||||||
| @@ -2,8 +2,8 @@ | |||||||
| // Created by ricardo on 2022/6/10. | // Created by ricardo on 2022/6/10. | ||||||
| // | // | ||||||
|  |  | ||||||
| #ifndef AUTO_BUS_GUI_MAINWINDOW_H | #ifndef AUTO_BUS_GUI_MAIN_WINDOW_H | ||||||
| #define AUTO_BUS_GUI_MAINWINDOW_H | #define AUTO_BUS_GUI_MAIN_WINDOW_H | ||||||
|  |  | ||||||
| #include <QMainWindow> | #include <QMainWindow> | ||||||
| #include "centralwidget.h" | #include "centralwidget.h" | ||||||
| @@ -31,6 +31,4 @@ private: | |||||||
|  |  | ||||||
|     void SetMenuBarConnection(); |     void SetMenuBarConnection(); | ||||||
| }; | }; | ||||||
|  | #endif //AUTO_BUS_GUI_MAIN_WINDOW_H | ||||||
|  |  | ||||||
| #endif //AUTO_BUS_GUI_MAINWINDOW_H |  | ||||||
|   | |||||||
							
								
								
									
										26
									
								
								src/mainScene.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								src/mainScene.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,26 @@ | |||||||
|  | // | ||||||
|  | // Created by ricardo on 2022/6/11. | ||||||
|  | // | ||||||
|  |  | ||||||
|  | #include "mainScene.h" | ||||||
|  |  | ||||||
|  | void SceneManager::init() | ||||||
|  | { | ||||||
|  |     scene = new QGraphicsScene; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void SceneManager::initBusStop(rail_node_t *rail_head) | ||||||
|  | { | ||||||
|  |     pixmap_items = new QGraphicsPixmapItem[1]; | ||||||
|  |  | ||||||
|  |     pixmap_items->setPixmap(QPixmap(":/picture/bus.png")); | ||||||
|  |     pixmap_items->setPos(100,100); | ||||||
|  |  | ||||||
|  |     scene->addItem(pixmap_items); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | SceneManager::~SceneManager() | ||||||
|  | { | ||||||
|  |     delete []pixmap_items; | ||||||
|  |     delete scene; | ||||||
|  | } | ||||||
		Reference in New Issue
	
	Block a user