我想使用动态属性来更改我的QLabel的样式,因为我们可以在QSS中通过以下方式针对此属性进行操作:
QLabel[foo = "warning"]{ color: red; }
QLabel[foo = "success"]{ color: green; }
当我使用 QApplication::setStyleSheet()
时,我的标签样式确实会更新,但是当我更改属性的值时似乎不起作用。
label = new QLabel( this );
label->setText( "some text" );
label->setProperty( "foo", "warning");
// after some event
label->setProperty( "foo", "success" );
// the label's color should be green now
我错过了什么,还是样式更改不能以这种方式工作?