我正在查找与QRadioButton检查/取消检查有关的问题。用于检查(一个白点)和取消检查(没有白点)的图像没有更新。我的问题是:我实现的QRadioButton很少。所有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图像没有更新的任何线索。谢谢。
发布于 2012-02-21 09:59:34
你的问题很可能与
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
发布于 2012-02-21 09:06:24
确保您的资源文件如下所示:
<qresource>
<file>Resources/radio-btn-selected.png</file>
<file>Resources/radio-btn-unselected.png</file>
</qresource>并且它被正确地包含在您的应用程序中。
.qrc包含在.pro文件中 RESOURCES = myresource.qrcQResource::registerResource("/path/to/myresource.rcc");https://stackoverflow.com/questions/9372992
复制相似问题