├── 0res
├── 1583500948212.png
├── 1583501501664.png
├── 1583501662153.png
├── 1583502593883.png
├── 1583502873866.png
├── 1583502956280.png
├── 1583503365288.png
├── 1583503650019.png
├── 1583505605223.png
├── 1583509718353.png
├── 1583509733718.png
├── 1583639858766.png
├── 1583639869008.png
├── 1584461432626.png
├── 999992dialog_1tablewidget.png
├── 999992dialog_3satree.png
├── 999992menubar_2button.png
├── 999992menubar_5modal.png
├── 999992menubar_6layout.png
├── 999992menubar_7mymenu.png
└── 999994CCompilerUI.png
├── 1Hello
├── Hello.pro
├── Hello.pro.user
├── main.cpp
├── mainwindow.cpp
└── mainwindow.h
├── 1titlebar_logo_title
├── 1titlebar_logo_title.pro
├── 1titlebar_logo_title.pro.user
├── main.cpp
├── mainwindow.cpp
├── mainwindow.h
├── mainwindow.ui
├── res.qrc
└── res
│ └── app_1title_dark_appicon.png
├── 2dialog_1listview
├── 2dialog_1listview.pro
├── 2dialog_1listview.pro.user
├── img
│ └── delete.png
├── main.cpp
├── mainwindow.cpp
├── mainwindow.h
├── mainwindow.ui
└── res.qrc
├── 2dialog_1tablewidget
├── 2dialog_1tablewidget.pro
├── 2dialog_1tablewidget.pro.user
├── main.cpp
├── mainwindow.cpp
├── mainwindow.h
└── mainwindow.ui
├── 2dialog_2pdfreader
├── 2dialog_2pdfreader.pro
├── 2dialog_2pdfreader.pro.user
├── main.cpp
├── mainwindow.cpp
├── mainwindow.h
└── mainwindow.ui
├── 2dialog_3satree
├── 2dialog_3satree.pro
├── 2dialog_3satree.pro.user
├── binarytree.cpp
├── binarytree.h
├── binarytreepainter.cpp
├── binarytreepainter.h
├── main.cpp
├── mainwindow.cpp
├── mainwindow.h
└── mainwindow.ui
├── 2menubar_1signal_slot
├── 2menubar_1signal_slot.pro
├── 2menubar_1signal_slot.pro.user
├── main.cpp
├── mainwindow.cpp
├── mainwindow.h
└── mainwindow.ui
├── 2menubar_2button
├── 2menubar_2button.pro
├── 2menubar_2button.pro.user
├── img
│ ├── app_round_button_black.9.png
│ ├── app_round_button_darkblue.9.png
│ ├── app_round_button_gray.9.png
│ ├── app_round_button_green.9.png
│ └── app_round_button_white.9.png
├── main.cpp
├── mainwindow.cpp
├── mainwindow.h
├── mainwindow.ui
└── res.qrc
├── 2menubar_3label
├── 2menubar_3label.pro
├── 2menubar_3label.pro.user
├── main.cpp
├── mainwindow.cpp
├── mainwindow.h
└── mainwindow.ui
├── 2menubar_4menu
├── 2menubar_4menu.pro
├── 2menubar_4menu.pro.user
├── hover_menu_analysebystep.ui
├── hovermenuanalyse.cpp
├── hovermenuanalyse.h
├── img
│ ├── app_2menu_new.png
│ ├── app_2menu_open.png
│ └── app_2menu_save.png
├── main.cpp
├── mainwindow.cpp
├── mainwindow.h
├── mainwindow.ui
├── menu_analyse_by_step.ui
└── res.qrc
├── 2menubar_5modal
├── 2menubar_5modal.pro
├── 2menubar_5modal.pro.user
├── main.cpp
├── mainwindow.cpp
├── mainwindow.h
├── mainwindow.ui
├── settingdialog.cpp
├── settingdialog.h
└── settingdialog.ui
├── 2menubar_6layout
├── 2menubar_6layout.pro
├── 2menubar_6layout.pro.user
├── main.cpp
├── mainwindow.cpp
├── mainwindow.h
└── mainwindow.ui
├── 2menubar_7mymenu
├── 2menubar_7mymenu.pro
├── 2menubar_7mymenu.pro.user
├── main.cpp
├── mainwindow.cpp
├── mainwindow.h
└── mainwindow.ui
├── 3main_1codeeditor
├── 3main_1codeeditor.pro
├── 3main_1codeeditor.pro.user
├── main.cpp
├── mainwindow.cpp
├── mainwindow.h
└── mainwindow.ui
├── 4CCompilerUI
├── CCompilerUI.pro
├── CCompilerUI.pro.user
├── img
│ ├── app_1title_dark_appicon1.png
│ ├── app_round_button_black.9.png
│ ├── app_round_button_darkblue.9.png
│ ├── app_round_button_gray.9.png
│ ├── app_round_button_green.9.png
│ ├── app_round_button_transparent.9.png
│ ├── app_round_button_white.9.png
│ ├── app_up.png
│ ├── app_up_down.png
│ ├── app_up_down_hover.png
│ └── app_up_hover.png
├── main.cpp
├── mainwindow.cpp
├── mainwindow.h
├── mainwindow.ui
└── res.qrc
└── README.md
/0res/1583500948212.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MarkCens/Qt-Learning-Demo/5a7b6ab2216bbacb350825c635d6f3c3928dc311/0res/1583500948212.png
--------------------------------------------------------------------------------
/0res/1583501501664.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MarkCens/Qt-Learning-Demo/5a7b6ab2216bbacb350825c635d6f3c3928dc311/0res/1583501501664.png
--------------------------------------------------------------------------------
/0res/1583501662153.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MarkCens/Qt-Learning-Demo/5a7b6ab2216bbacb350825c635d6f3c3928dc311/0res/1583501662153.png
--------------------------------------------------------------------------------
/0res/1583502593883.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MarkCens/Qt-Learning-Demo/5a7b6ab2216bbacb350825c635d6f3c3928dc311/0res/1583502593883.png
--------------------------------------------------------------------------------
/0res/1583502873866.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MarkCens/Qt-Learning-Demo/5a7b6ab2216bbacb350825c635d6f3c3928dc311/0res/1583502873866.png
--------------------------------------------------------------------------------
/0res/1583502956280.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MarkCens/Qt-Learning-Demo/5a7b6ab2216bbacb350825c635d6f3c3928dc311/0res/1583502956280.png
--------------------------------------------------------------------------------
/0res/1583503365288.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MarkCens/Qt-Learning-Demo/5a7b6ab2216bbacb350825c635d6f3c3928dc311/0res/1583503365288.png
--------------------------------------------------------------------------------
/0res/1583503650019.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MarkCens/Qt-Learning-Demo/5a7b6ab2216bbacb350825c635d6f3c3928dc311/0res/1583503650019.png
--------------------------------------------------------------------------------
/0res/1583505605223.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MarkCens/Qt-Learning-Demo/5a7b6ab2216bbacb350825c635d6f3c3928dc311/0res/1583505605223.png
--------------------------------------------------------------------------------
/0res/1583509718353.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MarkCens/Qt-Learning-Demo/5a7b6ab2216bbacb350825c635d6f3c3928dc311/0res/1583509718353.png
--------------------------------------------------------------------------------
/0res/1583509733718.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MarkCens/Qt-Learning-Demo/5a7b6ab2216bbacb350825c635d6f3c3928dc311/0res/1583509733718.png
--------------------------------------------------------------------------------
/0res/1583639858766.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MarkCens/Qt-Learning-Demo/5a7b6ab2216bbacb350825c635d6f3c3928dc311/0res/1583639858766.png
--------------------------------------------------------------------------------
/0res/1583639869008.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MarkCens/Qt-Learning-Demo/5a7b6ab2216bbacb350825c635d6f3c3928dc311/0res/1583639869008.png
--------------------------------------------------------------------------------
/0res/1584461432626.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MarkCens/Qt-Learning-Demo/5a7b6ab2216bbacb350825c635d6f3c3928dc311/0res/1584461432626.png
--------------------------------------------------------------------------------
/0res/999992dialog_1tablewidget.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MarkCens/Qt-Learning-Demo/5a7b6ab2216bbacb350825c635d6f3c3928dc311/0res/999992dialog_1tablewidget.png
--------------------------------------------------------------------------------
/0res/999992dialog_3satree.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MarkCens/Qt-Learning-Demo/5a7b6ab2216bbacb350825c635d6f3c3928dc311/0res/999992dialog_3satree.png
--------------------------------------------------------------------------------
/0res/999992menubar_2button.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MarkCens/Qt-Learning-Demo/5a7b6ab2216bbacb350825c635d6f3c3928dc311/0res/999992menubar_2button.png
--------------------------------------------------------------------------------
/0res/999992menubar_5modal.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MarkCens/Qt-Learning-Demo/5a7b6ab2216bbacb350825c635d6f3c3928dc311/0res/999992menubar_5modal.png
--------------------------------------------------------------------------------
/0res/999992menubar_6layout.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MarkCens/Qt-Learning-Demo/5a7b6ab2216bbacb350825c635d6f3c3928dc311/0res/999992menubar_6layout.png
--------------------------------------------------------------------------------
/0res/999992menubar_7mymenu.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MarkCens/Qt-Learning-Demo/5a7b6ab2216bbacb350825c635d6f3c3928dc311/0res/999992menubar_7mymenu.png
--------------------------------------------------------------------------------
/0res/999994CCompilerUI.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MarkCens/Qt-Learning-Demo/5a7b6ab2216bbacb350825c635d6f3c3928dc311/0res/999994CCompilerUI.png
--------------------------------------------------------------------------------
/1Hello/Hello.pro:
--------------------------------------------------------------------------------
1 | QT += core gui
2 |
3 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
4 |
5 | CONFIG += c++11
6 |
7 | # The following define makes your compiler emit warnings if you use
8 | # any Qt feature that has been marked deprecated (the exact warnings
9 | # depend on your compiler). Please consult the documentation of the
10 | # deprecated API in order to know how to port your code away from it.
11 | DEFINES += QT_DEPRECATED_WARNINGS
12 |
13 | # You can also make your code fail to compile if it uses deprecated APIs.
14 | # In order to do so, uncomment the following line.
15 | # You can also select to disable deprecated APIs only up to a certain version of Qt.
16 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
17 |
18 | SOURCES += \
19 | main.cpp \
20 | mainwindow.cpp
21 |
22 | HEADERS += \
23 | mainwindow.h
24 |
25 | # Default rules for deployment.
26 | qnx: target.path = /tmp/$${TARGET}/bin
27 | else: unix:!android: target.path = /opt/$${TARGET}/bin
28 | !isEmpty(target.path): INSTALLS += target
29 |
--------------------------------------------------------------------------------
/1Hello/Hello.pro.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | EnvironmentId
7 | {cc04c648-95f6-46a2-8902-3070ddc345f2}
8 |
9 |
10 | ProjectExplorer.Project.ActiveTarget
11 | 0
12 |
13 |
14 | ProjectExplorer.Project.EditorSettings
15 |
16 | true
17 | false
18 | true
19 |
20 | Cpp
21 |
22 | CppGlobal
23 |
24 |
25 |
26 | QmlJS
27 |
28 | QmlJSGlobal
29 |
30 |
31 | 2
32 | UTF-8
33 | false
34 | 4
35 | false
36 | 80
37 | true
38 | true
39 | 1
40 | true
41 | false
42 | 0
43 | true
44 | true
45 | 0
46 | 8
47 | true
48 | 1
49 | true
50 | true
51 | true
52 | false
53 |
54 |
55 |
56 | ProjectExplorer.Project.PluginSettings
57 |
58 |
59 | -fno-delayed-template-parsing
60 |
61 | true
62 |
63 |
64 |
65 | ProjectExplorer.Project.Target.0
66 |
67 | Desktop Qt 5.14.1 MinGW 32-bit
68 | Desktop Qt 5.14.1 MinGW 32-bit
69 | qt.qt5.5141.win32_mingw73_kit
70 | 0
71 | 0
72 | 0
73 |
74 | H:/Learn_Code/QtProjects/Helloworld/build-Hello-Desktop_Qt_5_14_1_MinGW_32_bit-Debug
75 |
76 |
77 | true
78 | QtProjectManager.QMakeBuildStep
79 | true
80 |
81 | false
82 | false
83 | false
84 |
85 |
86 | true
87 | Qt4ProjectManager.MakeStep
88 |
89 | false
90 |
91 |
92 | false
93 |
94 | 2
95 | Build
96 | Build
97 | ProjectExplorer.BuildSteps.Build
98 |
99 |
100 |
101 | true
102 | Qt4ProjectManager.MakeStep
103 |
104 | true
105 | clean
106 |
107 | false
108 |
109 | 1
110 | Clean
111 | Clean
112 | ProjectExplorer.BuildSteps.Clean
113 |
114 | 2
115 | false
116 |
117 | Debug
118 | Qt4ProjectManager.Qt4BuildConfiguration
119 | 2
120 |
121 |
122 | H:/Learn_Code/QtProjects/Helloworld/build-Hello-Desktop_Qt_5_14_1_MinGW_32_bit-Release
123 |
124 |
125 | true
126 | QtProjectManager.QMakeBuildStep
127 | false
128 |
129 | false
130 | false
131 | true
132 |
133 |
134 | true
135 | Qt4ProjectManager.MakeStep
136 |
137 | false
138 |
139 |
140 | false
141 |
142 | 2
143 | Build
144 | Build
145 | ProjectExplorer.BuildSteps.Build
146 |
147 |
148 |
149 | true
150 | Qt4ProjectManager.MakeStep
151 |
152 | true
153 | clean
154 |
155 | false
156 |
157 | 1
158 | Clean
159 | Clean
160 | ProjectExplorer.BuildSteps.Clean
161 |
162 | 2
163 | false
164 |
165 | Release
166 | Qt4ProjectManager.Qt4BuildConfiguration
167 | 0
168 |
169 |
170 | H:/Learn_Code/QtProjects/Helloworld/build-Hello-Desktop_Qt_5_14_1_MinGW_32_bit-Profile
171 |
172 |
173 | true
174 | QtProjectManager.QMakeBuildStep
175 | true
176 |
177 | false
178 | true
179 | true
180 |
181 |
182 | true
183 | Qt4ProjectManager.MakeStep
184 |
185 | false
186 |
187 |
188 | false
189 |
190 | 2
191 | Build
192 | Build
193 | ProjectExplorer.BuildSteps.Build
194 |
195 |
196 |
197 | true
198 | Qt4ProjectManager.MakeStep
199 |
200 | true
201 | clean
202 |
203 | false
204 |
205 | 1
206 | Clean
207 | Clean
208 | ProjectExplorer.BuildSteps.Clean
209 |
210 | 2
211 | false
212 |
213 | Profile
214 | Qt4ProjectManager.Qt4BuildConfiguration
215 | 0
216 |
217 | 3
218 |
219 |
220 | 0
221 | Deploy
222 | Deploy
223 | ProjectExplorer.BuildSteps.Deploy
224 |
225 | 1
226 | ProjectExplorer.DefaultDeployConfiguration
227 |
228 | 1
229 |
230 |
231 | dwarf
232 |
233 | cpu-cycles
234 |
235 |
236 | 250
237 |
238 | -e
239 | cpu-cycles
240 | --call-graph
241 | dwarf,4096
242 | -F
243 | 250
244 |
245 | -F
246 | true
247 | 4096
248 | false
249 | false
250 | 1000
251 |
252 | true
253 |
254 | false
255 | false
256 | false
257 | false
258 | true
259 | 0.01
260 | 10
261 | true
262 | kcachegrind
263 | 1
264 | 25
265 |
266 | 1
267 | true
268 | false
269 | true
270 | valgrind
271 |
272 | 0
273 | 1
274 | 2
275 | 3
276 | 4
277 | 5
278 | 6
279 | 7
280 | 8
281 | 9
282 | 10
283 | 11
284 | 12
285 | 13
286 | 14
287 |
288 | 2
289 |
290 | Qt4ProjectManager.Qt4RunConfiguration:H:/Learn_Code/QtProjects/Helloworld/Hello/Hello.pro
291 | H:/Learn_Code/QtProjects/Helloworld/Hello/Hello.pro
292 |
293 | false
294 |
295 | false
296 | true
297 | true
298 | false
299 | false
300 | true
301 |
302 | H:/Learn_Code/QtProjects/Helloworld/build-Hello-Desktop_Qt_5_14_1_MinGW_32_bit-Debug
303 |
304 | 1
305 |
306 |
307 |
308 | ProjectExplorer.Project.TargetCount
309 | 1
310 |
311 |
312 | ProjectExplorer.Project.Updater.FileVersion
313 | 22
314 |
315 |
316 | Version
317 | 22
318 |
319 |
320 |
--------------------------------------------------------------------------------
/1Hello/main.cpp:
--------------------------------------------------------------------------------
1 | #include "mainwindow.h"
2 |
3 | #include
4 |
5 | int main(int argc, char *argv[])
6 | {
7 | QApplication a(argc, argv);
8 | MainWindow w;
9 |
10 |
11 |
12 | w.show();
13 | return a.exec();
14 | }
15 |
--------------------------------------------------------------------------------
/1Hello/mainwindow.cpp:
--------------------------------------------------------------------------------
1 | #include "mainwindow.h"
2 |
3 | MainWindow::MainWindow(QWidget *parent)
4 | : QMainWindow(parent)
5 | {
6 | }
7 |
8 | MainWindow::~MainWindow()
9 | {
10 | }
11 |
12 |
--------------------------------------------------------------------------------
/1Hello/mainwindow.h:
--------------------------------------------------------------------------------
1 | #ifndef MAINWINDOW_H
2 | #define MAINWINDOW_H
3 |
4 | #include
5 |
6 | class MainWindow : public QMainWindow
7 | {
8 | Q_OBJECT
9 |
10 | public:
11 | MainWindow(QWidget *parent = nullptr);
12 | ~MainWindow();
13 | };
14 | #endif // MAINWINDOW_H
15 |
--------------------------------------------------------------------------------
/1titlebar_logo_title/1titlebar_logo_title.pro:
--------------------------------------------------------------------------------
1 | QT += core gui
2 |
3 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
4 |
5 | CONFIG += c++11
6 |
7 | # The following define makes your compiler emit warnings if you use
8 | # any Qt feature that has been marked deprecated (the exact warnings
9 | # depend on your compiler). Please consult the documentation of the
10 | # deprecated API in order to know how to port your code away from it.
11 | DEFINES += QT_DEPRECATED_WARNINGS
12 |
13 | # You can also make your code fail to compile if it uses deprecated APIs.
14 | # In order to do so, uncomment the following line.
15 | # You can also select to disable deprecated APIs only up to a certain version of Qt.
16 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
17 |
18 | SOURCES += \
19 | main.cpp \
20 | mainwindow.cpp
21 |
22 | HEADERS += \
23 | mainwindow.h
24 |
25 | FORMS += \
26 | mainwindow.ui
27 |
28 | # Default rules for deployment.
29 | qnx: target.path = /tmp/$${TARGET}/bin
30 | else: unix:!android: target.path = /opt/$${TARGET}/bin
31 | !isEmpty(target.path): INSTALLS += target
32 |
33 | RESOURCES += \
34 | res.qrc
35 |
--------------------------------------------------------------------------------
/1titlebar_logo_title/main.cpp:
--------------------------------------------------------------------------------
1 | #include "mainwindow.h"
2 |
3 | #include
4 |
5 | int main(int argc, char *argv[])
6 | {
7 | QApplication a(argc, argv);
8 | MainWindow w;
9 | w.show();
10 | return a.exec();
11 | }
12 |
--------------------------------------------------------------------------------
/1titlebar_logo_title/mainwindow.cpp:
--------------------------------------------------------------------------------
1 | #include "mainwindow.h"
2 | #include "ui_mainwindow.h"
3 | #include
4 |
5 | MainWindow::MainWindow(QWidget *parent)
6 | : QMainWindow(parent)
7 | , ui(new Ui::MainWindow)
8 | {
9 | ui->setupUi(this);
10 |
11 | //设置图标
12 | setWindowIcon(QIcon(":/res/app_1title_dark_appicon.png"));
13 |
14 | //设置窗口标题
15 | setWindowTitle(tr("C语言编译器"));
16 | }
17 |
18 | MainWindow::~MainWindow()
19 | {
20 | delete ui;
21 | }
22 |
23 |
--------------------------------------------------------------------------------
/1titlebar_logo_title/mainwindow.h:
--------------------------------------------------------------------------------
1 | #ifndef MAINWINDOW_H
2 | #define MAINWINDOW_H
3 |
4 | #include
5 |
6 | QT_BEGIN_NAMESPACE
7 | namespace Ui { class MainWindow; }
8 | QT_END_NAMESPACE
9 |
10 | class MainWindow : public QMainWindow
11 | {
12 | Q_OBJECT
13 |
14 | public:
15 | MainWindow(QWidget *parent = nullptr);
16 | ~MainWindow();
17 |
18 | private:
19 | Ui::MainWindow *ui;
20 | };
21 | #endif // MAINWINDOW_H
22 |
--------------------------------------------------------------------------------
/1titlebar_logo_title/mainwindow.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | MainWindow
4 |
5 |
6 |
7 | 0
8 | 0
9 | 900
10 | 600
11 |
12 |
13 |
14 |
15 | 720
16 | 450
17 |
18 |
19 |
20 |
21 |
22 |
23 |
33 |
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/1titlebar_logo_title/res.qrc:
--------------------------------------------------------------------------------
1 |
2 |
3 | res/app_1title_dark_appicon.png
4 |
5 |
6 |
--------------------------------------------------------------------------------
/1titlebar_logo_title/res/app_1title_dark_appicon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MarkCens/Qt-Learning-Demo/5a7b6ab2216bbacb350825c635d6f3c3928dc311/1titlebar_logo_title/res/app_1title_dark_appicon.png
--------------------------------------------------------------------------------
/2dialog_1listview/2dialog_1listview.pro:
--------------------------------------------------------------------------------
1 | QT += core gui
2 |
3 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
4 |
5 | CONFIG += c++11
6 |
7 | # The following define makes your compiler emit warnings if you use
8 | # any Qt feature that has been marked deprecated (the exact warnings
9 | # depend on your compiler). Please consult the documentation of the
10 | # deprecated API in order to know how to port your code away from it.
11 | DEFINES += QT_DEPRECATED_WARNINGS
12 |
13 | # You can also make your code fail to compile if it uses deprecated APIs.
14 | # In order to do so, uncomment the following line.
15 | # You can also select to disable deprecated APIs only up to a certain version of Qt.
16 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
17 |
18 | SOURCES += \
19 | main.cpp \
20 | mainwindow.cpp
21 |
22 | HEADERS += \
23 | mainwindow.h
24 |
25 | FORMS += \
26 | mainwindow.ui
27 |
28 | # Default rules for deployment.
29 | qnx: target.path = /tmp/$${TARGET}/bin
30 | else: unix:!android: target.path = /opt/$${TARGET}/bin
31 | !isEmpty(target.path): INSTALLS += target
32 |
33 | RESOURCES += \
34 | res.qrc
35 |
--------------------------------------------------------------------------------
/2dialog_1listview/img/delete.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MarkCens/Qt-Learning-Demo/5a7b6ab2216bbacb350825c635d6f3c3928dc311/2dialog_1listview/img/delete.png
--------------------------------------------------------------------------------
/2dialog_1listview/main.cpp:
--------------------------------------------------------------------------------
1 | #include "mainwindow.h"
2 |
3 | #include
4 |
5 | int main(int argc, char *argv[])
6 | {
7 | QApplication a(argc, argv);
8 | MainWindow w;
9 | w.show();
10 | return a.exec();
11 | }
12 |
--------------------------------------------------------------------------------
/2dialog_1listview/mainwindow.cpp:
--------------------------------------------------------------------------------
1 | #include "mainwindow.h"
2 | #include "ui_mainwindow.h"
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 |
10 | MainWindow::MainWindow(QWidget *parent): QMainWindow(parent), ui(new Ui::MainWindow)
11 | {
12 | ui->setupUi(this);
13 | //设置
14 | ui->listWidget->setStyleSheet("QListWidget::Item:hover{background:rgb(33,37,50);}"
15 | "QListWidget::Item:selected{background:rgb(33,37,50);border:none;}");
16 |
17 |
18 |
19 | ui->listWidget->setFocusPolicy(Qt::NoFocus);
20 |
21 |
22 | }
23 |
24 | MainWindow::~MainWindow()
25 | {
26 | delete ui;
27 | }
28 |
29 |
30 | void MainWindow::on_pushButton_clicked()
31 | {
32 | //删除一项
33 | QListWidgetItem* item = ui->listWidget->takeItem(ui->listWidget->currentRow());
34 | delete item;
35 | }
36 |
37 | void MainWindow::on_pushButton_2_clicked()
38 | {
39 | //添加一项
40 | QWidget* plugin_0widget = new QWidget(ui->listWidget);
41 | QHBoxLayout *plugin_hl_item = new QHBoxLayout;
42 | QLabel *plugin_2name = new QLabel(this);
43 | plugin_2name->setText("词法分析插件");
44 | plugin_2name->setStyleSheet("QLabel{padding-left:5px;color:rgb(234,234,234);font-family:'微软雅黑';}");
45 | QLabel *plugin_3path = new QLabel(this);
46 | plugin_3path->setText("H:\\Learn_Code\\QtProjects\\Lab\2dialog_1listview\\img");
47 | plugin_3path->setStyleSheet("QLabel{padding-left:5px;padding-right:5px;color:rgb(234,234,234);font-family:'微软雅黑';}");
48 | QPushButton *plugin_4delete = new QPushButton(this);
49 | plugin_4delete->setFixedSize(32, 32);
50 | plugin_4delete->setIcon(QIcon(":/img/delete.png"));
51 | plugin_4delete->setIconSize(QSize(20, 20));
52 | connect(plugin_4delete, SIGNAL(clicked()), this, SLOT(OpenFolder()));
53 | //为布局添加上面的控件
54 | plugin_hl_item->setContentsMargins(0, 0, 0, 0);
55 | plugin_hl_item->setMargin(0);
56 | plugin_hl_item->setSpacing(0);
57 | plugin_hl_item->addWidget(plugin_2name);
58 | plugin_hl_item->addWidget(plugin_3path);
59 | plugin_hl_item->addStretch();//添加Spacer
60 | plugin_hl_item->addWidget(plugin_4delete);
61 | plugin_0widget->setLayout(plugin_hl_item);
62 | plugin_0widget->setStyleSheet("background:transparent;");
63 |
64 | //将plugin_0widget作为列表的item
65 | QListWidgetItem *item = new QListWidgetItem();
66 | QSize size = item->sizeHint();
67 | item->setSizeHint(QSize(size.width(), 36));
68 | ui->listWidget->addItem(item);
69 | ui->listWidget->setSizeIncrement(size.width(), 36);
70 | ui->listWidget->setItemWidget(item, plugin_0widget);
71 | }
72 |
73 | void MainWindow::on_pushButton_update_clicked()
74 | {
75 | if(ui->listWidget->currentItem()!=Q_NULLPTR)
76 | {
77 | ui->listWidget->currentItem();
78 | }
79 | }
80 |
81 | void MainWindow::on_pushButton_read_clicked()
82 | {
83 |
84 | }
85 |
--------------------------------------------------------------------------------
/2dialog_1listview/mainwindow.h:
--------------------------------------------------------------------------------
1 | #ifndef MAINWINDOW_H
2 | #define MAINWINDOW_H
3 |
4 | #include
5 |
6 | QT_BEGIN_NAMESPACE
7 | namespace Ui { class MainWindow; }
8 | QT_END_NAMESPACE
9 |
10 | class MainWindow : public QMainWindow
11 | {
12 | Q_OBJECT
13 |
14 | public:
15 | MainWindow(QWidget *parent = nullptr);
16 | ~MainWindow();
17 |
18 | private slots:
19 | void on_pushButton_clicked();
20 |
21 | void on_pushButton_2_clicked();
22 |
23 | void on_pushButton_update_clicked();
24 |
25 | void on_pushButton_read_clicked();
26 |
27 | private:
28 | Ui::MainWindow *ui;
29 | };
30 | #endif // MAINWINDOW_H
31 |
--------------------------------------------------------------------------------
/2dialog_1listview/mainwindow.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | MainWindow
4 |
5 |
6 |
7 | 0
8 | 0
9 | 800
10 | 600
11 |
12 |
13 |
14 | MainWindow
15 |
16 |
17 |
18 | background-color:rgb(41, 47, 68)
19 |
20 |
21 | -
22 |
23 |
24 | -
25 |
26 |
-
27 |
28 |
29 | 修改一项
30 |
31 |
32 |
33 | -
34 |
35 |
36 | 读取一项
37 |
38 |
39 |
40 | -
41 |
42 |
43 | 去除一项
44 |
45 |
46 |
47 | -
48 |
49 |
50 | 添加一项
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
68 |
69 |
70 |
71 |
72 |
73 |
--------------------------------------------------------------------------------
/2dialog_1listview/res.qrc:
--------------------------------------------------------------------------------
1 |
2 |
3 | img/delete.png
4 |
5 |
6 |
--------------------------------------------------------------------------------
/2dialog_1tablewidget/2dialog_1tablewidget.pro:
--------------------------------------------------------------------------------
1 | QT += core gui
2 |
3 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
4 |
5 | CONFIG += c++11
6 |
7 | # The following define makes your compiler emit warnings if you use
8 | # any Qt feature that has been marked deprecated (the exact warnings
9 | # depend on your compiler). Please consult the documentation of the
10 | # deprecated API in order to know how to port your code away from it.
11 | DEFINES += QT_DEPRECATED_WARNINGS
12 |
13 | # You can also make your code fail to compile if it uses deprecated APIs.
14 | # In order to do so, uncomment the following line.
15 | # You can also select to disable deprecated APIs only up to a certain version of Qt.
16 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
17 |
18 | SOURCES += \
19 | main.cpp \
20 | mainwindow.cpp
21 |
22 | HEADERS += \
23 | mainwindow.h
24 |
25 | FORMS += \
26 | mainwindow.ui
27 |
28 | # Default rules for deployment.
29 | qnx: target.path = /tmp/$${TARGET}/bin
30 | else: unix:!android: target.path = /opt/$${TARGET}/bin
31 | !isEmpty(target.path): INSTALLS += target
32 |
--------------------------------------------------------------------------------
/2dialog_1tablewidget/main.cpp:
--------------------------------------------------------------------------------
1 | #include "mainwindow.h"
2 |
3 | #include
4 |
5 | int main(int argc, char *argv[])
6 | {
7 | QApplication a(argc, argv);
8 | MainWindow w;
9 | w.show();
10 | return a.exec();
11 | }
12 |
--------------------------------------------------------------------------------
/2dialog_1tablewidget/mainwindow.cpp:
--------------------------------------------------------------------------------
1 | #include "mainwindow.h"
2 | #include "ui_mainwindow.h"
3 | #include
4 | #include
5 | #include
6 |
7 | MainWindow::MainWindow(QWidget *parent): QMainWindow(parent), ui(new Ui::MainWindow)
8 | {
9 | ui->setupUi(this);
10 |
11 | ui->main_tw->setColumnCount(2);
12 | ui->main_tw->setRowCount(2);
13 | ui->main_tw->setHorizontalHeaderLabels(QStringList()<<"插件名称" << "插件路径");
14 | ui->main_tw->setSelectionBehavior(QAbstractItemView::SelectRows); //整行选中的方式
15 | ui->main_tw->setEditTriggers(QAbstractItemView::NoEditTriggers); //禁止修改
16 | ui->main_tw->setSelectionMode(QAbstractItemView::SingleSelection); //设置为可以选中单个
17 | ui->main_tw->setItem(0,0,new QTableWidgetItem("词法分析"));
18 | ui->main_tw->setItem(0,1,new QTableWidgetItem("C:\\Users\\MarkCen\\Desktop\\DProject\\000PROJECT\\ui"));
19 | ui->main_tw->verticalHeader()->setVisible(false);//隐藏列表头
20 | ui->main_tw->setItem(1,0,new QTableWidgetItem("语义分析"));
21 | ui->main_tw->setItem(1,1,new QTableWidgetItem("C:\\Users\\MarkCen\\Desktop\\DProject\\000PROJECT\\ui"));
22 |
23 | ui->main_tw->selectRow(0);
24 | //设置样式
25 | //设置表格样式
26 | ui->main_tw->setStyleSheet(
27 | "color:rgb(234,234,234);"
28 | "gridline-color:rgb(41,47,68);" /*表格中的网格线条颜色*/
29 | "background:rgb(41,47,68);"
30 | /*"alternate-background-color:gray;" *//*设置交替颜色*/
31 | "selection-color:rgb(234,234,234);"
32 | "selection-background-color:rgb(33,37,50);"
33 | "border:none;");
34 |
35 | //设置表头样式
36 | ui->main_tw->horizontalHeader()->setStyleSheet(
37 | "QHeaderView::section{background:rgb(33,37,50); padding:4px; border:0px solid rgb(41,47,68); color:rgb(234,234,234);}"
38 | "QHeaderView::section:checked{background-color:rgb(41,47,68); color:rgb(234,234,234);}");
39 | ui->main_tw->horizontalHeader()->setSectionResizeMode(QHeaderView::Interactive);
40 | ui->main_tw->horizontalHeader()->setStretchLastSection(true);//最后一列伸缩铺满
41 | ui->main_tw->setFocusPolicy(Qt::NoFocus);
42 |
43 | ui->main_tw->verticalScrollBar()->setStyleSheet(
44 | "QScrollBar:vertical{width:8px;background:rgba(0,0,0,0%);margin:0px,0px,0px,0px;padding-top:9px;padding-bottom:9px;}"
45 | "QScrollBar::handle:vertical{width:8px;background:rgba(0,0,0,25%);border-radius:4px;min-height:20;}"
46 | "QScrollBar::handle:vertical:hover{width:8px;background:rgba(0,0,0,50%);border-radius:4px;min-height:20;}"
47 | "QScrollBar::add-line:vertical{height:9px;width:8px;subcontrol-position:bottom;}"
48 | "QScrollBar::sub-line:vertical{height:9px;width:8px;subcontrol-position:top;}"
49 | "QScrollBar::add-line:vertical:hover{height:9px;width:8px;subcontrol-position:bottom;}"
50 | "QScrollBar::sub-line:vertical:hover{height:9px;width:8px;subcontrol-position:top;}"
51 | "QScrollBar::add-page:vertical,QScrollBar::sub-page:vertical{background:rgba(0,0,0,10%);border-radius:4px;}");
52 | }
53 |
54 | MainWindow::~MainWindow()
55 | {
56 | delete ui;
57 | }
58 |
59 | void MainWindow::on_main_bt_add_clicked()
60 | {
61 | int count = ui->main_tw->rowCount();
62 | qDebug()<main_tw->setRowCount(count+1);
64 | ui->main_tw->setItem(count,0,new QTableWidgetItem("语法分析"));
65 | ui->main_tw->setItem(count,1,new QTableWidgetItem("C:\\Users\\MarkCen\\Desktop\\DProject\\000PROJECT"));
66 | count = ui->main_tw->rowCount();
67 | qDebug()<main_tw->rowCount();
73 | if (ui->main_tw->currentItem() != Q_NULLPTR)
74 | {
75 | QMessageBox* msgBox = new QMessageBox;
76 | msgBox->setWindowFlags(Qt::Widget | Qt::FramelessWindowHint | Qt::WindowSystemMenuHint | Qt::WindowStaysOnTopHint);
77 | msgBox->setText("确实要删除吗?");
78 | msgBox->setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
79 | msgBox->setDefaultButton(QMessageBox::Ok);
80 | msgBox->setStyleSheet("QPushButton{background-color:rgb(255, 85, 0);color: rgb(85, 255, 0);}"
81 | "QMessageBox{background-color:white}");
82 | int ret = msgBox->exec();
83 | if(ret == QMessageBox::Ok){
84 | ui->main_tw->removeRow(ui->main_tw->currentRow());
85 | ui->main_tw->setRowCount(count-1);
86 | }
87 | delete msgBox;
88 | }
89 | }
90 |
91 | void MainWindow::on_main_bt_update_clicked()
92 | {
93 | int row = ui->main_tw->currentRow();
94 | QTableWidgetItem *item1 =ui->main_tw->item(row, 1);
95 | item1->setText("哈哈哈哈");
96 | ui->main_tw->setItem(row, 1, item1);
97 |
98 | }
99 |
100 | void MainWindow::on_main_bt_read_clicked()
101 | {
102 | int row = ui->main_tw->currentRow();
103 |
104 | QTableWidgetItem *item0 =ui->main_tw->item(row, 0);
105 | QTableWidgetItem *item1 =ui->main_tw->item(row, 1);
106 |
107 | qDebug()<< "---------> item0:" << item0->text() << endl;
108 | qDebug()<< "---------> item1:" << item1->text() << endl;
109 |
110 | }
111 |
--------------------------------------------------------------------------------
/2dialog_1tablewidget/mainwindow.h:
--------------------------------------------------------------------------------
1 | #ifndef MAINWINDOW_H
2 | #define MAINWINDOW_H
3 |
4 | #include
5 |
6 | QT_BEGIN_NAMESPACE
7 | namespace Ui { class MainWindow; }
8 | QT_END_NAMESPACE
9 |
10 | class MainWindow : public QMainWindow
11 | {
12 | Q_OBJECT
13 |
14 | public:
15 | MainWindow(QWidget *parent = nullptr);
16 | ~MainWindow();
17 |
18 | private slots:
19 | void on_main_bt_add_clicked();
20 |
21 | void on_main_bt_delete_clicked();
22 |
23 | void on_main_bt_update_clicked();
24 |
25 | void on_main_bt_read_clicked();
26 |
27 | private:
28 | Ui::MainWindow *ui;
29 | };
30 | #endif // MAINWINDOW_H
31 |
--------------------------------------------------------------------------------
/2dialog_1tablewidget/mainwindow.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | MainWindow
4 |
5 |
6 |
7 | 0
8 | 0
9 | 800
10 | 423
11 |
12 |
13 |
14 | MainWindow
15 |
16 |
17 |
18 | background:rgb(41, 47, 68)
19 |
20 |
21 | -
22 |
23 |
24 | QAbstractItemView::AnyKeyPressed|QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed
25 |
26 |
27 | QAbstractItemView::SingleSelection
28 |
29 |
30 | Qt::NoPen
31 |
32 |
33 |
34 | -
35 |
36 |
-
37 |
38 |
39 | 添加
40 |
41 |
42 |
43 | -
44 |
45 |
46 | 删除选择项
47 |
48 |
49 |
50 | -
51 |
52 |
53 | 修改选择项
54 |
55 |
56 |
57 | -
58 |
59 |
60 | 读取选择项
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
--------------------------------------------------------------------------------
/2dialog_2pdfreader/2dialog_2pdfreader.pro:
--------------------------------------------------------------------------------
1 | QT += core gui
2 |
3 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
4 |
5 | CONFIG += c++11
6 |
7 | # The following define makes your compiler emit warnings if you use
8 | # any Qt feature that has been marked deprecated (the exact warnings
9 | # depend on your compiler). Please consult the documentation of the
10 | # deprecated API in order to know how to port your code away from it.
11 | DEFINES += QT_DEPRECATED_WARNINGS
12 |
13 | # You can also make your code fail to compile if it uses deprecated APIs.
14 | # In order to do so, uncomment the following line.
15 | # You can also select to disable deprecated APIs only up to a certain version of Qt.
16 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
17 |
18 | SOURCES += \
19 | main.cpp \
20 | mainwindow.cpp
21 |
22 | HEADERS += \
23 | mainwindow.h
24 |
25 | FORMS += \
26 | mainwindow.ui
27 |
28 | # Default rules for deployment.
29 | qnx: target.path = /tmp/$${TARGET}/bin
30 | else: unix:!android: target.path = /opt/$${TARGET}/bin
31 | !isEmpty(target.path): INSTALLS += target
32 |
--------------------------------------------------------------------------------
/2dialog_2pdfreader/main.cpp:
--------------------------------------------------------------------------------
1 | #include "mainwindow.h"
2 |
3 | #include
4 |
5 | int main(int argc, char *argv[])
6 | {
7 | QApplication a(argc, argv);
8 | MainWindow w;
9 | w.show();
10 | return a.exec();
11 | }
12 |
--------------------------------------------------------------------------------
/2dialog_2pdfreader/mainwindow.cpp:
--------------------------------------------------------------------------------
1 | #include "mainwindow.h"
2 | #include "ui_mainwindow.h"
3 | #include
4 | #include
5 |
6 | MainWindow::MainWindow(QWidget *parent)
7 | : QMainWindow(parent)
8 | , ui(new Ui::MainWindow)
9 | {
10 | ui->setupUi(this);
11 |
12 |
13 | }
14 |
15 | MainWindow::~MainWindow()
16 | {
17 | delete ui;
18 | }
19 |
20 |
21 | void MainWindow::on_pushButton_clicked()
22 | {
23 | QString qtManulFile="C:\\Users\\MarkCen\\Desktop\\DProject\\000PROJECT\\ui\\note_1Duilib下载与运行Demo.pdf";
24 | QDesktopServices::openUrl(QUrl::fromLocalFile(qtManulFile));
25 | }
26 |
--------------------------------------------------------------------------------
/2dialog_2pdfreader/mainwindow.h:
--------------------------------------------------------------------------------
1 | #ifndef MAINWINDOW_H
2 | #define MAINWINDOW_H
3 |
4 | #include
5 |
6 | QT_BEGIN_NAMESPACE
7 | namespace Ui { class MainWindow; }
8 | QT_END_NAMESPACE
9 |
10 | class MainWindow : public QMainWindow
11 | {
12 | Q_OBJECT
13 |
14 | public:
15 | MainWindow(QWidget *parent = nullptr);
16 | ~MainWindow();
17 |
18 | private slots:
19 | void on_pushButton_clicked();
20 |
21 | private:
22 | Ui::MainWindow *ui;
23 | };
24 | #endif // MAINWINDOW_H
25 |
--------------------------------------------------------------------------------
/2dialog_2pdfreader/mainwindow.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | MainWindow
4 |
5 |
6 |
7 | 0
8 | 0
9 | 800
10 | 600
11 |
12 |
13 |
14 | MainWindow
15 |
16 |
17 |
18 |
19 |
20 | 350
21 | 170
22 | 80
23 | 20
24 |
25 |
26 |
27 | PushButton
28 |
29 |
30 |
31 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/2dialog_3satree/2dialog_3satree.pro:
--------------------------------------------------------------------------------
1 | QT += core gui
2 |
3 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
4 |
5 | CONFIG += c++11
6 |
7 | # The following define makes your compiler emit warnings if you use
8 | # any Qt feature that has been marked deprecated (the exact warnings
9 | # depend on your compiler). Please consult the documentation of the
10 | # deprecated API in order to know how to port your code away from it.
11 | DEFINES += QT_DEPRECATED_WARNINGS
12 |
13 | # You can also make your code fail to compile if it uses deprecated APIs.
14 | # In order to do so, uncomment the following line.
15 | # You can also select to disable deprecated APIs only up to a certain version of Qt.
16 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
17 |
18 | SOURCES += \
19 | binarytree.cpp \
20 | binarytreepainter.cpp \
21 | main.cpp \
22 | mainwindow.cpp
23 |
24 | HEADERS += \
25 | binarytree.h \
26 | binarytreepainter.h \
27 | mainwindow.h
28 |
29 | FORMS += \
30 | mainwindow.ui
31 |
32 | # Default rules for deployment.
33 | qnx: target.path = /tmp/$${TARGET}/bin
34 | else: unix:!android: target.path = /opt/$${TARGET}/bin
35 | !isEmpty(target.path): INSTALLS += target
36 |
--------------------------------------------------------------------------------
/2dialog_3satree/binarytree.cpp:
--------------------------------------------------------------------------------
1 | #include "binarytree.h"
2 | #include
3 | #include
4 | #include
5 | using namespace std;
6 |
7 | BinTreeNode* linkedBinaryTree::Rebuild(vector pre, vector mid)
8 | {
9 | int nodeSize = mid.size();
10 | if (nodeSize == 0)
11 | return NULL;
12 | vector leftPre, leftMid, rightPre, rightMid;
13 | BinTreeNode* Root = new BinTreeNode(pre[0]);
14 | int rootPos = 0;
15 | for (int i = 0; i < nodeSize; i++)
16 | {
17 | if (mid[i] == pre[0])
18 | {
19 | rootPos = i;
20 | break;
21 | }
22 | }
23 | for (int i = 0; i < nodeSize; i++)
24 | {
25 | if (i < rootPos)
26 | {
27 |
28 | leftMid.push_back(mid[i]);
29 |
30 | leftPre.push_back(pre[i + 1]);
31 | }
32 | else if (i > rootPos)
33 | {
34 |
35 | rightMid.push_back(mid[i]);
36 | rightPre.push_back(pre[i]);
37 | }
38 | }
39 | Root->leftChild = Rebuild(leftPre, leftMid);
40 | Root->rightChild = Rebuild(rightPre, rightMid);
41 | return Root;
42 | }
43 |
--------------------------------------------------------------------------------
/2dialog_3satree/binarytree.h:
--------------------------------------------------------------------------------
1 | #ifndef LINKEDBINARYTREE_H
2 | #define LINKEDBINARYTREE_H
3 | #include
4 | #include
5 | #include
6 | #include
7 | using namespace std;
8 | struct BinTreeNode
9 | {
10 | char data;
11 | BinTreeNode*leftChild, *rightChild;
12 | BinTreeNode() { leftChild = NULL; rightChild = NULL; }
13 | BinTreeNode(char x, BinTreeNode*l = NULL, BinTreeNode *r = NULL)
14 | {
15 | data = x;
16 | leftChild = l;
17 | rightChild = r;
18 | }
19 | };
20 | class linkedBinaryTree
21 | {
22 | private:
23 | BinTreeNode * root;
24 | public:
25 | linkedBinaryTree() {}
26 | BinTreeNode* Rebuild(vectorpre, vectormid);
27 | void set(vectorpre, vectormid)
28 | {
29 | root = this->Rebuild(pre, mid);
30 | }
31 | BinTreeNode*getRoot(){return root;}
32 | int getHeight(){int num=this->getHeight(root);return num;}
33 | int getHeight(BinTreeNode*subTree)
34 | {
35 | if (subTree == NULL)return 0;
36 | int i = getHeight(subTree->leftChild);
37 | int j = getHeight(subTree->rightChild);
38 | return (i < j) ? j + 1 : i + 1;
39 | }
40 | };
41 | #endif // LINKEDBINARYTREE_H
42 |
--------------------------------------------------------------------------------
/2dialog_3satree/binarytreepainter.cpp:
--------------------------------------------------------------------------------
1 | #include "binarytreepainter.h"
2 | #include
3 |
4 | #include
5 | #include
6 | #include
7 |
8 | BinaryTreePainter::BinaryTreePainter(QWidget *parent) : QWidget(parent)
9 | {
10 | resize(600, 400);
11 | myTree = new linkedBinaryTree();
12 | }
13 |
14 | bool BinaryTreePainter::setInput(QString input1, QString input2)
15 | {
16 | std::string s1 = input1.toStdString();
17 | std::string s2 = input2.toStdString();
18 | vectorv1;
19 | vectorv2;
20 | for(int i=0;iset(v1,v2);
23 | return true;
24 | }
25 | BinTreeNode* BinaryTreePainter::test()
26 | {
27 | BinTreeNode*root=NULL;
28 | root=new BinTreeNode('A');
29 | root->leftChild=new BinTreeNode('B');
30 | root->rightChild=new BinTreeNode('C');
31 | root->leftChild->leftChild=new BinTreeNode('D');
32 | root->leftChild->rightChild=new BinTreeNode('E');
33 | root->rightChild->leftChild=new BinTreeNode('F');
34 | root->rightChild->rightChild=new BinTreeNode('G');
35 | return root;
36 | }
37 | void BinaryTreePainter::draw(BinTreeNode *node, int x, int y, int angle, bool isLeft, int depth, QPainter *p)
38 | {
39 | int leftAngle, rightAngle;
40 | int dx,dy,nx,ny;
41 | if (node==NULL)
42 | return;
43 | p->drawText(x,y,QChar(node->data));
44 | if (node->leftChild!=NULL)
45 | {
46 | if (depth<2)
47 | {
48 | leftAngle = angle + rand()%15;
49 | } else
50 | {
51 | if (!isLeft) {
52 | leftAngle = angle + rand()%5 + 10;
53 | } else {
54 | leftAngle = rand()%45;
55 | }
56 | }
57 | int lenEdge = rootLengt-depth*35;
58 | dx = -cos(leftAngle*PI/180)*lenEdge;
59 | dy = sin(leftAngle*PI/180)*lenEdge;
60 | nx = x+dx;
61 | ny = y+dy;
62 | p->drawLine(x,y,nx,ny);
63 | draw(node->leftChild,nx,ny,leftAngle,true,depth+1,p);
64 | }
65 | if (node->rightChild!=NULL)
66 | {
67 | if (depth<2)
68 | {
69 | rightAngle = angle + rand()%15;
70 | } else
71 | {
72 | if (isLeft)
73 | {
74 | rightAngle = angle + rand()%5 + 10;
75 | }
76 | else
77 | {
78 | rightAngle = rand()%45;
79 | }
80 | }
81 | int lenEdge = rootLengt-depth*15;
82 | dx = cos(rightAngle*PI/180)*lenEdge;
83 | dy = sin(rightAngle*PI/180)*lenEdge;
84 | nx = x+dx;
85 | ny = y+dy;
86 | p->drawLine(x,y,nx,ny);
87 | draw(node->rightChild,nx,ny,rightAngle,false,depth+1,p);
88 |
89 | }
90 | if (node->leftChild==NULL && node->rightChild==NULL) {return ; }
91 |
92 | }
93 |
94 | void BinaryTreePainter::paintEvent(QPaintEvent *e)
95 | {
96 | QPainter p(this);
97 | draw(myTree->getRoot(), width()/2, height()/2, 10, true, 0, &p);
98 | }
99 |
--------------------------------------------------------------------------------
/2dialog_3satree/binarytreepainter.h:
--------------------------------------------------------------------------------
1 | #ifndef BINARYTREEPAINTER_H
2 | #define BINARYTREEPAINTER_H
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 |
9 | class BinaryTreePainter:public QWidget
10 | {
11 | Q_OBJECT
12 | public:
13 | explicit BinaryTreePainter(QWidget* parent = 0);
14 | bool setInput(QString input1, QString input2);
15 |
16 | protected:
17 | void paintEvent(QPaintEvent *);
18 | void draw(BinTreeNode *node, int x, int y, int angle, bool isLeft, int depth, QPainter *p);
19 | BinTreeNode* test();
20 |
21 | private:
22 | linkedBinaryTree* myTree;
23 | const int rootLengt=100;
24 | const double PI=3.1415926;
25 | };
26 |
27 | #endif // BINARYTREEPAINTER_H
28 |
--------------------------------------------------------------------------------
/2dialog_3satree/main.cpp:
--------------------------------------------------------------------------------
1 | #include "mainwindow.h"
2 |
3 | #include
4 |
5 | int main(int argc, char *argv[])
6 | {
7 | QApplication a(argc, argv);
8 | MainWindow w;
9 | w.show();
10 | return a.exec();
11 | }
12 |
--------------------------------------------------------------------------------
/2dialog_3satree/mainwindow.cpp:
--------------------------------------------------------------------------------
1 | #include "mainwindow.h"
2 | #include "ui_mainwindow.h"
3 | #include "binarytreepainter.h"
4 |
5 | using namespace std;
6 |
7 | MainWindow::MainWindow(QWidget *parent): QMainWindow(parent), ui(new Ui::MainWindow)
8 | {
9 | ui->setupUi(this);
10 |
11 |
12 | }
13 |
14 | MainWindow::~MainWindow()
15 | {
16 | delete ui;
17 | }
18 |
19 |
20 | void MainWindow::on_pushButton_clicked()
21 | {
22 | QString input1 = "ABC##D##EF#";
23 | QString input2 = "#C#B#D#AFE#";
24 | BinaryTreePainter *p = new BinaryTreePainter();
25 | p->setInput(input1,input2);
26 | p->show();
27 | }
28 |
--------------------------------------------------------------------------------
/2dialog_3satree/mainwindow.h:
--------------------------------------------------------------------------------
1 | #ifndef MAINWINDOW_H
2 | #define MAINWINDOW_H
3 |
4 | #include
5 |
6 |
7 | QT_BEGIN_NAMESPACE
8 | namespace Ui { class MainWindow; }
9 | QT_END_NAMESPACE
10 |
11 | //节点
12 | struct MyStackNode
13 | {
14 | int layer;
15 | struct MyBinTreeNode *treeNode;
16 | };
17 |
18 |
19 | class MainWindow : public QMainWindow
20 | {
21 | Q_OBJECT
22 |
23 | public:
24 | MainWindow(QWidget *parent = nullptr);
25 | ~MainWindow();
26 |
27 | private slots:
28 | void on_pushButton_clicked();
29 |
30 | private:
31 | Ui::MainWindow *ui;
32 | };
33 | #endif // MAINWINDOW_H
34 |
--------------------------------------------------------------------------------
/2dialog_3satree/mainwindow.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | MainWindow
4 |
5 |
6 |
7 | 0
8 | 0
9 | 800
10 | 600
11 |
12 |
13 |
14 | MainWindow
15 |
16 |
17 |
18 |
19 |
20 | 390
21 | 330
22 | 80
23 | 20
24 |
25 |
26 |
27 | 测试
28 |
29 |
30 |
31 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/2menubar_1signal_slot/2menubar_1signal_slot.pro:
--------------------------------------------------------------------------------
1 | QT += core gui
2 |
3 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
4 |
5 | CONFIG += c++11
6 |
7 | # The following define makes your compiler emit warnings if you use
8 | # any Qt feature that has been marked deprecated (the exact warnings
9 | # depend on your compiler). Please consult the documentation of the
10 | # deprecated API in order to know how to port your code away from it.
11 | DEFINES += QT_DEPRECATED_WARNINGS
12 |
13 | # You can also make your code fail to compile if it uses deprecated APIs.
14 | # In order to do so, uncomment the following line.
15 | # You can also select to disable deprecated APIs only up to a certain version of Qt.
16 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
17 |
18 | SOURCES += \
19 | main.cpp \
20 | mainwindow.cpp
21 |
22 | HEADERS += \
23 | mainwindow.h
24 |
25 | FORMS += \
26 | mainwindow.ui
27 |
28 | # Default rules for deployment.
29 | qnx: target.path = /tmp/$${TARGET}/bin
30 | else: unix:!android: target.path = /opt/$${TARGET}/bin
31 | !isEmpty(target.path): INSTALLS += target
32 |
--------------------------------------------------------------------------------
/2menubar_1signal_slot/main.cpp:
--------------------------------------------------------------------------------
1 | #include "mainwindow.h"
2 |
3 | #include
4 |
5 | int main(int argc, char *argv[])
6 | {
7 | QApplication a(argc, argv);
8 | MainWindow w;
9 | w.show();
10 | return a.exec();
11 | }
12 |
--------------------------------------------------------------------------------
/2menubar_1signal_slot/mainwindow.cpp:
--------------------------------------------------------------------------------
1 | #include "mainwindow.h"
2 | #include "ui_mainwindow.h"
3 | #include
4 |
5 | MainWindow::MainWindow(QWidget *parent)
6 | : QMainWindow(parent)
7 | , ui(new Ui::MainWindow)
8 | {
9 | ui->setupUi(this);
10 |
11 | QPushButton* bt_one = new QPushButton;
12 | bt_one->setParent(this);
13 | bt_one->setFixedWidth(200);
14 | bt_one->setFixedHeight(30);
15 | bt_one->setText("点我让另一个按钮变成傻子");
16 |
17 | bt_another = new QPushButton;
18 | bt_another->setParent(this);
19 | bt_another->move(250,0);
20 | bt_another->setFixedWidth(150);
21 | bt_another->setFixedHeight(30);
22 | bt_another->setText("我不是傻子");
23 |
24 | //信号实际上是发送者对象的一个方法
25 | //槽实际上也是接收者对象的一个方法
26 | connect(bt_one, &QPushButton::clicked, this, &MainWindow::change);
27 | }
28 |
29 | //槽处理的事件
30 | void MainWindow::change(){
31 | bt_another->setText("我是傻子");
32 | }
33 |
34 | MainWindow::~MainWindow()
35 | {
36 | delete ui;
37 | }
38 |
39 |
--------------------------------------------------------------------------------
/2menubar_1signal_slot/mainwindow.h:
--------------------------------------------------------------------------------
1 | #ifndef MAINWINDOW_H
2 | #define MAINWINDOW_H
3 |
4 | #include
5 | #include
6 |
7 | QT_BEGIN_NAMESPACE
8 | namespace Ui { class MainWindow; }
9 | QT_END_NAMESPACE
10 |
11 | class MainWindow : public QMainWindow
12 | {
13 | Q_OBJECT
14 |
15 | public:
16 | MainWindow(QWidget *parent = nullptr);
17 | ~MainWindow();
18 |
19 | private:
20 | Ui::MainWindow *ui;
21 |
22 | QPushButton* bt_another;
23 | void change();
24 | };
25 | #endif // MAINWINDOW_H
26 |
--------------------------------------------------------------------------------
/2menubar_1signal_slot/mainwindow.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | MainWindow
4 |
5 |
6 |
7 | 0
8 | 0
9 | 800
10 | 600
11 |
12 |
13 |
14 | MainWindow
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/2menubar_2button/2menubar_2button.pro:
--------------------------------------------------------------------------------
1 | QT += core gui
2 |
3 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
4 |
5 | CONFIG += c++11
6 |
7 | # The following define makes your compiler emit warnings if you use
8 | # any Qt feature that has been marked deprecated (the exact warnings
9 | # depend on your compiler). Please consult the documentation of the
10 | # deprecated API in order to know how to port your code away from it.
11 | DEFINES += QT_DEPRECATED_WARNINGS
12 |
13 | # You can also make your code fail to compile if it uses deprecated APIs.
14 | # In order to do so, uncomment the following line.
15 | # You can also select to disable deprecated APIs only up to a certain version of Qt.
16 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
17 |
18 | SOURCES += \
19 | main.cpp \
20 | mainwindow.cpp
21 |
22 | HEADERS += \
23 | mainwindow.h
24 |
25 | FORMS += \
26 | mainwindow.ui
27 |
28 | # Default rules for deployment.
29 | qnx: target.path = /tmp/$${TARGET}/bin
30 | else: unix:!android: target.path = /opt/$${TARGET}/bin
31 | !isEmpty(target.path): INSTALLS += target
32 |
33 | RESOURCES += \
34 | res.qrc
35 |
--------------------------------------------------------------------------------
/2menubar_2button/img/app_round_button_black.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MarkCens/Qt-Learning-Demo/5a7b6ab2216bbacb350825c635d6f3c3928dc311/2menubar_2button/img/app_round_button_black.9.png
--------------------------------------------------------------------------------
/2menubar_2button/img/app_round_button_darkblue.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MarkCens/Qt-Learning-Demo/5a7b6ab2216bbacb350825c635d6f3c3928dc311/2menubar_2button/img/app_round_button_darkblue.9.png
--------------------------------------------------------------------------------
/2menubar_2button/img/app_round_button_gray.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MarkCens/Qt-Learning-Demo/5a7b6ab2216bbacb350825c635d6f3c3928dc311/2menubar_2button/img/app_round_button_gray.9.png
--------------------------------------------------------------------------------
/2menubar_2button/img/app_round_button_green.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MarkCens/Qt-Learning-Demo/5a7b6ab2216bbacb350825c635d6f3c3928dc311/2menubar_2button/img/app_round_button_green.9.png
--------------------------------------------------------------------------------
/2menubar_2button/img/app_round_button_white.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MarkCens/Qt-Learning-Demo/5a7b6ab2216bbacb350825c635d6f3c3928dc311/2menubar_2button/img/app_round_button_white.9.png
--------------------------------------------------------------------------------
/2menubar_2button/main.cpp:
--------------------------------------------------------------------------------
1 | #include "mainwindow.h"
2 |
3 | #include
4 |
5 | int main(int argc, char *argv[])
6 | {
7 | QApplication a(argc, argv);
8 | MainWindow w;
9 | w.show();
10 | return a.exec();
11 | }
12 |
--------------------------------------------------------------------------------
/2menubar_2button/mainwindow.cpp:
--------------------------------------------------------------------------------
1 | #include "mainwindow.h"
2 | #include "ui_mainwindow.h"
3 |
4 | MainWindow::MainWindow(QWidget *parent): QMainWindow(parent), ui(new Ui::MainWindow){
5 | ui->setupUi(this);
6 |
7 | ui->main_menu_bt_analyse->setStyleSheet(
8 | "QPushButton{font-family:'微软雅黑'}"/*设置字体*/
9 | "QPushButton{color:rgb(234,234,234)}"/*设置字体颜色*/
10 | "QPushButton{border-image: url(:/img/app_round_button_darkblue.9.png);}"/*设置按钮背景*/
11 | "QPushButton:hover{border-image: url(:/img/app_round_button_green.9.png);}"/*设置鼠标滑过按钮背景*/
12 | "QPushButton:pressed{border-image: url(:/img/app_round_button_darkblue.9.png);}");/*设置鼠标点击按钮背景*/
13 | }
14 |
15 | MainWindow::~MainWindow(){
16 | delete ui;
17 | }
18 |
19 |
--------------------------------------------------------------------------------
/2menubar_2button/mainwindow.h:
--------------------------------------------------------------------------------
1 | #ifndef MAINWINDOW_H
2 | #define MAINWINDOW_H
3 |
4 | #include
5 |
6 | QT_BEGIN_NAMESPACE
7 | namespace Ui { class MainWindow; }
8 | QT_END_NAMESPACE
9 |
10 | class MainWindow : public QMainWindow
11 | {
12 | Q_OBJECT
13 |
14 | public:
15 | MainWindow(QWidget *parent = nullptr);
16 | ~MainWindow();
17 |
18 | private:
19 | Ui::MainWindow *ui;
20 | };
21 | #endif // MAINWINDOW_H
22 |
--------------------------------------------------------------------------------
/2menubar_2button/mainwindow.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | MainWindow
4 |
5 |
6 |
7 | 0
8 | 0
9 | 800
10 | 600
11 |
12 |
13 |
14 | MainWindow
15 |
16 |
17 |
18 |
19 |
20 | 240
21 | 120
22 | 70
23 | 20
24 |
25 |
26 |
27 | 单步分析
28 |
29 |
30 |
31 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/2menubar_2button/res.qrc:
--------------------------------------------------------------------------------
1 |
2 |
3 | img/app_round_button_black.9.png
4 | img/app_round_button_darkblue.9.png
5 | img/app_round_button_gray.9.png
6 | img/app_round_button_green.9.png
7 | img/app_round_button_white.9.png
8 |
9 |
10 |
--------------------------------------------------------------------------------
/2menubar_3label/2menubar_3label.pro:
--------------------------------------------------------------------------------
1 | QT += core gui
2 |
3 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
4 |
5 | CONFIG += c++11
6 |
7 | # The following define makes your compiler emit warnings if you use
8 | # any Qt feature that has been marked deprecated (the exact warnings
9 | # depend on your compiler). Please consult the documentation of the
10 | # deprecated API in order to know how to port your code away from it.
11 | DEFINES += QT_DEPRECATED_WARNINGS
12 |
13 | # You can also make your code fail to compile if it uses deprecated APIs.
14 | # In order to do so, uncomment the following line.
15 | # You can also select to disable deprecated APIs only up to a certain version of Qt.
16 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
17 |
18 | SOURCES += \
19 | main.cpp \
20 | mainwindow.cpp
21 |
22 | HEADERS += \
23 | mainwindow.h
24 |
25 | FORMS += \
26 | mainwindow.ui
27 |
28 | # Default rules for deployment.
29 | qnx: target.path = /tmp/$${TARGET}/bin
30 | else: unix:!android: target.path = /opt/$${TARGET}/bin
31 | !isEmpty(target.path): INSTALLS += target
32 |
--------------------------------------------------------------------------------
/2menubar_3label/main.cpp:
--------------------------------------------------------------------------------
1 | #include "mainwindow.h"
2 |
3 | #include
4 |
5 | int main(int argc, char *argv[])
6 | {
7 | QApplication a(argc, argv);
8 | MainWindow w;
9 | w.show();
10 | return a.exec();
11 | }
12 |
--------------------------------------------------------------------------------
/2menubar_3label/mainwindow.cpp:
--------------------------------------------------------------------------------
1 | #include "mainwindow.h"
2 | #include "ui_mainwindow.h"
3 |
4 | MainWindow::MainWindow(QWidget *parent)
5 | : QMainWindow(parent)
6 | , ui(new Ui::MainWindow)
7 | {
8 | ui->setupUi(this);
9 | }
10 |
11 | MainWindow::~MainWindow()
12 | {
13 | delete ui;
14 | }
15 |
16 |
--------------------------------------------------------------------------------
/2menubar_3label/mainwindow.h:
--------------------------------------------------------------------------------
1 | #ifndef MAINWINDOW_H
2 | #define MAINWINDOW_H
3 |
4 | #include
5 |
6 | QT_BEGIN_NAMESPACE
7 | namespace Ui { class MainWindow; }
8 | QT_END_NAMESPACE
9 |
10 | class MainWindow : public QMainWindow
11 | {
12 | Q_OBJECT
13 |
14 | public:
15 | MainWindow(QWidget *parent = nullptr);
16 | ~MainWindow();
17 |
18 | private:
19 | Ui::MainWindow *ui;
20 | };
21 | #endif // MAINWINDOW_H
22 |
--------------------------------------------------------------------------------
/2menubar_3label/mainwindow.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | MainWindow
4 |
5 |
6 |
7 | 0
8 | 0
9 | 800
10 | 600
11 |
12 |
13 |
14 | MainWindow
15 |
16 |
17 |
18 |
19 |
20 | 150
21 | 160
22 | 70
23 | 20
24 |
25 |
26 |
27 |
28 | 微软雅黑
29 | 10
30 |
31 |
32 |
33 | color:rgb(234, 234, 234)
34 |
35 |
36 | 行
37 |
38 |
39 | Qt::AlignCenter
40 |
41 |
42 |
43 |
53 |
54 |
55 |
56 |
57 |
58 |
--------------------------------------------------------------------------------
/2menubar_4menu/2menubar_4menu.pro:
--------------------------------------------------------------------------------
1 | QT += core gui
2 |
3 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
4 |
5 | CONFIG += c++11
6 |
7 | # The following define makes your compiler emit warnings if you use
8 | # any Qt feature that has been marked deprecated (the exact warnings
9 | # depend on your compiler). Please consult the documentation of the
10 | # deprecated API in order to know how to port your code away from it.
11 | DEFINES += QT_DEPRECATED_WARNINGS
12 |
13 | # You can also make your code fail to compile if it uses deprecated APIs.
14 | # In order to do so, uncomment the following line.
15 | # You can also select to disable deprecated APIs only up to a certain version of Qt.
16 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
17 |
18 | SOURCES += \
19 | hovermenuanalyse.cpp \
20 | main.cpp \
21 | mainwindow.cpp
22 |
23 | HEADERS += \
24 | hovermenuanalyse.h \
25 | mainwindow.h
26 |
27 | FORMS += \
28 | hover_menu_analysebystep.ui \
29 | mainwindow.ui
30 |
31 | # Default rules for deployment.
32 | qnx: target.path = /tmp/$${TARGET}/bin
33 | else: unix:!android: target.path = /opt/$${TARGET}/bin
34 | !isEmpty(target.path): INSTALLS += target
35 |
36 | RESOURCES += \
37 | res.qrc
38 |
--------------------------------------------------------------------------------
/2menubar_4menu/2menubar_4menu.pro.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | EnvironmentId
7 | {cc04c648-95f6-46a2-8902-3070ddc345f2}
8 |
9 |
10 | ProjectExplorer.Project.ActiveTarget
11 | 0
12 |
13 |
14 | ProjectExplorer.Project.EditorSettings
15 |
16 | true
17 | false
18 | true
19 |
20 | Cpp
21 |
22 | CppGlobal
23 |
24 |
25 |
26 | QmlJS
27 |
28 | QmlJSGlobal
29 |
30 |
31 | 2
32 | UTF-8
33 | false
34 | 4
35 | false
36 | 80
37 | true
38 | true
39 | 1
40 | true
41 | false
42 | 0
43 | true
44 | true
45 | 0
46 | 8
47 | true
48 | 1
49 | true
50 | true
51 | true
52 | false
53 |
54 |
55 |
56 | ProjectExplorer.Project.PluginSettings
57 |
58 |
59 | -fno-delayed-template-parsing
60 |
61 | true
62 |
63 |
64 |
65 | ProjectExplorer.Project.Target.0
66 |
67 | Desktop Qt 5.14.1 MinGW 32-bit
68 | Desktop Qt 5.14.1 MinGW 32-bit
69 | qt.qt5.5141.win32_mingw73_kit
70 | 0
71 | 0
72 | 0
73 |
74 | H:/Learn_Code/QtProjects/Lab/build-2menubar_4menu-Desktop_Qt_5_14_1_MinGW_32_bit-Debug
75 |
76 |
77 | true
78 | QtProjectManager.QMakeBuildStep
79 | true
80 |
81 | false
82 | false
83 | false
84 |
85 |
86 | true
87 | Qt4ProjectManager.MakeStep
88 |
89 | false
90 |
91 |
92 | false
93 |
94 | 2
95 | Build
96 | Build
97 | ProjectExplorer.BuildSteps.Build
98 |
99 |
100 |
101 | true
102 | Qt4ProjectManager.MakeStep
103 |
104 | true
105 | clean
106 |
107 | false
108 |
109 | 1
110 | Clean
111 | Clean
112 | ProjectExplorer.BuildSteps.Clean
113 |
114 | 2
115 | false
116 |
117 | Debug
118 | Qt4ProjectManager.Qt4BuildConfiguration
119 | 2
120 |
121 |
122 | H:/Learn_Code/QtProjects/Lab/build-2menubar_4menu-Desktop_Qt_5_14_1_MinGW_32_bit-Release
123 |
124 |
125 | true
126 | QtProjectManager.QMakeBuildStep
127 | false
128 |
129 | false
130 | false
131 | true
132 |
133 |
134 | true
135 | Qt4ProjectManager.MakeStep
136 |
137 | false
138 |
139 |
140 | false
141 |
142 | 2
143 | Build
144 | Build
145 | ProjectExplorer.BuildSteps.Build
146 |
147 |
148 |
149 | true
150 | Qt4ProjectManager.MakeStep
151 |
152 | true
153 | clean
154 |
155 | false
156 |
157 | 1
158 | Clean
159 | Clean
160 | ProjectExplorer.BuildSteps.Clean
161 |
162 | 2
163 | false
164 |
165 | Release
166 | Qt4ProjectManager.Qt4BuildConfiguration
167 | 0
168 |
169 |
170 | H:/Learn_Code/QtProjects/Lab/build-2menubar_4menu-Desktop_Qt_5_14_1_MinGW_32_bit-Profile
171 |
172 |
173 | true
174 | QtProjectManager.QMakeBuildStep
175 | true
176 |
177 | false
178 | true
179 | true
180 |
181 |
182 | true
183 | Qt4ProjectManager.MakeStep
184 |
185 | false
186 |
187 |
188 | false
189 |
190 | 2
191 | Build
192 | Build
193 | ProjectExplorer.BuildSteps.Build
194 |
195 |
196 |
197 | true
198 | Qt4ProjectManager.MakeStep
199 |
200 | true
201 | clean
202 |
203 | false
204 |
205 | 1
206 | Clean
207 | Clean
208 | ProjectExplorer.BuildSteps.Clean
209 |
210 | 2
211 | false
212 |
213 | Profile
214 | Qt4ProjectManager.Qt4BuildConfiguration
215 | 0
216 |
217 | 3
218 |
219 |
220 | 0
221 | Deploy
222 | Deploy
223 | ProjectExplorer.BuildSteps.Deploy
224 |
225 | 1
226 | ProjectExplorer.DefaultDeployConfiguration
227 |
228 | 1
229 |
230 |
231 | dwarf
232 |
233 | cpu-cycles
234 |
235 |
236 | 250
237 |
238 | -e
239 | cpu-cycles
240 | --call-graph
241 | dwarf,4096
242 | -F
243 | 250
244 |
245 | -F
246 | true
247 | 4096
248 | false
249 | false
250 | 1000
251 |
252 | true
253 |
254 | false
255 | false
256 | false
257 | false
258 | true
259 | 0.01
260 | 10
261 | true
262 | kcachegrind
263 | 1
264 | 25
265 |
266 | 1
267 | true
268 | false
269 | true
270 | valgrind
271 |
272 | 0
273 | 1
274 | 2
275 | 3
276 | 4
277 | 5
278 | 6
279 | 7
280 | 8
281 | 9
282 | 10
283 | 11
284 | 12
285 | 13
286 | 14
287 |
288 | 2
289 |
290 | Qt4ProjectManager.Qt4RunConfiguration:H:/Learn_Code/QtProjects/Lab/2menubar_4menu/2menubar_4menu.pro
291 | H:/Learn_Code/QtProjects/Lab/2menubar_4menu/2menubar_4menu.pro
292 |
293 | false
294 |
295 | false
296 | true
297 | true
298 | false
299 | false
300 | true
301 |
302 | H:/Learn_Code/QtProjects/Lab/build-2menubar_4menu-Desktop_Qt_5_14_1_MinGW_32_bit-Debug
303 |
304 | 1
305 |
306 |
307 |
308 | ProjectExplorer.Project.TargetCount
309 | 1
310 |
311 |
312 | ProjectExplorer.Project.Updater.FileVersion
313 | 22
314 |
315 |
316 | Version
317 | 22
318 |
319 |
320 |
--------------------------------------------------------------------------------
/2menubar_4menu/hover_menu_analysebystep.ui:
--------------------------------------------------------------------------------
1 |
2 | Dialog
3 |
4 |
5 |
6 | 0
7 | 0
8 | 400
9 | 300
10 |
11 |
12 |
13 | Dialog
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/2menubar_4menu/hovermenuanalyse.cpp:
--------------------------------------------------------------------------------
1 | #include "hovermenuanalyse.h"
2 |
3 | HoverMenuAnalyse::HoverMenuAnalyse()
4 | {
5 |
6 | }
7 |
--------------------------------------------------------------------------------
/2menubar_4menu/hovermenuanalyse.h:
--------------------------------------------------------------------------------
1 | #ifndef HOVERMENUANALYSE_H
2 | #define HOVERMENUANALYSE_H
3 |
4 | #include
5 |
6 | class HoverMenuAnalyse : public QDialog
7 | {
8 | public:
9 | HoverMenuAnalyse();
10 | };
11 |
12 | #endif // HOVERMENUANALYSE_H
13 |
--------------------------------------------------------------------------------
/2menubar_4menu/img/app_2menu_new.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MarkCens/Qt-Learning-Demo/5a7b6ab2216bbacb350825c635d6f3c3928dc311/2menubar_4menu/img/app_2menu_new.png
--------------------------------------------------------------------------------
/2menubar_4menu/img/app_2menu_open.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MarkCens/Qt-Learning-Demo/5a7b6ab2216bbacb350825c635d6f3c3928dc311/2menubar_4menu/img/app_2menu_open.png
--------------------------------------------------------------------------------
/2menubar_4menu/img/app_2menu_save.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MarkCens/Qt-Learning-Demo/5a7b6ab2216bbacb350825c635d6f3c3928dc311/2menubar_4menu/img/app_2menu_save.png
--------------------------------------------------------------------------------
/2menubar_4menu/main.cpp:
--------------------------------------------------------------------------------
1 | #include "mainwindow.h"
2 |
3 | #include
4 |
5 | int main(int argc, char *argv[])
6 | {
7 | QApplication a(argc, argv);
8 | MainWindow w;
9 | w.show();
10 | return a.exec();
11 | }
12 |
--------------------------------------------------------------------------------
/2menubar_4menu/mainwindow.cpp:
--------------------------------------------------------------------------------
1 | #include "mainwindow.h"
2 | #include "ui_mainwindow.h"
3 | #include
4 | #include
5 | #include
6 |
7 | MainWindow::MainWindow(QWidget *parent): QMainWindow(parent), ui(new Ui::MainWindow){
8 | ui->setupUi(this);
9 | /*
10 | ui->pushButton->installEventFilter(this);
11 | ui->pushButton->move(0,0);
12 | mian_menu_qd_analysebystep = new QDialog (this);
13 | QPushButton* bt1 = new QPushButton("哈哈哈", mian_menu_qd_analysebystep);
14 | QPushButton* bt2 = new QPushButton("哈哈哈", mian_menu_qd_analysebystep);
15 | QPushButton* bt3 = new QPushButton("哈哈哈", mian_menu_qd_analysebystep);
16 | mian_menu_qd_analysebystep->setWindowFlags(Qt::FramelessWindowHint);
17 | mian_menu_qd_analysebystep->hide();
18 | connect(ui->pushButton, &QPushButton::clicked, this, &MainWindow::btClick);
19 | */
20 |
21 | menuBar = new QMenuBar(this);
22 | QMenu* rootmenu = new QMenu("文件");
23 |
24 | QAction* action1= new QAction("新建");
25 | action1->setIcon(QIcon(":/img/app_2menu_new.png"));
26 | action1->setFont(QFont("微软雅黑"));
27 | QAction* action2= new QAction("打开");
28 | action2->setIcon(QIcon(":/img/app_2menu_open.png"));
29 | action2->setFont(QFont("微软雅黑"));
30 | QAction* action3= new QAction("关闭");
31 | action3->setIcon(QIcon(":/img/app_2menu_save.png"));
32 | action3->setFont(QFont("微软雅黑"));
33 | rootmenu->addAction(action1);
34 | rootmenu->addAction(action2);
35 | rootmenu->addAction(action3);
36 | menuBar->addMenu(rootmenu);
37 |
38 |
39 | menuBar->setStyleSheet(
40 | //5、以下为对菜单和菜单栏的设置(较简单)
41 | "QMenuBar{background-color:rgb(41,47,68);spacing:10;}"
42 | //"QMenuBar::item{background-color:rgb(41,47,68);}"
43 | "QMenu{background-color:rgb(41,47,68);}"
44 | "QMenu{color:rgb(255,255,255);spacing:10;}"
45 | "QMenu{font-family:'微软雅黑';}"
46 | );
47 |
48 | rootmenu->setStyleSheet(
49 | "QMenu{background-color:rgb(41,47,68);}"
50 | "QMenu::item{background-color:rgb(41,47,68);}"
51 | "QMenu::item{color:rgb(234,234,234);}"
52 | "QMenu::item{font-family:'微软雅黑';}"
53 | "QMenu::item:selected{background-color:rgb(33,37,50);}");
54 |
55 | }
56 |
57 | MainWindow::~MainWindow(){
58 | delete ui;
59 | }
60 |
61 | bool MainWindow::eventFilter(QObject *target, QEvent *e){
62 | // QPoint coursePoint;
63 | // coursePoint = QCursor::pos();//获取当前光标的位置
64 |
65 | // if(target == ui->pushButton)
66 | // {
67 | // if(e->type() == QEvent::Enter)
68 | // {
69 | // mian_menu_qd_analysebystep->move(coursePoint.x(),coursePoint.y());//坐标
70 | // int x=coursePoint.x()-300;
71 | // int y=coursePoint.y()-300;
72 | // //mian_menu_qd_analysebystep->setGeometry(x,y,150,150);
73 | // mian_menu_qd_analysebystep->show();
74 | // qDebug()<<("---------------------test:QEvent::Enter");
75 | // }
76 | // if(e->type() == QEvent::Leave)
77 | // {
78 | // mian_menu_qd_analysebystep->hide();
79 | // qDebug()<<("---------------------test:QEvent::Leave");
80 | // }
81 |
82 | // }
83 | return QWidget::eventFilter(target, e);
84 | }
85 |
86 | void MainWindow::btClick(){
87 | qDebug()<<("---------------------test:QPushButton::Click");
88 | }
89 |
90 |
--------------------------------------------------------------------------------
/2menubar_4menu/mainwindow.h:
--------------------------------------------------------------------------------
1 | #ifndef MAINWINDOW_H
2 | #define MAINWINDOW_H
3 |
4 | #include
5 | #include
6 |
7 | QT_BEGIN_NAMESPACE
8 | namespace Ui { class MainWindow; }
9 | QT_END_NAMESPACE
10 |
11 | class MainWindow : public QMainWindow
12 | {
13 | Q_OBJECT
14 |
15 | public:
16 | MainWindow(QWidget *parent = nullptr);
17 | ~MainWindow();
18 |
19 | public:
20 | QDialog *mian_menu_qd_analysebystep;
21 | bool eventFilter(QObject *target, QEvent *e);
22 |
23 |
24 | private:
25 | Ui::MainWindow *ui;
26 |
27 | void btClick();
28 |
29 | QMenu* file_menu;
30 | QMenuBar* menuBar;
31 | };
32 | #endif // MAINWINDOW_H
33 |
--------------------------------------------------------------------------------
/2menubar_4menu/mainwindow.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | MainWindow
4 |
5 |
6 |
7 | 0
8 | 0
9 | 800
10 | 600
11 |
12 |
13 |
14 | MainWindow
15 |
16 |
17 |
18 |
19 |
20 | 0
21 | 330
22 | 80
23 | 20
24 |
25 |
26 |
27 | PushButton
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/2menubar_4menu/menu_analyse_by_step.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | Dialog
4 |
5 |
6 |
7 | 0
8 | 0
9 | 400
10 | 300
11 |
12 |
13 |
14 | Dialog
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/2menubar_4menu/res.qrc:
--------------------------------------------------------------------------------
1 |
2 |
3 | img/app_2menu_new.png
4 | img/app_2menu_open.png
5 | img/app_2menu_save.png
6 |
7 |
8 |
--------------------------------------------------------------------------------
/2menubar_5modal/2menubar_5modal.pro:
--------------------------------------------------------------------------------
1 | QT += core gui
2 |
3 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
4 |
5 | CONFIG += c++11
6 |
7 | # The following define makes your compiler emit warnings if you use
8 | # any Qt feature that has been marked deprecated (the exact warnings
9 | # depend on your compiler). Please consult the documentation of the
10 | # deprecated API in order to know how to port your code away from it.
11 | DEFINES += QT_DEPRECATED_WARNINGS
12 |
13 | # You can also make your code fail to compile if it uses deprecated APIs.
14 | # In order to do so, uncomment the following line.
15 | # You can also select to disable deprecated APIs only up to a certain version of Qt.
16 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
17 |
18 | SOURCES += \
19 | main.cpp \
20 | mainwindow.cpp \
21 | settingdialog.cpp
22 |
23 | HEADERS += \
24 | mainwindow.h \
25 | settingdialog.h
26 |
27 | FORMS += \
28 | mainwindow.ui \
29 | settingdialog.ui
30 |
31 | # Default rules for deployment.
32 | qnx: target.path = /tmp/$${TARGET}/bin
33 | else: unix:!android: target.path = /opt/$${TARGET}/bin
34 | !isEmpty(target.path): INSTALLS += target
35 |
--------------------------------------------------------------------------------
/2menubar_5modal/2menubar_5modal.pro.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | EnvironmentId
7 | {cc04c648-95f6-46a2-8902-3070ddc345f2}
8 |
9 |
10 | ProjectExplorer.Project.ActiveTarget
11 | 0
12 |
13 |
14 | ProjectExplorer.Project.EditorSettings
15 |
16 | true
17 | false
18 | true
19 |
20 | Cpp
21 |
22 | CppGlobal
23 |
24 |
25 |
26 | QmlJS
27 |
28 | QmlJSGlobal
29 |
30 |
31 | 2
32 | UTF-8
33 | false
34 | 4
35 | false
36 | 80
37 | true
38 | true
39 | 1
40 | true
41 | false
42 | 0
43 | true
44 | true
45 | 0
46 | 8
47 | true
48 | 1
49 | true
50 | true
51 | true
52 | false
53 |
54 |
55 |
56 | ProjectExplorer.Project.PluginSettings
57 |
58 |
59 |
60 | ProjectExplorer.Project.Target.0
61 |
62 | Desktop Qt 5.14.1 MinGW 32-bit
63 | Desktop Qt 5.14.1 MinGW 32-bit
64 | qt.qt5.5141.win32_mingw73_kit
65 | 0
66 | 0
67 | 0
68 |
69 | H:/Learn_Code/QtProjects/Lab/build-2menubar_5modal-Desktop_Qt_5_14_1_MinGW_32_bit-Debug
70 |
71 |
72 | true
73 | QtProjectManager.QMakeBuildStep
74 | true
75 |
76 | false
77 | false
78 | false
79 |
80 |
81 | true
82 | Qt4ProjectManager.MakeStep
83 |
84 | false
85 |
86 |
87 | false
88 |
89 | 2
90 | Build
91 | Build
92 | ProjectExplorer.BuildSteps.Build
93 |
94 |
95 |
96 | true
97 | Qt4ProjectManager.MakeStep
98 |
99 | true
100 | clean
101 |
102 | false
103 |
104 | 1
105 | Clean
106 | Clean
107 | ProjectExplorer.BuildSteps.Clean
108 |
109 | 2
110 | false
111 |
112 | Debug
113 | Qt4ProjectManager.Qt4BuildConfiguration
114 | 2
115 |
116 |
117 | H:/Learn_Code/QtProjects/Lab/build-2menubar_5modal-Desktop_Qt_5_14_1_MinGW_32_bit-Release
118 |
119 |
120 | true
121 | QtProjectManager.QMakeBuildStep
122 | false
123 |
124 | false
125 | false
126 | true
127 |
128 |
129 | true
130 | Qt4ProjectManager.MakeStep
131 |
132 | false
133 |
134 |
135 | false
136 |
137 | 2
138 | Build
139 | Build
140 | ProjectExplorer.BuildSteps.Build
141 |
142 |
143 |
144 | true
145 | Qt4ProjectManager.MakeStep
146 |
147 | true
148 | clean
149 |
150 | false
151 |
152 | 1
153 | Clean
154 | Clean
155 | ProjectExplorer.BuildSteps.Clean
156 |
157 | 2
158 | false
159 |
160 | Release
161 | Qt4ProjectManager.Qt4BuildConfiguration
162 | 0
163 |
164 |
165 | H:/Learn_Code/QtProjects/Lab/build-2menubar_5modal-Desktop_Qt_5_14_1_MinGW_32_bit-Profile
166 |
167 |
168 | true
169 | QtProjectManager.QMakeBuildStep
170 | true
171 |
172 | false
173 | true
174 | true
175 |
176 |
177 | true
178 | Qt4ProjectManager.MakeStep
179 |
180 | false
181 |
182 |
183 | false
184 |
185 | 2
186 | Build
187 | Build
188 | ProjectExplorer.BuildSteps.Build
189 |
190 |
191 |
192 | true
193 | Qt4ProjectManager.MakeStep
194 |
195 | true
196 | clean
197 |
198 | false
199 |
200 | 1
201 | Clean
202 | Clean
203 | ProjectExplorer.BuildSteps.Clean
204 |
205 | 2
206 | false
207 |
208 | Profile
209 | Qt4ProjectManager.Qt4BuildConfiguration
210 | 0
211 |
212 | 3
213 |
214 |
215 | 0
216 | Deploy
217 | Deploy
218 | ProjectExplorer.BuildSteps.Deploy
219 |
220 | 1
221 | ProjectExplorer.DefaultDeployConfiguration
222 |
223 | 1
224 |
225 |
226 | dwarf
227 |
228 | cpu-cycles
229 |
230 |
231 | 250
232 |
233 | -e
234 | cpu-cycles
235 | --call-graph
236 | dwarf,4096
237 | -F
238 | 250
239 |
240 | -F
241 | true
242 | 4096
243 | false
244 | false
245 | 1000
246 |
247 | true
248 |
249 | false
250 | false
251 | false
252 | false
253 | true
254 | 0.01
255 | 10
256 | true
257 | kcachegrind
258 | 1
259 | 25
260 |
261 | 1
262 | true
263 | false
264 | true
265 | valgrind
266 |
267 | 0
268 | 1
269 | 2
270 | 3
271 | 4
272 | 5
273 | 6
274 | 7
275 | 8
276 | 9
277 | 10
278 | 11
279 | 12
280 | 13
281 | 14
282 |
283 | 2
284 |
285 | Qt4ProjectManager.Qt4RunConfiguration:H:/Learn_Code/QtProjects/Lab/2menubar_5modal/2menubar_5modal.pro
286 | H:/Learn_Code/QtProjects/Lab/2menubar_5modal/2menubar_5modal.pro
287 |
288 | false
289 |
290 | false
291 | true
292 | true
293 | false
294 | false
295 | true
296 |
297 | H:/Learn_Code/QtProjects/Lab/build-2menubar_5modal-Desktop_Qt_5_14_1_MinGW_32_bit-Debug
298 |
299 | 1
300 |
301 |
302 |
303 | ProjectExplorer.Project.TargetCount
304 | 1
305 |
306 |
307 | ProjectExplorer.Project.Updater.FileVersion
308 | 22
309 |
310 |
311 | Version
312 | 22
313 |
314 |
315 |
--------------------------------------------------------------------------------
/2menubar_5modal/main.cpp:
--------------------------------------------------------------------------------
1 | #include "mainwindow.h"
2 |
3 | #include
4 |
5 | int main(int argc, char *argv[])
6 | {
7 | QApplication a(argc, argv);
8 | MainWindow w;
9 | w.show();
10 | return a.exec();
11 | }
12 |
--------------------------------------------------------------------------------
/2menubar_5modal/mainwindow.cpp:
--------------------------------------------------------------------------------
1 | #include "mainwindow.h"
2 | #include "ui_mainwindow.h"
3 |
4 | MainWindow::MainWindow(QWidget *parent): QMainWindow(parent), ui(new Ui::MainWindow){
5 | ui->setupUi(this);
6 |
7 | //把给定的组件设定成主窗口的中央组件,这里是把plainTextEdit设为窗口的中央组件
8 | setCentralWidget(ui->pushButton);
9 |
10 | connect(ui->pushButton, &QPushButton::clicked, this, &MainWindow::on_actionNew_Window_triggered);
11 | }
12 |
13 | MainWindow::~MainWindow(){
14 | delete ui;
15 | }
16 |
17 | void MainWindow::on_actionNew_Window_triggered() {
18 | //新建一个窗口对象,其中的this指定了新的窗口的父对象是MainWindow,在销毁Mainwindow时也会销毁子对象,即该窗口对象
19 | settingDialog = new SettingDialog(this);
20 | //Modal属性决定了show()应该将弹出的dialog设置为模态还是非模态
21 | //默认情况下该属性为false并且show()弹出的窗口是非模态的
22 | //把这个属性设置为true就详单与设置QWidget::windowModality为Qt::ApplicationModal
23 | //执行exec()忽略这个Modal这个属性,并且把弹出的dialog设置为模态的
24 | settingDialog->setModal(true); //此处ture为模态,false为非模态
25 | settingDialog->show();
26 | }
27 |
28 |
29 |
--------------------------------------------------------------------------------
/2menubar_5modal/mainwindow.h:
--------------------------------------------------------------------------------
1 | #ifndef MAINWINDOW_H
2 | #define MAINWINDOW_H
3 |
4 | #include
5 | #include "settingdialog.h"
6 |
7 | QT_BEGIN_NAMESPACE
8 | namespace Ui { class MainWindow; }
9 | QT_END_NAMESPACE
10 |
11 | class MainWindow : public QMainWindow
12 | {
13 | Q_OBJECT
14 |
15 | public:
16 | MainWindow(QWidget *parent = nullptr);
17 | ~MainWindow();
18 |
19 | private slots:
20 | void on_actionNew_Window_triggered();
21 |
22 | private:
23 | Ui::MainWindow *ui;
24 | SettingDialog* settingDialog;
25 | };
26 | #endif // MAINWINDOW_H
27 |
--------------------------------------------------------------------------------
/2menubar_5modal/mainwindow.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | MainWindow
4 |
5 |
6 |
7 | 0
8 | 0
9 | 800
10 | 600
11 |
12 |
13 |
14 | MainWindow
15 |
16 |
17 |
18 |
19 |
20 | 350
21 | 280
22 | 80
23 | 20
24 |
25 |
26 |
27 | 马上登录
28 |
29 |
30 |
31 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/2menubar_5modal/settingdialog.cpp:
--------------------------------------------------------------------------------
1 | #include "settingdialog.h"
2 | #include "ui_settingdialog.h"
3 |
4 | SettingDialog::SettingDialog(QWidget *parent) :
5 | QDialog(parent),
6 | ui(new Ui::SettingDialog)
7 | {
8 | ui->setupUi(this);
9 | }
10 |
11 | SettingDialog::~SettingDialog()
12 | {
13 | delete ui;
14 | }
15 |
--------------------------------------------------------------------------------
/2menubar_5modal/settingdialog.h:
--------------------------------------------------------------------------------
1 | #ifndef SETTINGDIALOG_H
2 | #define SETTINGDIALOG_H
3 |
4 | #include
5 |
6 | namespace Ui {
7 | class SettingDialog;
8 | }
9 |
10 | class SettingDialog : public QDialog
11 | {
12 | Q_OBJECT
13 |
14 | public:
15 | explicit SettingDialog(QWidget *parent = nullptr);
16 | ~SettingDialog();
17 |
18 | private:
19 | Ui::SettingDialog *ui;
20 | };
21 |
22 | #endif // SETTINGDIALOG_H
23 |
--------------------------------------------------------------------------------
/2menubar_5modal/settingdialog.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | SettingDialog
4 |
5 |
6 |
7 | 0
8 | 0
9 | 400
10 | 300
11 |
12 |
13 |
14 | Dialog
15 |
16 |
17 |
18 |
19 | 99
20 | 230
21 | 181
22 | 20
23 |
24 |
25 |
26 | 登录
27 |
28 |
29 |
30 |
31 |
32 | 100
33 | 75
34 | 54
35 | 12
36 |
37 |
38 |
39 | 学号
40 |
41 |
42 |
43 |
44 |
45 | 170
46 | 70
47 | 113
48 | 20
49 |
50 |
51 |
52 |
53 |
54 |
55 | 170
56 | 100
57 | 113
58 | 20
59 |
60 |
61 |
62 |
63 |
64 |
65 | 100
66 | 102
67 | 54
68 | 12
69 |
70 |
71 |
72 | 口令
73 |
74 |
75 |
76 |
77 |
78 |
79 |
--------------------------------------------------------------------------------
/2menubar_6layout/2menubar_6layout.pro:
--------------------------------------------------------------------------------
1 | QT += core gui
2 |
3 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
4 |
5 | CONFIG += c++11
6 |
7 | # The following define makes your compiler emit warnings if you use
8 | # any Qt feature that has been marked deprecated (the exact warnings
9 | # depend on your compiler). Please consult the documentation of the
10 | # deprecated API in order to know how to port your code away from it.
11 | DEFINES += QT_DEPRECATED_WARNINGS
12 |
13 | # You can also make your code fail to compile if it uses deprecated APIs.
14 | # In order to do so, uncomment the following line.
15 | # You can also select to disable deprecated APIs only up to a certain version of Qt.
16 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
17 |
18 | SOURCES += \
19 | main.cpp \
20 | mainwindow.cpp
21 |
22 | HEADERS += \
23 | mainwindow.h
24 |
25 | FORMS += \
26 | mainwindow.ui
27 |
28 | # Default rules for deployment.
29 | qnx: target.path = /tmp/$${TARGET}/bin
30 | else: unix:!android: target.path = /opt/$${TARGET}/bin
31 | !isEmpty(target.path): INSTALLS += target
32 |
--------------------------------------------------------------------------------
/2menubar_6layout/main.cpp:
--------------------------------------------------------------------------------
1 | #include "mainwindow.h"
2 |
3 | #include
4 |
5 | int main(int argc, char *argv[])
6 | {
7 | QApplication a(argc, argv);
8 | MainWindow w;
9 | w.show();
10 | return a.exec();
11 | }
12 |
--------------------------------------------------------------------------------
/2menubar_6layout/mainwindow.cpp:
--------------------------------------------------------------------------------
1 | #include "mainwindow.h"
2 | #include "ui_mainwindow.h"
3 |
4 | MainWindow::MainWindow(QWidget *parent): QMainWindow(parent), ui(new Ui::MainWindow){
5 | ui->setupUi(this);
6 |
7 |
8 |
9 | ui->wg_result->hide();
10 |
11 | }
12 |
13 | MainWindow::~MainWindow(){
14 | delete ui;
15 | }
16 |
17 |
18 | void MainWindow::on_bt_show_clicked()
19 | {
20 | ui->wg_result->show();
21 | }
22 |
23 | void MainWindow::on_bt_hide_clicked()
24 | {
25 | ui->wg_result->hide();
26 | }
27 |
--------------------------------------------------------------------------------
/2menubar_6layout/mainwindow.h:
--------------------------------------------------------------------------------
1 | #ifndef MAINWINDOW_H
2 | #define MAINWINDOW_H
3 |
4 | #include
5 |
6 | QT_BEGIN_NAMESPACE
7 | namespace Ui { class MainWindow; }
8 | QT_END_NAMESPACE
9 |
10 | class MainWindow : public QMainWindow
11 | {
12 | Q_OBJECT
13 |
14 | public:
15 | MainWindow(QWidget *parent = nullptr);
16 | ~MainWindow();
17 |
18 | private slots:
19 | void on_bt_show_clicked();
20 |
21 | void on_bt_hide_clicked();
22 |
23 | private:
24 | Ui::MainWindow *ui;
25 |
26 | void wg_result_show();
27 | void wg_result_hide();
28 | bool m_wg_result_value = false;
29 | };
30 | #endif // MAINWINDOW_H
31 |
--------------------------------------------------------------------------------
/2menubar_6layout/mainwindow.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | MainWindow
4 |
5 |
6 |
7 | 0
8 | 0
9 | 1052
10 | 671
11 |
12 |
13 |
14 | MainWindow
15 |
16 |
17 |
18 | -
19 |
20 |
-
21 |
22 |
-
23 |
24 |
25 | -
26 |
27 |
-
28 |
29 |
30 | TextLabel
31 |
32 |
33 |
34 | -
35 |
36 |
37 | TextLabel
38 |
39 |
40 |
41 | -
42 |
43 |
44 | TextLabel
45 |
46 |
47 |
48 | -
49 |
50 |
51 | TextLabel
52 |
53 |
54 |
55 | -
56 |
57 |
58 | Qt::Horizontal
59 |
60 |
61 |
62 | 40
63 | 20
64 |
65 |
66 |
67 |
68 | -
69 |
70 |
71 | 显示
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 | -
80 |
81 |
82 |
-
83 |
84 |
-
85 |
86 |
87 | TextLabel
88 |
89 |
90 |
91 | -
92 |
93 |
94 | 隐藏
95 |
96 |
97 |
98 | -
99 |
100 |
101 | TextLabel
102 |
103 |
104 |
105 | -
106 |
107 |
108 | PushButton
109 |
110 |
111 |
112 | -
113 |
114 |
115 | TextLabel
116 |
117 |
118 |
119 | -
120 |
121 |
122 | PushButton
123 |
124 |
125 |
126 | -
127 |
128 |
129 | TextLabel
130 |
131 |
132 |
133 | -
134 |
135 |
136 | PushButton
137 |
138 |
139 |
140 | -
141 |
142 |
143 | TextLabel
144 |
145 |
146 |
147 | -
148 |
149 |
150 | PushButton
151 |
152 |
153 |
154 | -
155 |
156 |
157 | TextLabel
158 |
159 |
160 |
161 | -
162 |
163 |
164 | PushButton
165 |
166 |
167 |
168 | -
169 |
170 |
171 | TextLabel
172 |
173 |
174 |
175 | -
176 |
177 |
178 | PushButton
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
--------------------------------------------------------------------------------
/2menubar_7mymenu/2menubar_7mymenu.pro:
--------------------------------------------------------------------------------
1 | QT += core gui
2 |
3 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
4 |
5 | CONFIG += c++11
6 |
7 | # The following define makes your compiler emit warnings if you use
8 | # any Qt feature that has been marked deprecated (the exact warnings
9 | # depend on your compiler). Please consult the documentation of the
10 | # deprecated API in order to know how to port your code away from it.
11 | DEFINES += QT_DEPRECATED_WARNINGS
12 |
13 | # You can also make your code fail to compile if it uses deprecated APIs.
14 | # In order to do so, uncomment the following line.
15 | # You can also select to disable deprecated APIs only up to a certain version of Qt.
16 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
17 |
18 | SOURCES += \
19 | main.cpp \
20 | mainwindow.cpp
21 |
22 | HEADERS += \
23 | mainwindow.h
24 |
25 | FORMS += \
26 | mainwindow.ui
27 |
28 | # Default rules for deployment.
29 | qnx: target.path = /tmp/$${TARGET}/bin
30 | else: unix:!android: target.path = /opt/$${TARGET}/bin
31 | !isEmpty(target.path): INSTALLS += target
32 |
--------------------------------------------------------------------------------
/2menubar_7mymenu/2menubar_7mymenu.pro.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | EnvironmentId
7 | {cc04c648-95f6-46a2-8902-3070ddc345f2}
8 |
9 |
10 | ProjectExplorer.Project.ActiveTarget
11 | 0
12 |
13 |
14 | ProjectExplorer.Project.EditorSettings
15 |
16 | true
17 | false
18 | true
19 |
20 | Cpp
21 |
22 | CppGlobal
23 |
24 |
25 |
26 | QmlJS
27 |
28 | QmlJSGlobal
29 |
30 |
31 | 2
32 | UTF-8
33 | false
34 | 4
35 | false
36 | 80
37 | true
38 | true
39 | 1
40 | true
41 | false
42 | 0
43 | true
44 | true
45 | 0
46 | 8
47 | true
48 | 1
49 | true
50 | true
51 | true
52 | false
53 |
54 |
55 |
56 | ProjectExplorer.Project.PluginSettings
57 |
58 |
59 |
60 | ProjectExplorer.Project.Target.0
61 |
62 | Desktop Qt 5.14.1 MinGW 32-bit
63 | Desktop Qt 5.14.1 MinGW 32-bit
64 | qt.qt5.5141.win32_mingw73_kit
65 | 0
66 | 0
67 | 0
68 |
69 | H:/Learn_Code/QtProjects/Lab/build-2menubar_7mymenu-Desktop_Qt_5_14_1_MinGW_32_bit-Debug
70 |
71 |
72 | true
73 | QtProjectManager.QMakeBuildStep
74 | true
75 |
76 | false
77 | false
78 | false
79 |
80 |
81 | true
82 | Qt4ProjectManager.MakeStep
83 |
84 | false
85 |
86 |
87 | false
88 |
89 | 2
90 | Build
91 | Build
92 | ProjectExplorer.BuildSteps.Build
93 |
94 |
95 |
96 | true
97 | Qt4ProjectManager.MakeStep
98 |
99 | true
100 | clean
101 |
102 | false
103 |
104 | 1
105 | Clean
106 | Clean
107 | ProjectExplorer.BuildSteps.Clean
108 |
109 | 2
110 | false
111 |
112 | Debug
113 | Qt4ProjectManager.Qt4BuildConfiguration
114 | 2
115 |
116 |
117 | H:/Learn_Code/QtProjects/Lab/build-2menubar_7mymenu-Desktop_Qt_5_14_1_MinGW_32_bit-Release
118 |
119 |
120 | true
121 | QtProjectManager.QMakeBuildStep
122 | false
123 |
124 | false
125 | false
126 | true
127 |
128 |
129 | true
130 | Qt4ProjectManager.MakeStep
131 |
132 | false
133 |
134 |
135 | false
136 |
137 | 2
138 | Build
139 | Build
140 | ProjectExplorer.BuildSteps.Build
141 |
142 |
143 |
144 | true
145 | Qt4ProjectManager.MakeStep
146 |
147 | true
148 | clean
149 |
150 | false
151 |
152 | 1
153 | Clean
154 | Clean
155 | ProjectExplorer.BuildSteps.Clean
156 |
157 | 2
158 | false
159 |
160 | Release
161 | Qt4ProjectManager.Qt4BuildConfiguration
162 | 0
163 |
164 |
165 | H:/Learn_Code/QtProjects/Lab/build-2menubar_7mymenu-Desktop_Qt_5_14_1_MinGW_32_bit-Profile
166 |
167 |
168 | true
169 | QtProjectManager.QMakeBuildStep
170 | true
171 |
172 | false
173 | true
174 | true
175 |
176 |
177 | true
178 | Qt4ProjectManager.MakeStep
179 |
180 | false
181 |
182 |
183 | false
184 |
185 | 2
186 | Build
187 | Build
188 | ProjectExplorer.BuildSteps.Build
189 |
190 |
191 |
192 | true
193 | Qt4ProjectManager.MakeStep
194 |
195 | true
196 | clean
197 |
198 | false
199 |
200 | 1
201 | Clean
202 | Clean
203 | ProjectExplorer.BuildSteps.Clean
204 |
205 | 2
206 | false
207 |
208 | Profile
209 | Qt4ProjectManager.Qt4BuildConfiguration
210 | 0
211 |
212 | 3
213 |
214 |
215 | 0
216 | Deploy
217 | Deploy
218 | ProjectExplorer.BuildSteps.Deploy
219 |
220 | 1
221 | ProjectExplorer.DefaultDeployConfiguration
222 |
223 | 1
224 |
225 |
226 | dwarf
227 |
228 | cpu-cycles
229 |
230 |
231 | 250
232 |
233 | -e
234 | cpu-cycles
235 | --call-graph
236 | dwarf,4096
237 | -F
238 | 250
239 |
240 | -F
241 | true
242 | 4096
243 | false
244 | false
245 | 1000
246 |
247 | true
248 |
249 | false
250 | false
251 | false
252 | false
253 | true
254 | 0.01
255 | 10
256 | true
257 | kcachegrind
258 | 1
259 | 25
260 |
261 | 1
262 | true
263 | false
264 | true
265 | valgrind
266 |
267 | 0
268 | 1
269 | 2
270 | 3
271 | 4
272 | 5
273 | 6
274 | 7
275 | 8
276 | 9
277 | 10
278 | 11
279 | 12
280 | 13
281 | 14
282 |
283 | 2
284 |
285 | Qt4ProjectManager.Qt4RunConfiguration:H:/Learn_Code/QtProjects/Lab/2menubar_7mymenu/2menubar_7mymenu.pro
286 | H:/Learn_Code/QtProjects/Lab/2menubar_7mymenu/2menubar_7mymenu.pro
287 |
288 | false
289 |
290 | false
291 | true
292 | true
293 | false
294 | false
295 | true
296 |
297 | H:/Learn_Code/QtProjects/Lab/build-2menubar_7mymenu-Desktop_Qt_5_14_1_MinGW_32_bit-Debug
298 |
299 | 1
300 |
301 |
302 |
303 | ProjectExplorer.Project.TargetCount
304 | 1
305 |
306 |
307 | ProjectExplorer.Project.Updater.FileVersion
308 | 22
309 |
310 |
311 | Version
312 | 22
313 |
314 |
315 |
--------------------------------------------------------------------------------
/2menubar_7mymenu/main.cpp:
--------------------------------------------------------------------------------
1 | #include "mainwindow.h"
2 |
3 | #include
4 |
5 | int main(int argc, char *argv[])
6 | {
7 | QApplication a(argc, argv);
8 | MainWindow w;
9 | w.show();
10 | return a.exec();
11 | }
12 |
--------------------------------------------------------------------------------
/2menubar_7mymenu/mainwindow.cpp:
--------------------------------------------------------------------------------
1 | #include "mainwindow.h"
2 | #include "ui_mainwindow.h"
3 |
4 | MainWindow::MainWindow(QWidget *parent): QMainWindow(parent), ui(new Ui::MainWindow){
5 | ui->setupUi(this);
6 |
7 | QList lists;
8 | QAction *newFile = new QAction("新建", this);
9 | QAction *openFile = new QAction("打开", this);
10 | QAction *saveFile = new QAction("保存"); //恢复默认设置
11 | QAction *closeFile = new QAction("关闭", this);
12 | QMenu *mfile = new QMenu;
13 | lists.append(newFile);
14 | lists.append(openFile);
15 | lists.append(saveFile);
16 | lists.append(closeFile);
17 | mfile->addActions(lists);
18 |
19 |
20 | ui->bt_file->setMenu(mfile);
21 | }
22 |
23 | MainWindow::~MainWindow(){
24 | delete ui;
25 | }
26 |
27 |
--------------------------------------------------------------------------------
/2menubar_7mymenu/mainwindow.h:
--------------------------------------------------------------------------------
1 | #ifndef MAINWINDOW_H
2 | #define MAINWINDOW_H
3 |
4 | #include
5 |
6 | QT_BEGIN_NAMESPACE
7 | namespace Ui { class MainWindow; }
8 | QT_END_NAMESPACE
9 |
10 | class MainWindow : public QMainWindow
11 | {
12 | Q_OBJECT
13 |
14 | public:
15 | MainWindow(QWidget *parent = nullptr);
16 | ~MainWindow();
17 |
18 | private:
19 | Ui::MainWindow *ui;
20 | };
21 | #endif // MAINWINDOW_H
22 |
--------------------------------------------------------------------------------
/2menubar_7mymenu/mainwindow.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | MainWindow
4 |
5 |
6 |
7 | 0
8 | 0
9 | 800
10 | 600
11 |
12 |
13 |
14 | MainWindow
15 |
16 |
17 |
18 |
19 |
20 | 320
21 | 200
22 | 80
23 | 20
24 |
25 |
26 |
27 | PushButton
28 |
29 |
30 |
31 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/3main_1codeeditor/3main_1codeeditor.pro:
--------------------------------------------------------------------------------
1 | QT += core gui
2 |
3 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
4 |
5 | CONFIG += c++11
6 |
7 | # The following define makes your compiler emit warnings if you use
8 | # any Qt feature that has been marked deprecated (the exact warnings
9 | # depend on your compiler). Please consult the documentation of the
10 | # deprecated API in order to know how to port your code away from it.
11 | DEFINES += QT_DEPRECATED_WARNINGS
12 |
13 | # You can also make your code fail to compile if it uses deprecated APIs.
14 | # In order to do so, uncomment the following line.
15 | # You can also select to disable deprecated APIs only up to a certain version of Qt.
16 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
17 |
18 | SOURCES += \
19 | main.cpp \
20 | mainwindow.cpp
21 |
22 | HEADERS += \
23 | mainwindow.h
24 |
25 | FORMS += \
26 | mainwindow.ui
27 |
28 | # Default rules for deployment.
29 | qnx: target.path = /tmp/$${TARGET}/bin
30 | else: unix:!android: target.path = /opt/$${TARGET}/bin
31 | !isEmpty(target.path): INSTALLS += target
32 |
33 | win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../../Learn_Open_Source/QScintilla-2.11.4/QScintilla-2.11.4/build-qscintilla-Desktop_Qt_5_14_1_MinGW_32_bit-Debug/ -lqscintilla2_qt5
34 | else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../../Learn_Open_Source/QScintilla-2.11.4/QScintilla-2.11.4/build-qscintilla-Desktop_Qt_5_14_1_MinGW_32_bit-Debug/ -lqscintilla2_qt5d
35 |
36 | INCLUDEPATH += $$PWD/../../../../Learn_Open_Source/QScintilla-2.11.4/QScintilla-2.11.4/Qt4Qt5
37 | DEPENDPATH += $$PWD/../../../../Learn_Open_Source/QScintilla-2.11.4/QScintilla-2.11.4/Qt4Qt5
38 |
--------------------------------------------------------------------------------
/3main_1codeeditor/main.cpp:
--------------------------------------------------------------------------------
1 | #include "mainwindow.h"
2 |
3 | #include
4 |
5 | int main(int argc, char *argv[])
6 | {
7 | QApplication a(argc, argv);
8 | MainWindow w;
9 | w.show();
10 | return a.exec();
11 | }
12 |
--------------------------------------------------------------------------------
/3main_1codeeditor/mainwindow.cpp:
--------------------------------------------------------------------------------
1 | #include "mainwindow.h"
2 | #include "ui_mainwindow.h"
3 |
4 | #include "Qsci/qsciscintilla.h"
5 | #include "Qsci/qscilexercss.h"
6 | #include "Qsci/qsciapis.h"
7 |
8 | MainWindow::MainWindow(QWidget *parent)
9 | : QMainWindow(parent)
10 | , ui(new Ui::MainWindow)
11 | {
12 | ui->setupUi(this);
13 |
14 |
15 |
16 |
17 | //qsciscintilla.h文件还定义了各参数枚举
18 | //编辑器类
19 | QsciScintilla *editor=new QsciScintilla(this);
20 |
21 | //设置语法
22 | QsciLexerCSS *textLexer=new QsciLexerCSS;//创建一个词法分析器
23 | editor->setLexer(textLexer); //给QsciScintilla设置词法分析器
24 | textLexer->setPaper(QColor(33,37,50));//文本区域背景色
25 | textLexer->setColor(QColor(0,170,0),QsciLexerCSS::Comment); //设置自带的注释行为灰色
26 | textLexer->setColor(QColor(Qt::yellow),QsciLexerCSS::Tag);//标签
27 | textLexer->setColor(QColor(Qt::yellow),QsciLexerCSS::IDSelector);//id选择器
28 |
29 | //代码提示
30 | QsciAPIs *apis=new QsciAPIs(textLexer);
31 | apis->add(QString("gongjianbo1"));
32 | apis->add(QString("Gong"));
33 | apis->prepare();
34 |
35 | //行号提示
36 | editor->SendScintilla(QsciScintilla::SCI_SETCODEPAGE,QsciScintilla::SC_CP_UTF8);//设置编码为UTF-8
37 | QFont line_font;
38 | line_font.setFamily("Consolas");
39 | line_font.setPointSize(16);
40 | editor->setFont(line_font);//设置文本字体
41 | editor->setWrapMode(QsciScintilla::WrapWord); //文本自动换行模式
42 | //editor->setWrapVisualFlags(QsciScintilla::WrapFlagByText);
43 |
44 | editor->setEolMode(QsciScintilla::EolWindows); //微软风格换行符
45 | //editor->setEolVisibility(true);//显示换行符
46 |
47 | editor->setWhitespaceVisibility(QsciScintilla::WsInvisible);//此时空格不显示
48 | editor->setWhitespaceSize(4);//空格点大小
49 |
50 | //indent
51 | editor->setIndentationsUseTabs(false);//false用表示用空格代替\t
52 | editor->setTabWidth(8);//\t宽度设为8个空格
53 | editor->setIndentationGuides(true);//用tab键缩进时,在缩进位置上显示一个竖点线,缩进有效,在字符串后加空格不显示
54 | editor->setIndentationWidth(0);//如果在行首部空格位置tab,缩进的宽度字符数,并且不会转换为空格
55 | editor->setAutoIndent(true);//换行后自动缩进
56 | editor->setBackspaceUnindents(true);
57 | editor->setTabIndents(true);//True如果行前空格数少于tabWidth,补齐空格数,False如果在文字前tab同true,如果在行首tab,则直接增加tabwidth个空格
58 | editor->setBraceMatching(QsciScintilla::SloppyBraceMatch);//括号匹配
59 |
60 | //current line color
61 | editor->setCaretWidth(2);//光标宽度,0表示不显示光标
62 | editor->setCaretForegroundColor(QColor("darkCyan")); //光标颜色
63 | editor->setCaretLineVisible(true); //是否高亮显示光标所在行
64 | editor->setCaretLineBackgroundColor(QColor(41,47,68));//光标所在行背景颜色
65 |
66 | //selection color
67 | editor->setSelectionBackgroundColor(Qt::black);//选中文本背景色
68 | editor->setSelectionForegroundColor(Qt::white);//选中文本前景色
69 |
70 | //edge
71 | //editor->setEdgeColumn(50); //edge宽度,没发现有啥用
72 | //editor->setEdgeMode(QsciScintilla::EdgeLine);
73 | //editor->setEdgeColor(QColor("green"));
74 |
75 | QFont margin_font;
76 | margin_font.setFamily("Consolas");
77 | margin_font.setPointSize(16);//边栏字体设置px我这里显示不出行号,不知道是怎么回事
78 | editor->setMarginsFont(margin_font);//设置页边字体
79 | editor->setMarginType(0,QsciScintilla::NumberMargin);//设置标号为0的页边显示行号
80 | //editor->setMarginMarkerMask(0,QsciScintilla::Background);//页边掩码
81 | //editor->setMarginSensitivity(0,true);//注册通知事件,当用户点击边栏时,scintilla会通知我们
82 | editor->setMarginLineNumbers(0,true);//设置第0个边栏为行号边栏,True表示显示
83 | editor->setMarginWidth(0,15);//设置0边栏宽度
84 | editor->setMarginsBackgroundColor(Qt::gray);
85 | editor->setMarginsForegroundColor(Qt::white);
86 |
87 | editor->setFolding(QsciScintilla::BoxedTreeFoldStyle);//折叠样式
88 | editor->setFoldMarginColors(Qt::gray,Qt::lightGray);//折叠栏颜色
89 |
90 | //auto complete
91 | //Acs[None|All|Document|APIs]
92 | //禁用自动补全提示功能|所有可用的资源|当前文档中出现的名称都自动补全提示|使用QsciAPIs类加入的名称都自动补全提示
93 | editor->setAutoCompletionSource(QsciScintilla::AcsAll);//自动补全。对于所有Ascii字符
94 | //editor->setAutoCompletionCaseSensitivity(false);//大小写敏感度,设置lexer可能会更改,不过貌似没啥效果
95 | editor->setAutoCompletionThreshold(1);//设置每输入一个字符就会出现自动补全的提示
96 | //editor->setAutoCompletionReplaceWord(false);//是否用补全的字符串替代光标右边的字符串
97 |
98 | setCentralWidget(editor);
99 |
100 |
101 | }
102 |
103 | MainWindow::~MainWindow()
104 | {
105 | delete ui;
106 | }
107 |
108 |
--------------------------------------------------------------------------------
/3main_1codeeditor/mainwindow.h:
--------------------------------------------------------------------------------
1 | #ifndef MAINWINDOW_H
2 | #define MAINWINDOW_H
3 |
4 | #include
5 |
6 | QT_BEGIN_NAMESPACE
7 | namespace Ui { class MainWindow; }
8 | QT_END_NAMESPACE
9 |
10 | class MainWindow : public QMainWindow
11 | {
12 | Q_OBJECT
13 |
14 | public:
15 | MainWindow(QWidget *parent = nullptr);
16 | ~MainWindow();
17 |
18 | private:
19 | Ui::MainWindow *ui;
20 | };
21 | #endif // MAINWINDOW_H
22 |
--------------------------------------------------------------------------------
/3main_1codeeditor/mainwindow.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | MainWindow
4 |
5 |
6 |
7 | 0
8 | 0
9 | 800
10 | 600
11 |
12 |
13 |
14 | MainWindow
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/4CCompilerUI/CCompilerUI.pro:
--------------------------------------------------------------------------------
1 | QT += core gui
2 |
3 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
4 |
5 | CONFIG += c++11
6 |
7 | # The following define makes your compiler emit warnings if you use
8 | # any Qt feature that has been marked deprecated (the exact warnings
9 | # depend on your compiler). Please consult the documentation of the
10 | # deprecated API in order to know how to port your code away from it.
11 | DEFINES += QT_DEPRECATED_WARNINGS
12 |
13 | # You can also make your code fail to compile if it uses deprecated APIs.
14 | # In order to do so, uncomment the following line.
15 | # You can also select to disable deprecated APIs only up to a certain version of Qt.
16 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
17 |
18 | SOURCES += \
19 | main.cpp \
20 | mainwindow.cpp
21 |
22 | HEADERS += \
23 | mainwindow.h
24 |
25 | FORMS += \
26 | mainwindow.ui
27 |
28 | # Default rules for deployment.
29 | qnx: target.path = /tmp/$${TARGET}/bin
30 | else: unix:!android: target.path = /opt/$${TARGET}/bin
31 | !isEmpty(target.path): INSTALLS += target
32 |
33 | RESOURCES += \
34 | res.qrc
35 |
36 | win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../../Learn_Open_Source/QScintilla-2.11.4/QScintilla-2.11.4/build-qscintilla-Desktop_Qt_5_14_1_MinGW_32_bit-Debug/ -lqscintilla2_qt5
37 | else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../../Learn_Open_Source/QScintilla-2.11.4/QScintilla-2.11.4/build-qscintilla-Desktop_Qt_5_14_1_MinGW_32_bit-Debug/ -lqscintilla2_qt5d
38 |
39 | INCLUDEPATH += $$PWD/../../../../Learn_Open_Source/QScintilla-2.11.4/QScintilla-2.11.4/build-qscintilla-Desktop_Qt_5_14_1_MinGW_32_bit-Debug
40 | DEPENDPATH += $$PWD/../../../../Learn_Open_Source/QScintilla-2.11.4/QScintilla-2.11.4/build-qscintilla-Desktop_Qt_5_14_1_MinGW_32_bit-Debug
41 |
--------------------------------------------------------------------------------
/4CCompilerUI/img/app_1title_dark_appicon1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MarkCens/Qt-Learning-Demo/5a7b6ab2216bbacb350825c635d6f3c3928dc311/4CCompilerUI/img/app_1title_dark_appicon1.png
--------------------------------------------------------------------------------
/4CCompilerUI/img/app_round_button_black.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MarkCens/Qt-Learning-Demo/5a7b6ab2216bbacb350825c635d6f3c3928dc311/4CCompilerUI/img/app_round_button_black.9.png
--------------------------------------------------------------------------------
/4CCompilerUI/img/app_round_button_darkblue.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MarkCens/Qt-Learning-Demo/5a7b6ab2216bbacb350825c635d6f3c3928dc311/4CCompilerUI/img/app_round_button_darkblue.9.png
--------------------------------------------------------------------------------
/4CCompilerUI/img/app_round_button_gray.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MarkCens/Qt-Learning-Demo/5a7b6ab2216bbacb350825c635d6f3c3928dc311/4CCompilerUI/img/app_round_button_gray.9.png
--------------------------------------------------------------------------------
/4CCompilerUI/img/app_round_button_green.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MarkCens/Qt-Learning-Demo/5a7b6ab2216bbacb350825c635d6f3c3928dc311/4CCompilerUI/img/app_round_button_green.9.png
--------------------------------------------------------------------------------
/4CCompilerUI/img/app_round_button_transparent.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MarkCens/Qt-Learning-Demo/5a7b6ab2216bbacb350825c635d6f3c3928dc311/4CCompilerUI/img/app_round_button_transparent.9.png
--------------------------------------------------------------------------------
/4CCompilerUI/img/app_round_button_white.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MarkCens/Qt-Learning-Demo/5a7b6ab2216bbacb350825c635d6f3c3928dc311/4CCompilerUI/img/app_round_button_white.9.png
--------------------------------------------------------------------------------
/4CCompilerUI/img/app_up.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MarkCens/Qt-Learning-Demo/5a7b6ab2216bbacb350825c635d6f3c3928dc311/4CCompilerUI/img/app_up.png
--------------------------------------------------------------------------------
/4CCompilerUI/img/app_up_down.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MarkCens/Qt-Learning-Demo/5a7b6ab2216bbacb350825c635d6f3c3928dc311/4CCompilerUI/img/app_up_down.png
--------------------------------------------------------------------------------
/4CCompilerUI/img/app_up_down_hover.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MarkCens/Qt-Learning-Demo/5a7b6ab2216bbacb350825c635d6f3c3928dc311/4CCompilerUI/img/app_up_down_hover.png
--------------------------------------------------------------------------------
/4CCompilerUI/img/app_up_hover.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MarkCens/Qt-Learning-Demo/5a7b6ab2216bbacb350825c635d6f3c3928dc311/4CCompilerUI/img/app_up_hover.png
--------------------------------------------------------------------------------
/4CCompilerUI/main.cpp:
--------------------------------------------------------------------------------
1 | #include "mainwindow.h"
2 |
3 | #include
4 |
5 | int main(int argc, char *argv[])
6 | {
7 | QApplication a(argc, argv);
8 | MainWindow w;
9 | w.show();
10 | return a.exec();
11 | }
12 |
--------------------------------------------------------------------------------
/4CCompilerUI/mainwindow.cpp:
--------------------------------------------------------------------------------
1 | #include "mainwindow.h"
2 | #include "ui_mainwindow.h"
3 |
4 | MainWindow::MainWindow(QWidget *parent): QMainWindow(parent), ui(new Ui::MainWindow)
5 | {
6 | ui->setupUi(this);
7 |
8 | loadWindowUI();//加载、设置主窗口控件
9 |
10 | }
11 |
12 | MainWindow::~MainWindow()
13 | {
14 | delete ui;
15 | }
16 |
17 | void MainWindow::loadWindowUI()
18 | {
19 | loadTitlebar();//加载设置标题栏窗口控件
20 | loadMenubar();//加载设置菜单栏窗口控件
21 | loadMainPanel();//加载设置主面板编辑器控件
22 | loadResultbar();//加载设置编译输出结果控件
23 | loadStatusbar();//加载设置状态栏控件
24 | }
25 |
26 | void MainWindow::loadTitlebar()
27 | {
28 | this->setWindowIcon(QIcon(":/img/app_1title_dark_appicon1.png"));
29 | this->setWindowTitle("C语言编译器");
30 | }
31 |
32 |
33 | void MainWindow::loadMenubar()
34 | {
35 | //文件菜单项
36 | QList file_menu_list;
37 | QAction *file_menu_item_new = new QAction("新建 Ctrl+N");
38 | QAction *file_menu_item_open = new QAction("打开 Ctrl+O");
39 | QAction *file_menu_item_save = new QAction("保存 Ctrl+S");
40 | QAction *file_menu_item_close = new QAction("关闭 Ctrl+X");
41 | file_menu_list.append(file_menu_item_new);
42 | file_menu_list.append(file_menu_item_open);
43 | file_menu_list.append(file_menu_item_save);
44 | file_menu_list.append(file_menu_item_close);
45 | QMenu *file_menu = new QMenu;
46 | file_menu->setStyleSheet("QMenu{background-color:rgb(33,37,50);}\
47 | QMenu::item{font-size: 10pt;font-family: '微软雅黑';color: rgb(234,234,234);background-color:rgb(33,37,50);padding:8px 8px;margin:2px 2px;}\
48 | QMenu::item:selected{background-color: rgb(234,234,234);color: rgb(33,37,50);}\
49 | QMenu::item:pressed{border: 1px solid rgb(33,37,50);background-color: rgb(234,234,234);}");
50 | file_menu->addActions(file_menu_list);
51 | ui->main_menu_bt_1file->setMenu(file_menu);
52 |
53 | //编辑菜单项
54 | QList edit_menu_list;
55 | QAction *edit_menu_item_format = new QAction("格式化 Alt+Shift+F");
56 | QAction *edit_menu_item_copy = new QAction("复制 Ctrl+C");
57 | QAction *edit_menu_item_delete = new QAction("删除 Ctrl+D");
58 | QAction *edit_menu_item_paste = new QAction("粘贴 Ctrl+V");
59 | QAction *edit_menu_item_undo = new QAction("撤销 Ctrl+Z");
60 | QAction *edit_menu_item_redo = new QAction("重做 Ctrl+Y");
61 | edit_menu_list.append(edit_menu_item_format);
62 | edit_menu_list.append(edit_menu_item_copy);
63 | edit_menu_list.append(edit_menu_item_delete);
64 | edit_menu_list.append(edit_menu_item_paste);
65 | edit_menu_list.append(edit_menu_item_undo);
66 | edit_menu_list.append(edit_menu_item_redo);
67 | QMenu *edit_menu = new QMenu;
68 | edit_menu->setStyleSheet("QMenu{background-color:rgb(33,37,50);}\
69 | QMenu::item{font-size: 10pt;font-family: '微软雅黑';color: rgb(234,234,234);background-color:rgb(33,37,50);padding:8px 8px;margin:2px 2px;}\
70 | QMenu::item:selected{background-color: rgb(234,234,234);color: rgb(33,37,50);}\
71 | QMenu::item:pressed{border: 1px solid rgb(33,37,50);background-color: rgb(234,234,234);}");
72 | edit_menu->addActions(edit_menu_list);
73 | ui->main_menu_bt_2edit->setMenu(edit_menu);
74 |
75 | //编辑菜单项
76 | QList theme_menu_list;
77 | QAction *theme_menu_item_light = new QAction("亮色 Alt+Shift+L");
78 | QAction *theme_menu_item_dark = new QAction("夜色 Alt+Shift+D");
79 | theme_menu_list.append(theme_menu_item_light);
80 | theme_menu_list.append(theme_menu_item_dark);
81 | QMenu *theme_menu = new QMenu;
82 | theme_menu->setStyleSheet("QMenu{background-color:rgb(33,37,50);}\
83 | QMenu::item{font-size: 10pt;font-family: '微软雅黑';color: rgb(234,234,234);background-color:rgb(33,37,50);padding:8px 8px;margin:2px 2px;}\
84 | QMenu::item:selected{background-color: rgb(234,234,234);color: rgb(33,37,50);}\
85 | QMenu::item:pressed{border: 1px solid rgb(33,37,50);background-color: rgb(234,234,234);}");
86 | theme_menu->addActions(theme_menu_list);
87 | ui->main_menu_bt_4theme->setMenu(theme_menu);
88 |
89 | //单步分析菜单项
90 | QList bystep_menu_list;
91 | QAction *bystep_menu_item_la = new QAction("词法分析");
92 | QAction *bystep_menu_item_ga = new QAction("语法分析");
93 | QAction *bystep_menu_item_sa = new QAction("语义分析");
94 | QAction *bystep_menu_item_icg = new QAction("中间代码生成");
95 | QAction *bystep_menu_item_ico = new QAction("中间代码优化");
96 | QAction *bystep_menu_item_ocg = new QAction("目标代码生成");
97 | bystep_menu_list.append(bystep_menu_item_la);
98 | bystep_menu_list.append(bystep_menu_item_ga);
99 | bystep_menu_list.append(bystep_menu_item_sa);
100 | bystep_menu_list.append(bystep_menu_item_icg);
101 | bystep_menu_list.append(bystep_menu_item_ico);
102 | bystep_menu_list.append(bystep_menu_item_ocg);
103 | QMenu *bystep_menu = new QMenu;
104 | bystep_menu->setStyleSheet("QMenu{background-color:rgb(33,37,50);}\
105 | QMenu::item{font-size: 10pt;font-family: '微软雅黑';color: rgb(234,234,234);background-color:rgb(33,37,50);padding:8px 8px;margin:2px 2px;}\
106 | QMenu::item:selected{background-color: rgb(234,234,234);color: rgb(33,37,50);}\
107 | QMenu::item:pressed{border: 1px solid rgb(33,37,50);background-color: rgb(234,234,234);}");
108 | bystep_menu->addActions(bystep_menu_list);
109 | ui->main_menu_bt_6bystep->setMenu(bystep_menu);
110 | }
111 |
112 | void MainWindow::loadMainPanel()
113 | {
114 | //编辑器类
115 | main_editor= new QsciScintilla();
116 | main_editor->SendScintilla(QsciScintilla::SCI_SETCODEPAGE,QsciScintilla::SC_CP_UTF8);//设置编码为UTF-8
117 |
118 |
119 | //代码字体字体
120 | QFont code_font;
121 | code_font.setFamily("Consolas");
122 | code_font.setPointSize(16);//边栏字体大小
123 |
124 | //设置语法、语法高亮
125 | QsciLexerCPP *textLexer=new QsciLexerCPP;//创建一个C++词法分析器
126 | main_editor->setLexer(textLexer); //给QsciScintilla设置词法分析器
127 | textLexer->setPaper(QColor(33,37,50));//文本区域背景色
128 | textLexer->setFont(code_font);//设置代码字体大小
129 | textLexer->setDollarsAllowed(false);//设置不允许使用'$'符号
130 | textLexer->setFoldComments(true);//设置可以折叠多行注释
131 | textLexer->setColor(QColor(234, 234, 234), -1);//所有样式置为前景主题色
132 | textLexer->setColor(QColor(234, 234, 234), QsciLexerCPP::Default);//默认
133 | textLexer->setColor(QColor(255, 255, 255), QsciLexerCPP::Comment);//多行注释
134 | textLexer->setColor(QColor(30, 144, 255), QsciLexerCPP::CommentLine);//单行注释
135 | textLexer->setColor(QColor(234, 234, 234), QsciLexerCPP::CommentDoc);
136 | textLexer->setColor(QColor(255, 0, 255), QsciLexerCPP::Number);
137 | textLexer->setColor(QColor(255, 255, 0), QsciLexerCPP::Keyword);//关键词
138 | textLexer->setColor(QColor(255, 215, 0), QsciLexerCPP::DoubleQuotedString);//两次引用
139 | textLexer->setColor(QColor(255, 165, 0), QsciLexerCPP::SingleQuotedString);//单次引用
140 | textLexer->setColor(QColor(0, 255, 255), QsciLexerCPP::UUID);//唯一识别码
141 | textLexer->setColor(QColor(255, 0, 255), QsciLexerCPP::PreProcessor);//预处理头
142 | textLexer->setColor(QColor(234, 234, 234), QsciLexerCPP::Operator);//算符
143 | textLexer->setColor(QColor( 0, 250, 154), QsciLexerCPP::Identifier);//标识符
144 | textLexer->setColor(QColor(220, 20, 60), QsciLexerCPP::UnclosedString);//未封闭字符串
145 | textLexer->setColor(QColor(255, 255, 255), QsciLexerCPP::VerbatimString);//转义字符
146 | textLexer->setColor(QColor(30, 144, 255), QsciLexerCPP::RawString);//生字符串
147 | textLexer->setColor(QColor(255, 255, 255), QsciLexerCPP::CommentLineDoc);//单行注释文档
148 |
149 | //设置行号边栏
150 | QFont margin_font;
151 | margin_font.setFamily("Consolas");
152 | margin_font.setPointSize(12);//边栏字体大小
153 | main_editor->setMarginsFont(margin_font);//设置边栏字体
154 | main_editor->setMarginType(0,QsciScintilla::NumberMargin);//设置标号为0的边栏显示行号
155 | main_editor->setMarginLineNumbers(0,true);//设置第0个边栏为行号边栏,True表示显示
156 | main_editor->setMarginWidth(0,45);//设置0边栏宽度,经测试可以显示99999个行号(字体大小:12)
157 | main_editor->setMarginsForegroundColor(QColor(234, 234, 234));//边栏字体颜色
158 | main_editor->setMarginsBackgroundColor(QColor(33, 37, 50));//边栏字体背景
159 | main_editor->setFolding(QsciScintilla::PlainFoldStyle);//折叠样式
160 | main_editor->setFoldMarginColors(QColor(33, 37, 50),QColor(33, 37, 50));//折叠栏颜色
161 |
162 | //当前行设置
163 | main_editor->setCaretWidth(2);//光标宽度,0表示不显示光标
164 | main_editor->setCaretForegroundColor(QColor(234, 234, 234)); //光标颜色
165 | main_editor->setCaretLineVisible(true); //是否高亮显示光标所在行
166 | main_editor->setCaretLineBackgroundColor(QColor(41,47,68));//光标所在行背景颜色
167 |
168 | //选中部分设置
169 | main_editor->setSelectionBackgroundColor(QColor(234, 234, 234));//选中文本背景色
170 | main_editor->setSelectionForegroundColor(QColor(41,47,68));//选中文本前景色
171 |
172 | //缩进设置
173 | main_editor->setIndentationsUseTabs(false);//false表示用空格代替\t
174 | main_editor->setTabWidth(4);//缩进宽度设为8个空格
175 | main_editor->setIndentationGuides(true);//用tab键缩进时,在缩进位置上显示一个竖点线,缩进有效,在字符串后加空格不显示
176 | main_editor->setIndentationWidth(0);//如果在行首部空格位置tab,缩进的宽度字符数,并且不会转换为空格
177 | main_editor->setAutoIndent(true);//换行后自动缩进
178 | main_editor->setBackspaceUnindents(true);//删除缩进,直接删除这个缩进宽度,而不是空格
179 | main_editor->setTabIndents(true);//True如果行前空格数少于tabWidth,补齐空格数,False如果在文字前tab同true,如果在行首tab,则直接增加tabwidth个空格
180 | main_editor->setBraceMatching(QsciScintilla::SloppyBraceMatch);//括号匹配
181 |
182 | //设置空格
183 | main_editor->setWhitespaceVisibility(QsciScintilla::WsInvisible);
184 | main_editor->setWhitespaceSize(4);//空格点大小
185 |
186 | //代码提示静态集合
187 | QsciAPIs *apis=new QsciAPIs(textLexer);
188 | apis->add(QString("break"));
189 | apis->add(QString("case"));
190 | apis->add(QString("char"));
191 | apis->add(QString("continue"));
192 | apis->add(QString("default"));
193 | apis->add(QString("do"));
194 | apis->add(QString("else"));
195 | apis->add(QString("for"));
196 | apis->add(QString("if"));
197 | apis->add(QString("int"));
198 | apis->add(QString("long"));
199 | apis->add(QString("return"));
200 | apis->add(QString("short"));
201 | apis->add(QString("signed"));
202 | apis->add(QString("sizeof"));
203 | apis->add(QString("static"));
204 | apis->add(QString("struct"));
205 | apis->add(QString("switch"));
206 | apis->add(QString("typedef"));
207 | apis->add(QString("unsigned"));
208 | apis->add(QString("void"));
209 | apis->add(QString("while"));
210 | apis->add(QString("define"));
211 | apis->add(QString("#include"));
212 | apis->add(QString("main"));
213 | apis->prepare();
214 |
215 | //代码补全
216 | main_editor->setAutoCompletionSource(QsciScintilla::AcsAll);//自动补全
217 | main_editor->setAutoCompletionThreshold(1);//设置每输入1个字符就会出现自动补全的提示
218 |
219 | //换行设置
220 | main_editor->setWrapMode(QsciScintilla::WrapWord); //文本自动换行模式
221 | main_editor->setEolMode(QsciScintilla::EolWindows); //Windows操作系统风格换行符
222 |
223 | //滚动条设置
224 | main_editor->setScrollWidth(1);
225 | main_editor->setScrollWidthTracking(true);
226 | main_editor->verticalScrollBar()->setStyleSheet(
227 | "QScrollBar:vertical{width:8px;background:rgba(0,0,0,0%);margin:0px,0px,0px,0px;padding-top:9px;padding-bottom:9px;}"
228 | "QScrollBar::handle:vertical{width:8px;background:rgba(0,0,0,25%);border-radius:4px;min-height:20;}"
229 | "QScrollBar::handle:vertical:hover{width:8px;background:rgba(0,0,0,50%);border-radius:4px;min-height:20;}"
230 | "QScrollBar::add-line:vertical{height:9px;width:8px;subcontrol-position:bottom;}"
231 | "QScrollBar::sub-line:vertical{height:9px;width:8px;subcontrol-position:top;}"
232 | "QScrollBar::add-line:vertical:hover{height:9px;width:8px;subcontrol-position:bottom;}"
233 | "QScrollBar::sub-line:vertical:hover{height:9px;width:8px;subcontrol-position:top;}"
234 | "QScrollBar::add-page:vertical,QScrollBar::sub-page:vertical{background:rgba(0,0,0,10%);border-radius:4px;}");
235 | main_editor->horizontalScrollBar()->setStyleSheet(
236 | "QScrollBar:horizontal{width:8px;background:rgba(0,0,0,0%);margin:0px,0px,0px,0px;padding-top:9px;padding-bottom:9px;}"
237 | "QScrollBar::handle:horizontal{width:8px;background:rgba(0,0,0,25%);border-radius:4px;min-height:20;}"
238 | "QScrollBar::handle:horizontal:hover{width:8px;background:rgba(0,0,0,50%);border-radius:4px;min-height:20;}"
239 | "QScrollBar::add-line:horizontal{height:9px;width:8px;subcontrol-position:bottom;}"
240 | "QScrollBar::sub-line:horizontal{height:9px;width:8px;subcontrol-position:top;}"
241 | "QScrollBar::add-line:horizontal:hover{height:9px;width:8px;subcontrol-position:bottom;}"
242 | "QScrollBar::sub-line:horizontal:hover{height:9px;width:8px;subcontrol-position:top;}"
243 | "QScrollBar::add-page:horizontal,QScrollBar::sub-page:horizontal{background:rgba(0,0,0,10%);border-radius:4px;}");
244 |
245 |
246 | //把编辑器类添加到布局中去
247 | main_editor->setParent(ui->main_wg_main);
248 | ui->main_vl_main->addWidget(main_editor);
249 | ui->main_wg_main->setLayout(ui->main_vl_main);
250 | }
251 |
252 | void MainWindow::loadResultbar()
253 | {
254 |
255 | }
256 |
257 | void MainWindow::loadStatusbar()
258 | {
259 |
260 | }
261 |
262 |
263 |
264 |
265 |
--------------------------------------------------------------------------------
/4CCompilerUI/mainwindow.h:
--------------------------------------------------------------------------------
1 | #ifndef MAINWINDOW_H
2 | #define MAINWINDOW_H
3 | //Qt库头文件
4 | #include
5 | #include
6 | #include
7 | #include
8 |
9 | //qsciscintilla编辑器库头文件
10 | #include "Qsci/qsciscintilla.h"
11 | #include "Qsci/qscilexercpp.h"
12 | #include "Qsci/qsciapis.h"
13 |
14 | QT_BEGIN_NAMESPACE
15 | namespace Ui { class MainWindow; }
16 | QT_END_NAMESPACE
17 |
18 | class MainWindow : public QMainWindow
19 | {
20 | Q_OBJECT
21 |
22 | public:
23 | MainWindow(QWidget *parent = nullptr);
24 | ~MainWindow();
25 |
26 | private:
27 | Ui::MainWindow *ui;
28 |
29 | //声明加载窗口UI函数
30 | void loadWindowUI();
31 | void loadTitlebar();
32 | void loadMenubar();
33 | void loadMainPanel();
34 | void loadResultbar();
35 | void loadStatusbar();
36 |
37 | //声明全局变量
38 |
39 | QsciScintilla *main_editor; //编辑器类
40 |
41 | };
42 | #endif // MAINWINDOW_H
43 |
--------------------------------------------------------------------------------
/4CCompilerUI/res.qrc:
--------------------------------------------------------------------------------
1 |
2 |
3 | img/app_round_button_black.9.png
4 | img/app_round_button_darkblue.9.png
5 | img/app_round_button_gray.9.png
6 | img/app_round_button_green.9.png
7 | img/app_round_button_white.9.png
8 | img/app_up.png
9 | img/app_up_down.png
10 | img/app_round_button_transparent.9.png
11 | img/app_1title_dark_appicon1.png
12 | img/app_up_down_hover.png
13 | img/app_up_hover.png
14 |
15 |
16 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # **Qt学习文档**
2 |
3 | 那么,在该GitHub项目中,每一个目录都将会对应一个Qt项目,这些Qt项目的意义在于使用Qt的控件,并且还是关于开发自定义编辑器方面的。核心的Demo效果如下:
4 |
5 | QTableWidget,多行多列控件。
6 |
7 | 
8 |
9 |
10 |
11 | BinaryTree,二叉树绘制(有点ugly)。
12 |
13 | 
14 |
15 |
16 |
17 | Button,自定义按钮。
18 |
19 | 
20 |
21 |
22 |
23 | Dialog,模态框。
24 |
25 | 
26 |
27 |
28 |
29 | Layout,Qt布局。
30 |
31 | 
32 |
33 |
34 |
35 | ButtonMenu,按钮菜单。
36 |
37 | 
38 |
39 |
40 |
41 | CodeEditor,好看的、有语法高亮的编辑器界面。
42 |
43 | 
44 |
45 |
46 |
47 | ## 一、标题栏
48 |
49 | ### 1、修改标题
50 |
51 | 方式一如下:
52 |
53 | 
54 |
55 | 方式二如下:
56 |
57 | 
58 |
59 |
60 |
61 | ### 2、修改图标
62 |
63 | 1、创建qrc文件。
64 |
65 | 
66 |
67 | 然后在该项目目录之下新建一个资源文件夹,命名自定义,这个文件夹 便可以存放一些图片资源,这样项目在使用的时候可以使用相对路径,如果这些图片资源放在其他盘使用的则是绝对路径。比如,"res"。新建完后如下:
68 |
69 | 
70 |
71 | 对刚刚添加的qrc文件添加“现有文件”。添加完后项目如下:
72 |
73 | 
74 |
75 | 接下来在主窗口添加代码设置窗口图标:
76 |
77 | 
78 |
79 | 修改完窗口图标和标题之后的效果如下:
80 |
81 | 
82 |
83 |
84 |
85 | ## 二、菜单栏
86 |
87 | ### 1、信号和槽(事件处理)
88 |
89 | 原理如下:
90 |
91 | 
92 |
93 | demo:点击一个按钮,让另外一个按钮的文本发生变化。
94 |
95 | 
96 |
97 | 
98 |
99 | MainWindow代码(记得在MainWindow头文件声明相关的成员)如下:
100 |
101 | ```c++
102 | #include "mainwindow.h"
103 | #include "ui_mainwindow.h"
104 | #include
105 |
106 | MainWindow::MainWindow(QWidget *parent): QMainWindow(parent), ui(new Ui::MainWindow){
107 | ui->setupUi(this);
108 |
109 | QPushButton* bt_one = new QPushButton;
110 | bt_one->setParent(this);
111 | bt_one->setFixedWidth(200);
112 | bt_one->setFixedHeight(30);
113 | bt_one->setText("点我让另一个按钮变成傻子");
114 |
115 | bt_another = new QPushButton;
116 | bt_another->setParent(this);
117 | bt_another->move(250,0);
118 | bt_another->setFixedWidth(150);
119 | bt_another->setFixedHeight(30);
120 | bt_another->setText("我不是傻子");
121 |
122 | //信号实际上是发送者对象的一个方法
123 | //槽实际上也是接收者对象的一个方法
124 | connect(bt_one, &QPushButton::clicked, this, &MainWindow::change);
125 | }
126 |
127 | //槽处理的事件
128 | void MainWindow::change(){
129 | bt_another->setText("我是傻子");
130 | }
131 |
132 | MainWindow::~MainWindow(){
133 | delete ui;
134 | }
135 | ```
136 |
137 | ### 2、自定义按钮、文本样式
138 |
139 | 比较常用的方法是使用styleSheet的方式。使用如下(在代码中设置):
140 |
141 | ```c++
142 | #include "mainwindow.h"
143 | #include "ui_mainwindow.h"
144 |
145 | MainWindow::MainWindow(QWidget *parent): QMainWindow(parent), ui(new Ui::MainWindow){
146 | ui->setupUi(this);
147 |
148 | ui->main_menu_bt_analyse->setStyleSheet(
149 | "QPushButton{font-family:'微软雅黑'}"/*设置字体*/
150 | "QPushButton{color:rgb(234,234,234)}"/*设置字体颜色*/
151 | "QPushButton{border-image: url(:/img/app_round_button_darkblue.9.png);}"/*设置按钮背景*/
152 | "QPushButton:hover{border-image: url(:/img/app_round_button_green.9.png);}"/*设置鼠标滑过按钮背景*/
153 | "QPushButton:pressed{border-image: url(:/img/app_round_button_darkblue.9.png);}");/*设置鼠标点击按钮背景*/
154 | }
155 |
156 | MainWindow::~MainWindow(){
157 | delete ui;
158 | }
159 | ```
160 |
161 | 除了在代码中设置,也可以在Qt Designer中点击控件的styleSheet属性,其中资源一般是图片。并对其添加相关的样式。如下:
162 |
163 | 
164 |
165 | 
166 |
167 | ### 3、按钮菜单
168 |
169 | 具体代码如下:
170 |
171 | ```c++
172 | //文件菜单项
173 | QList file_menu_list;
174 | QAction *file_menu_item_new = new QAction("新建 Ctrl+N");
175 | QAction *file_menu_item_open = new QAction("打开 Ctrl+O");
176 | QAction *file_menu_item_save = new QAction("保存 Ctrl+S");
177 | QAction *file_menu_item_close = new QAction("关闭 Ctrl+X");
178 | file_menu_list.append(file_menu_item_new);
179 | file_menu_list.append(file_menu_item_open);
180 | file_menu_list.append(file_menu_item_save);
181 | file_menu_list.append(file_menu_item_close);
182 | QMenu *file_menu = new QMenu;
183 | file_menu->setStyleSheet("QMenu{background-color:rgb(33,37,50);}\
184 | QMenu::item{font-size: 10pt;font-family: '微软雅黑';color: rgb(234,234,234);background-color:rgb(33,37,50);padding:8px 8px;margin:2px 2px;}\
185 | QMenu::item:selected{background-color: rgb(234,234,234);color: rgb(33,37,50);}\
186 | QMenu::item:pressed{border: 1px solid rgb(33,37,50);background-color: rgb(234,234,234);}");
187 | file_menu->addActions(file_menu_list);
188 | ui->main_menu_bt_1file->setMenu(file_menu);
189 | ```
190 |
191 |
192 |
193 | ### 4、Qt界面布局
194 |
195 | 1) Qt布局一般都使用水平布局和垂直布局。
196 |
197 | 2) 使用自底向上的方法为控件添加布局。选中控件、右键添加布局即可。
198 |
199 | 3) 每一个Widget都需要制定布局,这样才能使布局(或者里面的控件)最大化,也就是随着窗口自适应。而Widget指定布局的位置如下图:
200 |
201 | 
202 |
203 |
204 |
205 |
206 |
207 |
208 |
209 | ## 三、主界面
210 |
211 | ### 1、CodeEditor
212 |
213 | 使用请参考文章:https://blog.csdn.net/gongjianbo1992/article/details/100828180。
214 |
215 | 美化请参考文章:https://www.bbsmax.com/A/MAzAXq0od9/。
216 |
217 |
218 |
219 |
220 |
221 | ## 四、状态栏
222 |
223 | ### 1、滑入滑出窗口
224 |
225 | 对Widget控件调用其的show()和hide()即可。
226 |
227 |
228 |
229 | ## 五、其他常用控件
230 |
231 | ### 1、QTableWidget
232 |
233 | 数据项(也就是item)的行数(rowCount)是需要自己更新的,当添加了一行,同时也需要setRowCount(当前count+1),删除了一行也是如此。
234 |
235 | 关于QTableWidget的一些样式如下:
236 |
237 | ```c++
238 | //设置样式
239 | //设置表格样式
240 | ui->main_tw->setStyleSheet(
241 | "color:rgb(234,234,234);"
242 | "gridline-color:rgb(41,47,68);" /*表格中的网格线条颜色*/
243 | "background:rgb(41,47,68);"
244 | /*"alternate-background-color:gray;" *//*设置交替颜色*/
245 | "selection-color:rgb(234,234,234);"
246 | "selection-background-color:rgb(33,37,50);"
247 | "border:none;");
248 |
249 | //设置表头样式
250 | ui->main_tw->horizontalHeader()->setStyleSheet(
251 | "QHeaderView::section{background:rgb(33,37,50); padding:4px; border:0px solid rgb(41,47,68); color:rgb(234,234,234);}"
252 | "QHeaderView::section:checked{background-color:rgb(41,47,68); color:rgb(234,234,234);}");
253 | ui->main_tw->horizontalHeader()->setSectionResizeMode(QHeaderView::Interactive);
254 | ui->main_tw->horizontalHeader()->setStretchLastSection(true);//最后一列伸缩铺满
255 | ui->main_tw->setFocusPolicy(Qt::NoFocus);
256 | ui->main_tw->verticalScrollBar()->setStyleSheet(
257 | "QScrollBar:vertical{width:8px;background:rgba(0,0,0,0%);margin:0px,0px,0px,0px;padding-top:9px;padding-bottom:9px;}"
258 | "QScrollBar::handle:vertical{width:8px;background:rgba(0,0,0,25%);border-radius:4px;min-height:20;}"
259 | "QScrollBar::handle:vertical:hover{width:8px;background:rgba(0,0,0,50%);border-radius:4px;min-height:20;}"
260 | "QScrollBar::add-line:vertical{height:9px;width:8px;subcontrol-position:bottom;}"
261 | "QScrollBar::sub-line:vertical{height:9px;width:8px;subcontrol-position:top;}"
262 | "QScrollBar::add-line:vertical:hover{height:9px;width:8px;subcontrol-position:bottom;}"
263 | "QScrollBar::sub-line:vertical:hover{height:9px;width:8px;subcontrol-position:top;}"
264 | "QScrollBar::add-page:vertical,QScrollBar::sub-page:vertical{background:rgba(0,0,0,10%);border-radius:4px;}");
265 | ```
266 |
267 |
268 |
269 | ### 2、MessageBox
270 |
271 | ```c++
272 | QMessageBox* msgBox = new QMessageBox;
273 | msgBox->setWindowFlags(Qt::Widget | Qt::FramelessWindowHint | Qt::WindowSystemMenuHint | Qt::WindowStaysOnTopHint);
274 | msgBox->setText("确实要删除吗?");
275 | msgBox->setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
276 | msgBox->setDefaultButton(QMessageBox::Ok);
277 | //设置QMessageBox的样式
278 | msgBox->setStyleSheet("QPushButton{background-color:rgb(255, 85, 0);color: rgb(85, 255, 0);}"
279 | "QMessageBox{background-color:white}");
280 | int ret = msgBox->exec();
281 | if(ret == QMessageBox::Ok){
282 | ui->main_tw->removeRow(ui->main_tw->currentRow());
283 | ui->main_tw->setRowCount(count-1);
284 | }
285 | delete msgBox;
286 | ```
287 |
288 |
289 |
290 |
291 |
292 |
293 |
294 |
295 |
296 |
297 |
298 |
299 |
300 |
301 |
302 |
303 |
304 |
305 |
306 |
307 |
308 |
309 |
310 |
311 |
312 |
313 |
314 |
315 |
316 |
317 |
318 |
319 |
320 |
321 |
322 |
323 |
324 |
325 |
326 |
327 |
328 |
329 |
330 |
331 |
332 |
333 |
334 |
335 |
336 |
337 |
338 |
339 |
340 |
341 |
342 |
343 |
344 |
345 |
346 |
347 |
348 |
349 |
350 |
351 |
352 |
353 |
354 |
355 |
356 |
357 |
358 |
359 |
360 |
361 |
362 |
363 |
364 |
365 |
366 |
367 |
368 |
369 |
370 |
371 |
372 |
373 |
374 |
375 |
376 |
377 |
378 |
379 |
380 |
381 |
382 |
383 |
384 |
385 |
386 |
387 |
388 |
389 |
390 |
391 |
392 |
393 |
394 |
395 |
396 |
397 |
398 |
399 |
400 |
401 |
402 |
403 |
404 |
405 |
406 |
407 |
408 |
409 |
410 |
411 |
412 |
413 |
414 |
415 |
416 |
417 |
418 |
419 |
420 |
421 |
422 |
423 |
424 |
425 |
426 |
427 |
428 |
429 |
430 |
431 |
432 |
433 |
434 |
435 |
436 |
437 |
438 |
439 |
440 |
441 |
442 |
443 |
444 |
445 |
446 |
447 |
448 |
449 |
450 |
451 |
452 |
453 |
454 |
455 |
456 |
457 |
458 |
459 |
460 |
461 |
462 |
463 |
464 |
465 |
466 |
467 |
468 |
469 |
470 |
471 |
472 |
473 |
474 |
475 |
476 |
477 |
478 |
479 |
480 |
481 |
482 |
483 |
484 |
485 |
486 |
487 |
488 |
489 |
490 |
491 |
492 |
493 |
494 |
495 |
496 |
497 |
498 |
499 |
500 |
501 |
502 |
503 |
504 |
505 |
506 |
507 |
508 |
509 |
510 |
511 |
512 |
513 |
514 |
515 |
516 |
517 |
518 |
519 |
520 |
521 |
522 |
523 |
524 |
525 |
526 |
527 |
528 |
529 |
530 |
531 |
532 |
533 |
534 |
535 |
536 |
537 |
538 |
539 |
540 |
541 |
542 |
543 |
544 |
545 |
546 |
547 |
548 |
549 |
550 |
551 |
552 |
553 |
554 |
555 |
556 |
557 |
558 |
559 |
560 |
561 |
562 |
563 |
564 |
565 |
566 |
567 |
568 |
569 |
570 |
571 |
572 |
573 |
574 |
575 |
576 |
577 |
578 |
579 |
580 |
581 |
582 |
583 |
584 |
585 |
586 |
587 |
588 |
589 |
590 |
591 |
592 |
593 |
594 |
595 |
596 |
597 |
598 |
599 |
600 |
601 |
602 |
603 |
604 |
605 |
606 |
607 |
608 |
609 |
610 |
611 |
612 |
613 |
614 |
615 |
616 |
617 |
618 |
619 |
620 |
--------------------------------------------------------------------------------