QTextEdit和QPlainTextEdit样式表中属性选择器不起作用的问题。
描述:QPlainTextEdit中设置QPlaintTextEdit[readOnly="true"]{....} QPlainTextEdit[readOnly="false"]{.....} 来为QPlainTextEdit在‘可编辑/不可编辑‘两种不同状态下设置不同的样式无效。
Qt文档中有这样一段话:
If the value of the Qt property changes after the style sheet has been set,it might be necessary to force a style sheet recomputation.
One way to achieve this is to unset the style sheet and set it again.
我的解决办法:
若只想更新很多控件中其中一个控件的样式,可以:
ui->frame->setStyle(ui->frame->style());
或者
ui->frame->setStyleSheet(ui->frame->styleSheet());
或者
ui->frame->setStyleSheet("");