一、概述
案例:使用Qt的QButtonGroup和QRadioButton做一个简单的选中、未选中的样例(服务于视频背景消除中的一个小案例)
ps:基于Qt6.2.3,主要是记录一下,防止后面忘记回看
二、代码示例
QPushButton *choiceVideo = new QPushButton(this); choiceVideo->setText("选择视频"); connect(choiceVideo,&QPushButton::clicked,[=](){ path = QFileDialog::getOpenFileName(this, tr("选择视频"), ".", tr("video Files(*.mp4 *.avi)")); const char *fileRealPath = filePath.toStdString().c_str(); qDebug()<< ":图片路径路径:"<<fileRealPath; }); //创建一组Group QButtonGroup *btnGroup = new QButtonGroup(this); QRadioButton *btn1 = new QRadioButton(this); btn1->setText("MOG背景消除"); btn1->move(0,choiceVideo->y()+choiceVideo->height()+20); QRadioButton *btn2 = new QRadioButton(this); btn2->move(btn1->x()+btn1->width()+20,choiceVideo->y()+choiceVideo->height()+20); btn2->setText("其他背景消除"); btnGroup->addButton(btn1); btnGroup->setId(btn1,0); btnGroup->addButton(btn2); btnGroup->setId(btn2,1); connect(btn1,&QRadioButton::clicked,[=](bool flag){ qDebug()<<"测试RadioButton的Id:"<<btn1->text(); if(path.isEmpty()){ QMessageBox::warning(this,"警告","视频路径不能为空"); }else{ showMogBackgroundRemove(path.toStdString().c_str()); } }); connect(btn2,&QRadioButton::clicked,[=](bool flag){ qDebug()<<"测试RadioButton的Id:"<<btn2->text(); });
三、演示图像
原创文章,作者:254126420,如若转载,请注明出处:https://blog.ytso.com/245471.html