我发现与检查/取消选中QRadioButton相关的问题。我用于检查(白点)和取消选中(没有白点)的图像不会更新。 我的问题是:我已经实现了很少的QRadioButton(s)。所有QRadioButtons首次检查为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);
每个QRadioButtons的图像设置如下:
代码:
ui->radioButtonAll->setStyleSheet(
"QRadioButton::indicator::checked { image: url(:/Resources/radio-btn-selected.png);}"
"QRadioButton::indicator::unchecked {image: url(:/Resources/radio-btn-unselected.png);}"
);
没有更新QRradioButton图像的任何线索。谢谢。
答案 0 :(得分:13)
您的问题很可能与
有关setAutoExclusive(布尔)
默认情况下,属于同一父级的所有按钮的行为就像它们属于同一个独占按钮组一样。选择一个之后,您将无法返回所有按钮未选中状态。
解决方法是找出选中的按钮,并为该按钮执行以下操作
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
答案 1 :(得分:0)
确保您的资源文件如下:
<qresource>
<file>Resources/radio-btn-selected.png</file>
<file>Resources/radio-btn-unselected.png</file>
</qresource>
并且它已正确包含在您的应用程序中。
.qrc
文件中加入.pro
RESOURCES = myresource.qrc
QResource::registerResource("/path/to/myresource.rcc");