QCheckbox的用法

时间:2023-02-16 19:03:52

QCheckBox继承自QAbstractButton,它提供了一个带文本标签的复选框

void stateChanged(int state);

当复选框状态发生改变,这个信号就会被发射。即:用户选中或者取消选中

QCheckbox的用法

实现两个复选框只能选择其一的代码实现

connect(checkBox_hex_send,&QCheckBox::stateChanged,this,
&MainWindow::on_checkbox_hex_send_statechanged);
connect(checkBox_ascll_send,&QCheckBox::stateChanged,this,
&MainWindow::on_checkbox_ascll_send_statechanged);

void MainWindow::on_checkbox_hex_send_statechanged(int arg1)
{
if(arg1 == Qt::CheckState::Checked)
{
checkBox_ascll_send->blockSignals(true);
checkBox_ascll_send->setCheckState(Qt::CheckState::Unchecked);
checkBox_ascll_send->blockSignals(false);
}
}
void MainWindow::on_checkbox_ascll_send_statechanged(int arg1)
{
if(arg1 == Qt::CheckState::Checked)
{
checkBox_hex_send->blockSignals(true);
checkBox_hex_send->setCheckState(Qt::CheckState::Unchecked);
checkBox_hex_send->blockSignals(false);
}
}

QCheckbox的用法

QCheckbox的用法

两个checkBox只能选择一个,互斥。