当前位置:网站首页>Use of RadioButton in QT
Use of RadioButton in QT
2022-06-11 11:52:00 【Sensh】
Qt in radioButton Use
First in ui Drag several on the interface radioButton Control , Pictured ( Add a Group Box):
Go straight to the code :
//mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QAbstractButton>
//QAbstractButton Class is an abstract base class for button parts , Provides functions that are common to buttons .
//QAbstractButton Provides click and tick buttons .QRadioButton and QCheckBox Class only provides tick buttons
#include <QButtonGroup> //
QT_BEGIN_NAMESPACE
namespace Ui {
class MainWindow; }
QT_END_NAMESPACE
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = nullptr);
~MainWindow();
QButtonGroup *btnGroup; // add to buttongroup
public slots:
void onButtonClicked(QAbstractButton *button);
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
//mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
//radioButton
btnGroup= new QButtonGroup(this);
btnGroup->addButton(ui->radioBtnV1);
btnGroup->addButton(ui->radioBtnV2);
btnGroup->addButton(ui->radioBtnV3);
btnGroup->addButton(ui->radioBtnV4);
btnGroup->setId(ui->radioBtnV1,0);
btnGroup->setId(ui->radioBtnV2,1);
btnGroup->setId(ui->radioBtnV3,2);
btnGroup->setId(ui->radioBtnV4,3);
ui->radioBtnV1->setChecked(1); // The first... Is selected by default
//ButtonGroup Signal link
connect(btnGroup, SIGNAL(buttonClicked(QAbstractButton*)), this, SLOT(onButtonClicked(QAbstractButton*))); // Signal output selection
}
void MainWindow::onButtonClicked(QAbstractButton *button) //radio button choice
{
Q_UNUSED(button)
int sigChoose = btnGroup->checkedId(); // Select signal
if(sigChoose==0) qDebug() << sigChoose;
else if(sigChoose==1) qDebug() << sigChoose;
else if(sigChoose==2) qDebug() << sigChoose;
else if(sigChoose==3) qDebug() << sigChoose;
}
MainWindow::~MainWindow()
{
delete ui;
}
边栏推荐
- Golang uses XOR ^ to exchange two variables and encrypt / decrypt them
- 2020-07 study notes sorting
- WordPress站内链接修改插件:Velvet Blues Update URLs
- 中级web开发工程师,面试题+笔记+项目实战
- 灵动边栏(Widget)插件:MO Widgets
- WordPress user name modification plug-in: username changer
- Etcd introduction
- Études à la fin de l'enseignement 03
- PS does not display text cursor, text box, and does not highlight after selection
- Count the top k strings with the most occurrences
猜你喜欢
随机推荐
解决swagger文档接口404的问题
Full Permutation (recursion, backtracking)
Guice integrated properties configuration
灵动边栏(Widget)插件:MO Widgets
MYCAT sub database and sub table
NFT digital collection system platform construction
Weekly Postgres world news 2022w08
C# 将OFD转为PDF
JS 加法乘法错误解决 number-precision
Smart sidebar plug-in: Mo widgets
为WordPress相关日志插件增加自动缩略图功能
WordPress站内链接修改插件:Velvet Blues Update URLs
NFT digital collection app system construction
2020-07 学习笔记整理
PS does not display text cursor, text box, and does not highlight after selection
Pan domain SSL certificate, sectigo cheap wildcard certificate popularization plan
[C language] anonymous/unnamed struct & Union
在畢設中學習03
普通人应当如何挑选年金险产品?
广东市政安全施工资料管理软件2022新表格来啦









