Skip to content

Commit 027c02a

Browse files
committed
增加 其他控件 Combo Box, Qlabel 显示图片等
1 parent 52e43c2 commit 027c02a

29 files changed

+303
-4
lines changed

014_Control_Other/014_Control_Other.pro

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,6 @@ FORMS += \
2222
qnx: target.path = /tmp/$${TARGET}/bin
2323
else: unix:!android: target.path = /opt/$${TARGET}/bin
2424
!isEmpty(target.path): INSTALLS += target
25+
26+
RESOURCES += \
27+
res.qrc

014_Control_Other/nekosilverfox.png

53.7 KB
Loading

014_Control_Other/res.qrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<RCC>
2+
<qresource prefix="/pic">
3+
<file>舔屏.gif</file>
4+
<file>nekosilverfox.png</file>
5+
</qresource>
6+
</RCC>

014_Control_Other/widget.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
#include "widget.h"
22
#include "ui_widget.h"
3+
#include <QMovie>
34

45
Widget::Widget(QWidget *parent)
56
: QWidget(parent)
67
, ui(new Ui::Widget)
78
{
89
ui->setupUi(this);
910

11+
/* @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ Stacked Widget @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ */
1012
// 点击按钮 Stacked Widget 切换页
1113
connect(ui->btnScrollArea, &QPushButton::clicked,
1214
this, [=](){ui->stackedWidget->setCurrentIndex(0);}); // Scroll Area
@@ -20,6 +22,37 @@ Widget::Widget(QWidget *parent)
2022
// 设置默认选中第 0 项
2123
ui->stackedWidget->setCurrentIndex(0);
2224

25+
26+
/* @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ Combo Box - 下拉框 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ */
27+
ui->comboBox->addItem("狐狸"); // 添加值
28+
ui->comboBox->addItem("狗子");
29+
ui->comboBox->addItem("猫子");
30+
31+
// connect(ui->btnSelectCat, &QPushButton::clicked,
32+
// this, [=](){ui->comboBox->setCurrentIndex(2);}); // 通过按钮选择
33+
34+
connect(ui->btnSelectCat, &QPushButton::clicked,
35+
this, [=](){ui->comboBox->setCurrentText("猫子");}); // 通过按钮选择
36+
37+
38+
/* @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ Dial - 滚轮 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ */
39+
ui->dial->setMaximum(0); // 设置最小最大值
40+
ui->dial->setMaximum(365);
41+
connect(ui->dial, &QDial::valueChanged,
42+
this, [=](int value){ qDebug() << "Dial value: " << value;}); // 如果指针位置变化就输出数值
43+
44+
/* @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ Label - 显示图片 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ */
45+
ui->labelPic->setPixmap(QPixmap(":/pic/nekosilverfox.png")); // 显示图片
46+
ui->labelPic->setScaledContents(true); // 设置自动缩放到可用空间
47+
48+
// 显示动图
49+
QMovie* movie = new QMovie(":/pic/舔屏.gif");
50+
ui->labelGif->setMovie(movie);
51+
ui->labelGif->setScaledContents(true);
52+
movie->start(); // 播放
53+
54+
55+
2356
}
2457

2558
Widget::~Widget()

