Browse Source

修改cmakelist.txt, 新增qrc文件

master
tianzhendong 2 years ago
parent
commit
41e1068b70
  1. 26
      CMakeLists.txt
  2. 0
      resources/app_win32.rc
  3. 0
      resources/favicon.ico
  4. 11
      resources/img.qrc
  5. 12
      src/widget.cpp

26
CMakeLists.txt

@ -5,19 +5,35 @@ set(CMAKE_CXX_STANDARD 14)
set(CMAKE_AUTOMOC ON) set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON) set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON) set(CMAKE_AUTOUIC ON)
#
set(CMAKE_PREFIX_PATH "C:/Qt/Qt5.14.2/5.14.2/mingw73_64") set(CMAKE_PREFIX_PATH "C:/Qt/Qt5.14.2/5.14.2/mingw73_64")
# qt
find_package(Qt5 COMPONENTS find_package(Qt5 COMPONENTS
Core Core
Gui Gui
Widgets Widgets
REQUIRED) REQUIRED)
#
aux_source_directory(${PROJECT_SOURCE_DIR} DIR_MAIN_SRCS)
aux_source_directory(${PROJECT_SOURCE_DIR}/resources DIR_RESOURCES_SRCS)
aux_source_directory(${PROJECT_SOURCE_DIR}/src DIR_SRC_SRCS)
# qrc
qt5_add_resources(QRC_FILES resources/img.qrc)
include_directories(resources) # debug releasereleasecmd
IF (CMAKE_BUILD_TYPE STREQUAL Debug)
add_executable(${PROJECT_NAME}
resources/app_win32.rc
${DIR_MAIN_SRCS} ${DIR_RESOURCES_SRCS} ${DIR_SRC_SRCS}
${QRC_FILES})
else(CMAKE_BUILD_TYPE STREQUAL Release)
add_executable(${PROJECT_NAME}
WIN32 resources/app_win32.rc ${QRC_FILES}
${DIR_MAIN_SRCS} ${DIR_RESOURCES_SRCS} ${DIR_SRC_SRCS} ${QRC_FILES})
ENDIF()
add_executable(TemplateWindow src/main.cpp app_win32.rc src/widget.cpp src/widget.h src/widget.ui) target_link_libraries(${PROJECT_NAME}
target_link_libraries(TemplateWindow
Qt5::Core Qt5::Core
Qt5::Gui Qt5::Gui
Qt5::Widgets Qt5::Widgets

0
app_win32.rc → resources/app_win32.rc

0
favicon.ico → resources/favicon.ico

Before

Width:  |  Height:  |  Size: 4.2 KiB

After

Width:  |  Height:  |  Size: 4.2 KiB

11
resources/img.qrc

@ -0,0 +1,11 @@
<RCC>
<qresource prefix="img">
<file>favicon.ico</file>
</qresource>
<qresource prefix="png">
<file>close.png</file>
<file>fullscreen3.png</file>
<file>fullscreen4.png</file>
<file>min.png</file>
</qresource>
</RCC>

12
src/widget.cpp

@ -31,9 +31,9 @@ Widget::Widget(QWidget *parent)
connect(ui->btnMin, SIGNAL(clicked()), this, SLOT(btnMinClickedSlot())); connect(ui->btnMin, SIGNAL(clicked()), this, SLOT(btnMinClickedSlot()));
connect(ui->btnClose, SIGNAL(clicked()), this, SLOT(btnCloseClickedSlot())); connect(ui->btnClose, SIGNAL(clicked()), this, SLOT(btnCloseClickedSlot()));
ui->btnMin->setStyleSheet("border-image: url(../resources/min.png)"); ui->btnMin->setStyleSheet("border-image: url(:/png/min.png)");
ui->btnMax->setStyleSheet("border-image: url(../resources/fullscreen3.png)"); ui->btnMax->setStyleSheet("border-image: url(:/png/fullscreen3.png)");
ui->btnClose->setStyleSheet("border-image: url(../resources/close.png)"); ui->btnClose->setStyleSheet("border-image: url(:/png/close.png)");
} }
Widget::~Widget() Widget::~Widget()
@ -79,15 +79,15 @@ void Widget::closeEvent(QCloseEvent *event)
void Widget::btnMaxClickedSlot() void Widget::btnMaxClickedSlot()
{ {
ui->btnMax->setStyleSheet("border-image: url(../resources/fullscreen4.png)"); ui->btnMax->setStyleSheet("border-image: url(:/png/fullscreen4.png)");
if(this->isMaximized()){ if(this->isMaximized()){
ui->layoutMain->setMargin(9); ui->layoutMain->setMargin(9);
ui->btnMax->setStyleSheet("border-image: url(../resources/fullscreen3.png)"); ui->btnMax->setStyleSheet("border-image: url(:/png/fullscreen3.png)");
this->showNormal(); this->showNormal();
} }
else{ else{
ui->layoutMain->setMargin(0); ui->layoutMain->setMargin(0);
ui->btnMax->setStyleSheet("border-image: url(../resources/fullscreen4.png)"); ui->btnMax->setStyleSheet("border-image: url(:/png/fullscreen4.png)");
this->showMaximized(); this->showMaximized();
} }
} }

Loading…
Cancel
Save