Skip to content

Commit a9ee1e9

Browse files
修改cmakelist文件保证在linux上能使用clion进行qt工程的开发
1 parent e12e4e3 commit a9ee1e9

File tree

6 files changed

+89
-10
lines changed

6 files changed

+89
-10
lines changed

qt_clion/CMakeLists.txt

Lines changed: 52 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,11 @@ set(QT_VERSION 5)
1010
set(REQUIRED_LIBS Core Gui Widgets)
1111
set(REQUIRED_LIBS_QUALIFIED Qt5::Core Qt5::Gui Qt5::Widgets)
1212

13-
add_executable(${PROJECT_NAME}
14-
main.cpp
15-
mainwindow.cpp)
16-
17-
target_include_directories(${PROJECT_NAME}
18-
PUBLIC ./)
19-
20-
#set(CMAKE_PREFIX_PATH "D:/software/Qt5.13.0/mingw73_64/lib/cmake/Qt5")
13+
if(WIN32)
14+
set(CMAKE_PREFIX_PATH "D:/software/Qt5.13.0/mingw73_64/lib/cmake/Qt5")
15+
else()
16+
set(CMAKE_PREFIX_PATH "/usr/lib/x86_64-linux-gnu/cmake/Qt5")
17+
endif()
2118

2219

2320
if (NOT CMAKE_PREFIX_PATH)
@@ -26,6 +23,53 @@ if (NOT CMAKE_PREFIX_PATH)
2623
endif ()
2724

2825

26+
## 添加用户界面文件
27+
#set(FORMS
28+
# mainwindow.ui
29+
# )
30+
31+
# 自动生成用户界面文件的 C++ 代码
32+
#qt5_wrap_ui(UI_HEADERS ${FORMS})
33+
34+
# 自动生成用户界面文件的 C++ 代码
35+
# 自动生成用户界面文件的 C++ 代码
36+
#set(UI_HEADERS)
37+
if(WIN32)
38+
39+
#foreach(FORM ${FORMS})
40+
# get_filename_component(FORM_BASE ${FORM} NAME_WE)
41+
# set(UI_HEADER "${CMAKE_CURRENT_BINARY_DIR}/ui_${FORM_BASE}.h")
42+
# list(APPEND UI_HEADERS ${UI_HEADER})
43+
# add_custom_command(
44+
# OUTPUT ${UI_HEADER}
45+
# COMMAND ${Qt5_DIR}/../../../bin/uic ${CMAKE_CURRENT_SOURCE_DIR}/${FORM} -o ${UI_HEADER}
46+
# DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${FORM}
47+
# )
48+
#endforeach()
49+
50+
else()
51+
# foreach(FORM ${FORMS})
52+
# get_filename_component(FORM_BASE ${FORM} NAME_WE)
53+
# set(UI_HEADER "${CMAKE_CURRENT_BINARY_DIR}/ui_${FORM_BASE}.h")
54+
# list(APPEND UI_HEADERS ${UI_HEADER})
55+
# add_custom_command(
56+
# OUTPUT ${UI_HEADER}
57+
# COMMAND /usr/bin/uic ${CMAKE_CURRENT_SOURCE_DIR}/${FORM} -o ${UI_HEADER}
58+
# DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${FORM}
59+
# )
60+
# endforeach()
61+
62+
endif()
63+
64+
65+
add_executable(${PROJECT_NAME}
66+
main.cpp
67+
mainwindow.cpp)
68+
69+
target_include_directories(${PROJECT_NAME}
70+
PUBLIC ./)
71+
72+
2973
find_package(Qt${QT_VERSION} COMPONENTS ${REQUIRED_LIBS} REQUIRED)
3074
target_link_libraries(${PROJECT_NAME} ${REQUIRED_LIBS_QUALIFIED})
3175

qt_clion/mainwindow.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// You may need to build the project (run Qt uic code generator) to get "ui_MainWindow.h" resolved
66

77
#include "mainwindow.h"
8-
#include "ui_MainWindow.h"
8+
#include "ui_mainwindow.h"
99

1010

1111
MainWindow::MainWindow(QWidget *parent) :

qt_painter/achou.png

454 KB
Loading

qt_painter/main.cpp

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#include "mainwindow.h"
22
#include <QApplication>
3-
3+
#include <QGraphicsScene>
4+
#include <QGraphicsRectItem>
5+
#include <QDebug>
6+
#include <QGraphicsView>
47
/*
58
* 绘图主要依赖QPainter QPaintDevice QPaintEngine三个类
69
* QPainter :用来执行绘图操作
@@ -20,5 +23,29 @@ int main(int argc, char *argv[])
2023
MainWindow w;
2124
w.show();
2225

26+
27+
// 新建场景
28+
QGraphicsScene scene;
29+
// 创建矩形图形项
30+
QGraphicsRectItem *item = new QGraphicsRectItem(0, 0, 100, 100);
31+
// 将图形项添加到场景中
32+
scene.addItem(item);
33+
// 输出(50, 50)点处的图形项
34+
qDebug() << scene.itemAt(50, 50, QTransform());
35+
36+
// 为场景创建视图
37+
QGraphicsView view(&scene);
38+
// // 设置场景的前景色
39+
// view.setForegroundBrush(QColor(255, 255, 0, 100));
40+
// // 设置场景的背景图片
41+
// view.setBackgroundBrush(QPixmap("../myScene/background.png"));
42+
43+
scene.setForegroundBrush(QColor(220, 210, 0, 100));
44+
scene.setBackgroundBrush(QPixmap(":/images/achou"));
45+
46+
view.resize(400, 300);
47+
view.show();
48+
49+
2350
return a.exec();
2451
}

qt_painter/qt_painter.pro

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,6 @@ FORMS += \
3838
qnx: target.path = /tmp/$${TARGET}/bin
3939
else: unix:!android: target.path = /opt/$${TARGET}/bin
4040
!isEmpty(target.path): INSTALLS += target
41+
42+
RESOURCES += \
43+
res.qrc

qt_painter/res.qrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<RCC>
2+
<qresource prefix="/images">
3+
<file alias="achou">achou.png</file>
4+
</qresource>
5+
</RCC>

0 commit comments

Comments
 (0)