网站首页 > 博客文章 正文
1、用法一:
一般用到控件comboBox的基本用法是获取当前的值:
1.currentIndex(); 获取当前comBox的索引,是int类型的值。
2.currentText(); 获取当前comBox的文本,是QString类型。
2、用法二:
可以通过以下两种方式来通过切换comobox的值来执行一些指令:
1、通过首先在界面上拖入控件comobox,然后就是直接通过将comobox中的输入“Chinese”和“English”
1 void MainWindow::on_comboBox_currentIndexChanged(const QString &arg1)
2 {
3 // if(ui->comboBox->currentText()=="Chinese")
4 // {
5 // qDebug()<<"优秀";
6 // }
7
8 // else if (ui->comboBox->currentText()== "English")
9 // {
10 // qDebug()<<"good";
11 // }
12 //或者是这样
13 if(ui->comboBox->currentIndex() == 0)
14 {
15 qDebug()<<"优秀";
16 }
17 else if(ui->comboBox->currentIndex()==1)
18 {
19 qDebug()<<"good";
20 }
21
22 }
在构造函数中进行绑定:
connect(ui->comboBox,SIGNAL(currentTextChanged(QString)),this,SLOT(SetValue(QString)));
【领QT开发教程学习资料,点击下方链接莬费领取↓↓,先码住不迷路~】
点击→领取「链接」
执行槽函数:
1 void MainWindow::SetValue(QString)
2 {
3 if(ui->comboBox->currentText()== "Chinese")
4 {
5 qDebug()<<"111";
6
7 }
8 else if(ui->comboBox->currentText()=="English")
9 {
10 qDebug()<<"222";
11 }
12
13 }
3、用法三:
就是当comobox里面的值发生了改变之后,自动识别并打印出来里面的值,如下代码:
在.h文件中:
void on_comboBox_currentIndexChanged(const QString &arg1);
在.cpp文件中如下:
1 void MainWindow::on_comboBox_currentIndexChanged(const QString &arg1)
2 {
3 QString str =ui->comboBox->currentText();
4 qDebug()<<"str:"<<str;
5
6 }
猜你喜欢
- 2024-10-24 Qt Examples——QSlider(qt qcompleter)
- 2024-10-24 正点原子I.MX6U嵌入式Qt开发指南:第七章《Qt控件 2》
- 2024-10-24 销售订单管理,Excel表格模板演示
- 2024-10-24 抓大放小,瞅瞅 Qt 的几个基础模块
- 2024-10-24 WPF --- 如何重写WPF原生控件样式?
- 2024-10-24 Python入坑系列-pyside6桌面编程之border边框
- 2024-10-24 1.3 MyFirstWidget代码讲解及实用编程技巧分享
- 2024-10-24 C#知识|.Net控件二次封装之ComboBox下拉框
- 2024-10-24 在WPF 中想要在表格的同一列上显示多个表头
- 2024-10-24 Qt模型视图结构_代理(犀牛缩放视图后看不见模型了)
你 发表评论:
欢迎- 最近发表
- 标签列表
-
- powershellfor (55)
- messagesource (56)
- aspose.pdf破解版 (56)
- promise.race (63)
- 2019cad序列号和密钥激活码 (62)
- window.performance (66)
- qt删除文件夹 (72)
- mysqlcaching_sha2_password (64)
- ubuntu升级gcc (58)
- nacos启动失败 (64)
- ssh-add (70)
- jwt漏洞 (58)
- macos14下载 (58)
- yarnnode (62)
- abstractqueuedsynchronizer (64)
- source~/.bashrc没有那个文件或目录 (65)
- springboot整合activiti工作流 (70)
- jmeter插件下载 (61)
- 抓包分析 (60)
- idea创建mavenweb项目 (65)
- vue回到顶部 (57)
- qcombobox样式表 (68)
- vue数组concat (56)
- tomcatundertow (58)
- pastemac (61)
本文暂时没有评论,来添加一个吧(●'◡'●)