Qt5-控件-QRadioButton-单选按钮-用于从多个选项中选取一个-单选神器
2024-10-13 09:58:12
#ifndef MAINWINDOW_H
#define MAINWINDOW_H #include <QMainWindow>
#include <QRadioButton>
#include <QButtonGroup> class MainWindow : public QMainWindow
{
Q_OBJECT public:
MainWindow(QWidget *parent = );
~MainWindow(); QRadioButton* radio0[];
QRadioButton* radio1[]; QButtonGroup* group[];
}; #endif // MAINWINDOW_H
#include "mainwindow.h" MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
this->resize(,);
this->centralWidget(); QString str0[] = {"笔记本","电话","打印机"};
QString str1[] = {"萝卜","白菜","青椒"}; group[] = new QButtonGroup(this);
group[] = new QButtonGroup(this); int xpos = , ypos = ;
for(int i=;i<;i++)
{
radio0[i] = new QRadioButton(str0[i],this);
group[]->addButton(radio0[i]);
radio0[i]->setGeometry(xpos,ypos,,); radio1[i] = new QRadioButton(str1[i],this);
group[]->addButton(radio1[i]);
radio1[i]->setGeometry(xpos+,ypos,,); ypos += ;
}
} MainWindow::~MainWindow()
{ }
#include "mainwindow.h"
#include <QApplication> int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show(); return a.exec();
}
最新文章
- Linux运维工程师入门须掌握的10个技术点
- 20145218 《Java程序设计》第四周学习总结
- YAR 并行RPC框架研究
- NOSQL Mongo入门学习笔记 - MongoDB的安装(一)
- bzoj 3158 千钧一发(最小割)
- Cocos2d-x 学习(1)—— 通过Cocos Studio创建第一个Demo
- 黑马程序猿——java基金会--jdk、变量
- C语言库函数大全及应用实例十一
- (中等) CF 585B Phillip and Trains,BFS。
- scanf函数之扫描集
- C++11 标准新特性: 右值引用与转移语义
- nodejs之socket.io模块——实现了websocket协议
- Dynamics CRM2013 任务列表添加自定义按钮
- Mybatis 源码学习系列
- Web应用程序架构的比较
- vue中用ajax上传文件
- Custom partition assignment and migration kafka集群扩充迁移指定partition
- 利用Python制作简单的小程序:IP查看器
- ROS Qt Creator Plug-in wiki
- Windows 安装 docker 以及1709的简单使用