如果你想让 QRadioButton
控件默认选中,可以使用 setChecked(true)
函数来设置其状态为选中。以下是示例代码:
// 其他代码...
radioButton = new QRadioButton(frame);
radioButton->setObjectName(QString::fromUtf8("radioButton"));
radioButton->setChecked(true); // 默认选中
gridLayout->addWidget(radioButton, 0, 0, 1, 1);
radioButton_2 = new QRadioButton(frame);
radioButton_2->setObjectName(QString::fromUtf8("radioButton_2"));
gridLayout->addWidget(radioButton_2, 1, 0, 1, 1);
// 其他代码...
通过调用 setChecked(true)
函数,我们将 QRadioButton
控件的状态设为选中,从而使其在界面加载时默认处于选中状态。
同样的,你可以对其他的 QRadioButton
控件进行相似的操作,例如:
radioButton_3 = new QRadioButton(frame_2);
radioButton_3->setObjectName(QString::fromUtf8("radioButton_3"));
radioButton_3->setChecked(true); // 默认选中
gridLayout_2->addWidget(radioButton_3, 0, 0, 1, 1);
// 其他代码...
希望这能帮助到你!
内容由零声教学AI助手提供,问题来源于学员提问