3

组框内的单选底部将被视为一组底部。它们是互斥的。我怎样才能清理他们的检查状态?

我有几个收音机底部,其中一个是检查过的。我怎样才能“清理”(取消选中)所有收音机底部?“setChecked”在组内不起作用,我尝试做以下事情但失败了。

我的代码如下,radioButtom 在 groupBox 内,我想取消选中它。第一个 setChecked 确实有效,但第二个无效,radioBottom 没有被取消选中

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    QRadioButton *radioButton;
    ui->setupUi(this);
    radioButton->setChecked(true);
    radioButton->setChecked(false);
}

我的代码中的问题在哪里?

4

2 回答 2

4

诀窍是autoExclusive在取消选中之前禁用该属性,然后重新启用它。

ui->radioButton->setChecked(true);
ui->radioButton->setAutoExclusive(false);
ui->radioButton->setChecked(false);
ui->radioButton->setAutoExclusive(true);

在此之后,radioButton 未选中。

于 2010-05-12T06:46:49.460 回答
1

在 Qt 文档中说:QRadioButton 是一个选项按钮,可以打开(选中)或关闭(未选中)。单选按钮通常为用户提供“多选一”的选择。在一组单选按钮中,一次只能检查一个单选按钮;如果用户选择另一个按钮,则先前选择的按钮将关闭。AFAIK 我认为您将无法检查所有 QRadioButtons。

在我的实践中,我从未在一个对话框/窗口中看到所有的 QRadioButtons 都同时被选中。但可能是我弄错了。

作为我这边的解决方案,我可能会建议您创建一个额外的 QRadioButton,然后将其隐藏,因此,当您需要在一个小部件上隐藏所有 QRadioButton 时,您只需在隐藏的小部件上设置检查 (true)。

祝你好运。

于 2010-05-12T06:45:59.103 回答