014_Control_Other/widget.ui

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,155 @@
244244
</item>
245245
</layout>
246246
</widget>
247+
<widget class="QComboBox" name="comboBox">
248+
<property name="geometry">
249+
<rect>
250+
<x>440</x>
251+
<y>30</y>
252+
<width>103</width>
253+
<height>32</height>
254+
</rect>
255+
</property>
256+
</widget>
257+
<widget class="QPushButton" name="btnSelectCat">
258+
<property name="geometry">
259+
<rect>
260+
<x>570</x>
261+
<y>30</y>
262+
<width>100</width>
263+
<height>32</height>
264+
</rect>
265+
</property>
266+
<property name="text">
267+
<string>选中猫</string>
268+
</property>
269+
</widget>
270+
<widget class="QFontComboBox" name="fontComboBox">
271+
<property name="geometry">
272+
<rect>
273+
<x>440</x>
274+
<y>100</y>
275+
<width>284</width>
276+
<height>32</height>
277+
</rect>
278+
</property>
279+
</widget>
280+
<widget class="QLineEdit" name="lineEdit">
281+
<property name="geometry">
282+
<rect>
283+
<x>440</x>
284+
<y>170</y>
285+
<width>271</width>
286+
<height>21</height>
287+
</rect>
288+
</property>
289+
<property name="echoMode">
290+
<enum>QLineEdit::PasswordEchoOnEdit</enum>
291+
</property>
292+
</widget>
293+
<widget class="QTextEdit" name="textEdit">
294+
<property name="geometry">
295+
<rect>
296+
<x>30</x>
297+
<y>240</y>
298+
<width>104</width>
299+
<height>74</height>
300+
</rect>
301+
</property>
302+
</widget>
303+
<widget class="QPlainTextEdit" name="plainTextEdit">
304+
<property name="geometry">
305+
<rect>
306+
<x>150</x>
307+
<y>240</y>
308+
<width>104</width>
309+
<height>74</height>
310+
</rect>
311+
</property>
312+
</widget>
313+
<widget class="QSpinBox" name="spinBox">
314+
<property name="geometry">
315+
<rect>
316+
<x>310</x>
317+
<y>240</y>
318+
<width>42</width>
319+
<height>22</height>
320+
</rect>
321+
</property>
322+
</widget>
323+
<widget class="QDoubleSpinBox" name="doubleSpinBox">
324+
<property name="geometry">
325+
<rect>
326+
<x>290</x>
327+
<y>280</y>
328+
<width>62</width>
329+
<height>22</height>
330+
</rect>
331+
</property>
332+
</widget>
333+
<widget class="QGroupBox" name="groupBox">
334+
<property name="geometry">
335+
<rect>
336+
<x>410</x>
337+
<y>220</y>
338+
<width>156</width>
339+
<height>132</height>
340+
</rect>
341+
</property>
342+
<property name="title">
343+
<string>(Date/Time) Edit</string>
344+
</property>
345+
<layout class="QVBoxLayout" name="verticalLayout_2">
346+
<item>
347+
<widget class="QTimeEdit" name="timeEdit"/>
348+
</item>
349+
<item>
350+
<widget class="QDateEdit" name="dateEdit"/>
351+
</item>
352+
<item>
353+
<widget class="QDateTimeEdit" name="dateTimeEdit"/>
354+
</item>
355+
</layout>
356+
</widget>
357+
<widget class="QDial" name="dial">
358+
<property name="geometry">
359+
<rect>
360+
<x>620</x>
361+
<y>240</y>
362+
<width>121</width>
363+
<height>91</height>
364+
</rect>
365+
</property>
366+
<property name="orientation">
367+
<enum>Qt::Horizontal</enum>
368+
</property>
369+
</widget>
370+
<widget class="QLabel" name="labelPic">
371+
<property name="geometry">
372+
<rect>
373+
<x>50</x>
374+
<y>370</y>
375+
<width>161</width>
376+
<height>151</height>
377+
</rect>
378+
</property>
379+
<property name="text">
380+
<string>TextLabel</string>
381+
</property>
382+
</widget>
383+
<widget class="QLabel" name="labelGif">
384+
<property name="geometry">
385+
<rect>
386+
<x>270</x>
387+
<y>370</y>
388+
<width>171</width>
389+
<height>161</height>
390+
</rect>
391+
</property>
392+
<property name="text">
393+
<string>TextLabel</string>
394+
</property>
395+
</widget>
247396
</widget>
248397
<resources/>
249398
<connections/>

014_Control_Other/舔屏.gif

81.3 KB
Loading

README.md

Lines changed: 112 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,9 @@ MainWindow::MainWindow(QWidget *parent)
515515

516516
## 铆接部件
517517

518-
铆接部件 `QDockWidget`,也称浮动窗口,可以有==多个==。
518+
![image-20221203144419409](doc/pic/README/image-20221203144419409.png)
519+
520+
铆接部件 `QDockWidget`,也称==浮动窗口==,可以有==多个==。
519521

520522
**注意:铆接部件的位置是相对于核心部件的!围绕着核心部件的,而不是相对于整个窗口!**
521523

