Qt基础 07_单选框、复选框及实例
来源:互联网 发布:java 写一句话木马 编辑:程序博客网 时间:2024/06/06 03:04
/******************************************************
* 课程名 :QT编程
* 时 间 :2017年6月5日(周一)下午前半段
* 工程名 :09-checkBox
* 类 名 :dialog09
* 内 容 :单选框、复选框
* CSDN :Qt基础 07_单选框、复选框及实例
******************************************************/
目标:建立单选框、复选框,并将用户的选择显示在窗口中
一、绘制ui界面
通过拖拽GroupBox、CheckBox、RadioButton、Label等部件,完成如下界面:
GroupBox的名称变为:hoobbyBox和cityBox
CheckBox的名称变为:runCheckBox、swimCheckBox和ballCheckBox
RadioButton的名称变为:jxRadioButton、jsRadioButton和zjRadioButton
label的名称变为:hoobbylabel和citylabel
二、使用户点击的复选框呈现在窗口中
步骤一:在dialog09.h中定义槽函数:
private slots: void showHobbyToLabel( );
在dialog09.cpp中实现
void Dialog09::showToLabel( ){ QString str = ""; if(ui->runCheckBox->isChecked()) { str += ui->runCheckBox->text() + " "; } if(ui->swimCheckBox->isChecked()) { str += ui->swimCheckBox->text() + " "; } if(ui->ballCheckBox->isChecked()) { str += ui->ballCheckBox->text() + " "; } //显示 ui->hoobbylabel->setText(str);}
步骤二:在构造函数中连接
Dialog09::Dialog09(QWidget *parent) : QDialog(parent), ui(new Ui::Dialog09){ ui->setupUi(this); connect(ui->runCheckBox,SIGNAL(stateChanged(int)),this,SLOT(showHobbyToLabel())); connect(ui->swimCheckBox,SIGNAL(clicked()),this,SLOT(showHobbyToLabel())); connect(ui->ballCheckBox,SIGNAL(clicked()),this,SLOT(showHobbyToLabel()));}
三、使用户点击的单选框呈现在窗口中
步骤一:在dialog09.h中定义槽函数:
private slots: void showCityToLabel( );
在dialog09.cpp中实现
void Dialog09::showCityToLabel(){ QString str = ""; if(ui->jxRadioButton->isChecked()) { str += ui->jxRadioButton->text() + " "; } if(ui->jsRadioButton->isChecked()) { str += ui->jsRadioButton->text() + " "; } if(ui->zjRadioButton->isChecked()) { str += ui->zjRadioButton->text() + " "; } //显示 ui->citylabel->setText(str);}
步骤二:在构造函数中连接:
//初始化子部件 ui->zjRadioButton->setChecked(true); //代码——使"浙江"变为默认 //连接。单选框 connect(ui->jxRadioButton,SIGNAL(stateChanged(int)),this,SLOT(showCityToLabel())); connect(ui->jsRadioButton,SIGNAL(clicked()),this,SLOT(showCityToLabel())); connect(ui->zjRadioButton,SIGNAL(clicked()),this,SLOT(showCityToLabel()));
完成。
源代码:http://download.csdn.net/download/c_estbon/9865381
阅读全文
0 0
- Qt基础 07_单选框、复选框及实例
- easyui单选框及复选框
- Qt入门-单选框和复选框
- Qt treewidget 复选框
- QT复选框使用
- Html之input类型_复选框等_p换行_实例
- 【QT】:QT中的单选框和复选框的使用
- servlet表单处理使用GET()方法实例 及复选框
- jquery复选框实例
- [Cocoa]_[NSTableView]_[添加复选框]
- JSP基础实例_列表框交互_学习笔记
- 复选框 CheckBox 的实例
- servlet_07 servlet复选框实例
- 实例2:设置复选框
- Qt基础 06_信号和槽(二)自定义信号和槽的实例
- 复选框及回显
- Qt 页面布局+TreeWidget插入复选框
- Qt 中 QComboBox 嵌入复选框
- 树的重心
- 过去10年来,SEO技术有多大变化?
- java中数据结构时间复杂度
- 数据库事务
- 500. Keyboard Row
- Qt基础 07_单选框、复选框及实例
- ffmpeg在window下编译32位
- jQuery ajax
- 分布式消息kafka
- ASP.NET MVC IOC 之AutoFac攻略
- 如何更改vue项目运行的端口号
- java获取当前路径的几种方法
- 阿里云centos服务器基本构建(服务器的探索之路)
- Retrofit