我正在开发一个示例应用程序,其中我需要在复选框未选中时禁用复选框的文本,并在复选框被选中时启用它。
代码:
if(ui->checkBox->isChecked() == true)
{
// Enable the text of the checkbox
}
else
{
// Disable the text of the checkbox
}我看过各种文章,但都没有找到正确的解决方案。
发布于 2013-04-24 19:13:38
使用stylesheet
对于您的所有小部件:
ui->setStyleSheet(
"QCheckBox:checked {
{color: black;}
}
QCheckBox:unchecked {
{color: grey;}
}"
)编辑:
正如注释中所提到的,要使其与自定义主题一起工作,您可以将样式设置为查询palette
QPalette my_palette = ui->palette()
QColor my_active_color = my_palette.color(QPalette::Active, QPalette::Text);
QColor my_disabled_color = my_palette.color(QPalette::Disabled, QPalette::Text);
QString my_style =
QString("QCheckBox:checked { {color: rgb(%1, %2, %3);} } "
"QCheckBox:unchecked { {color: rgb(%4, %5, %6);}}")
.arg( my_active_color.red())
.arg( my_active_color.green())
.arg( my_active_color.blue() )
.arg( my_disabled_color.red())
.arg( my_disabled_color.green())
.arg( my_disabled_color.blue() );
ui->setStyleSheet(my_style);请注意,我没有尝试过它,它可能有任何打字错误,但你明白我的意思。
发布于 2013-04-24 19:27:50
我找到解决方案了。这就是我是如何做到的:
ui->checkBox->setStyleSheet( "QCheckBox:checked{color: black;} QCheckBox:unchecked{color: grey;}");https://stackoverflow.com/questions/16190317
复制相似问题