@@ -1150,7 +1152,7 @@ connect(ui->actionOpenFile, &QAction::triggered,
11501152

11511153
![image-20221203140110110](doc/pic/README/image-20221203140110110.png)
11521154

1153-
## Tool Box
1155+
### Tool Box
11541156

11551157
![image-20221203140151611](doc/pic/README/image-20221203140151611.png)
11561158

@@ -1162,7 +1164,7 @@ connect(ui->actionOpenFile, &QAction::triggered,
11621164

11631165

11641166

1165-
## Tab Widget
1167+
### Tab Widget
11661168

11671169
类似于浏览器的多==标签==页
11681170

@@ -1190,7 +1192,7 @@ connect(ui->actionOpenFile, &QAction::triggered,
11901192

11911193

11921194

1193-
**通过小箭头切换栈容器,如果页不够用就添加一个。**但是注意,==这个小箭头只是辅助我们设计的,程序运行起来之后,并不会显示,所以我们可以通过自定义按钮,通过 `currentStack` 切换栈==
1195+
**通过小箭头切换栈容器,如果页不够用就添加一个。**但是注意,==这个小箭头只是辅助我们设计的,程序运行起来之后,并不会显示,所以我们可以通过自定义按钮,通过 `stackedWidget->setCurrentIndex(索引)` 切换栈==
11941196

11951197
![image-20221203142009053](doc/pic/README/image-20221203142009053.png)
11961198

@@ -1204,9 +1206,115 @@ connect(ui->actionOpenFile, &QAction::triggered,
12041206

12051207

12061208

1209+
### Combo Box
1210+
1211+
![image-20221203144554453](doc/pic/README/image-20221203144554453.png)
1212+
1213+
**下拉框**,可以通过代码添加值:
1214+
1215+
可以通过代码选择当前选中的内容:
1216+
1217+
- 通过索引:`comboBox->setCurrentIndex(索引);`
1218+
- 通过下拉框中的文字内容:`comboBox->setCurrentText("猫子");`
1219+
1220+
1221+
1222+
**效果及代码:**
1223+
1224+
![image-20221203145348848](doc/pic/README/image-20221203145348848.png)
1225+
1226+
1227+
1228+
### Font Combo Box
1229+
1230+
![image-20221203145456249](doc/pic/README/image-20221203145456249.png)
1231+
1232+
**选择字体**
1233+
1234+
![image-20221203145525829](doc/pic/README/image-20221203145525829.png)
1235+
1236+
1237+
1238+
### Line Edit
1239+
1240+
![image-20221203145609404](doc/pic/README/image-20221203145609404.png)
1241+
1242+
**单行编辑框**
1243+
1244+
**可以对输入的内容做不同的输入模式:**
1245+
1246+
![image-20221203145713706](doc/pic/README/image-20221203145713706.png)
1247+
1248+
- `Normal`,可以正常输入文字内容 ![image-20221203145826876](doc/pic/README/image-20221203145826876.png)
1249+
- `NoEcho`,输入内容但是不显示类似于 Linux 下输入密码的效果 ![image-20221203145938500](doc/pic/README/image-20221203145938500.png)
1250+
- `Password`,会变成小黑圆点 ![image-20221203145956363](doc/pic/README/image-20221203145956363.png)
1251+
- `PasswordEchoOnEdit`**失去焦点时**才会变成小黑圆点 ![image-20221203150006693](doc/pic/README/image-20221203150006693.png)
1252+
1253+
1254+
1255+
### (Plain) Text Edit
1256+
1257+
![image-20221203150113188](doc/pic/README/image-20221203150113188.png)
1258+
1259+
**区别:**
1260+
1261+
- `Text Edit` 输入内部的文字**可带有格式**,比如颜色、大小、加粗...
1262+
- `Plain Text Edit` 只能输入**纯文本**
1263+
12071264

12081265

1266+
### (Double) Spin Box
12091267

1268+
点击箭头可以加减,带有 Double 的是可以输入双精度的
12101269

1270+
![image-20221203150537882](doc/pic/README/image-20221203150537882.png)
12111271

12121272

1273+
1274+
![image-20221203150611547](doc/pic/README/image-20221203150611547.png)
1275+
1276+
1277+
1278+
### (Date/Time) Edit
1279+
1280+
![image-20221203150856557](doc/pic/README/image-20221203150856557.png)
1281+
1282+
- `Time Edit`:选择时间
1283+
- `Date Edit`:选择日期
1284+
- `Date/Time Edit`:时间加日期
1285+
1286+
![image-20221203150842960](doc/pic/README/image-20221203150842960.png)
1287+
1288+
### Dial
1289+
1290+
![image-20221203155115323](doc/pic/README/image-20221203155115323.png)
1291+
1292+
**滚轮**
1293+
1294+
**效果及代码:**
1295+
1296+
![image-20221203155956762](doc/pic/README/image-20221203155956762.png)
1297+
1298+
1299+
1300+
**更改样式:**
1301+
1302+
![image-20221203155432229](doc/pic/README/image-20221203155432229.png)
1303+
1304+
1305+
1306+
### 滚动条
1307+
1308+
![image-20221203161108507](doc/pic/README/image-20221203161108507.png)
1309+
1310+
1311+
1312+
1313+
1314+
### Label
1315+
1316+
Label 不仅可以显示文字,还可以显示`图片(QPixMap)``动图(QMovie)`
1317+
1318+
**效果及代码:**
1319+
1320+
![image-20221203162325641](doc/pic/README/image-20221203162325641.png)
3.99 KB
Loading
3.74 KB
Loading
168 KB
Loading
4.42 KB
Loading
62 KB
Loading
2.93 KB
Loading
2.93 KB
Loading
23.8 KB
Loading
3.64 KB
Loading
1.8 KB
Loading
2.15 KB
Loading
2.15 KB
Loading
5.89 KB
Loading
5.75 KB
Loading
5.38 KB
Loading
11.9 KB
Loading
9.61 KB
Loading
3 KB
Loading
73.2 KB
Loading
229 KB
Loading
11.7 KB
Loading
238 KB
Loading

0 commit comments

Comments
 (0)