gpt4 book ai didi

qt - Qt 中的 QRadioButton 选中/取消选中问题

转载 作者:行者123 更新时间:2023-12-03 07:10:07 26 4
gpt4 key购买 nike

我发现与选中/取消选中 QRadioButton 相关的问题。我用于检查(白点)和取消检查(没有白点)的图像未更新。我的问题是:我已经实现了一些 QRadioButton。第一次所有 QRadioButton 都检查为 false。因此,本例的图像没有白点。当用户选择任何 QRadioButton 时,它的图像会更改为另一个图像,即带有白点的图像。单击按钮时,我将单选按钮的状态从选中状态重置为取消选中状态。然而图像状态没有改变。它们仍处于检查状态。代码片段如下:

代码:

if(ui->radioButtonReadOnlineData->isChecked())
ui->radioButtonReadOnlineData->setChecked(false);
if(ui->radioButtonSavetoDBReadOfflineData->isChecked())
ui->radioButtonSavetoDBReadOfflineData->setChecked(false);
if(ui->radioButtonViewLocalData->isChecked())
ui->radioButtonViewLocalData->setChecked(false);
if(ui->radioButtonDateRange->isChecked())
ui->radioButtonDateRange->setChecked(false);
if(ui->radioButtonAll->isChecked())
ui->radioButtonAll->setChecked(false);

每个 QRadioButton 的图像设置如下:

代码:

ui->radioButtonAll->setStyleSheet(
"QRadioButton::indicator::checked { image: url(:/Resources/radio-btn-selected.png);}"
"QRadioButton::indicator::unchecked {image: url(:/Resources/radio-btn-unselected.png);}"
);

任何 QRradioButton 图像未更新的线索。谢谢。

最佳答案

您的问题很可能与

setAutoExclusive(bool)

默认情况下,属于同一父级的所有按钮的行为就好像它们是同一独占按钮组的一部分一样。选择一个按钮后,您将无法返回到取消选中所有按钮的状态。

解决方法是找出选中的按钮,然后针对该按钮执行以下操作

theSelectedButton->setAutoExclusive(false);
thsSelectedButton->setChecked(false);
theSelectedButton->setAutoExclusive(true);

查看这些链接以获取更多信息:

http://developer.qt.nokia.com/forums/viewthread/5482

http://www.qtforum.org/article/19619/qradiobutton-setchecked-bug.html

关于qt - Qt 中的 QRadioButton 选中/取消选中问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9372992/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com