I'm trying to use a dynamic property to change a style for a QPushButton.

I have something like the following:

C++
Qt Code:
  1. // Create button with dynamic property
  2. button = new QPushButton(this);
  3. button->setObjectName(QString::fromUtf8("MyButton"));
  4. button->setProperty("myProperty", "rank1");
  5. // Button background should be red now
  6. ...
  7. // Change the property
  8. button->setProperty("myProperty", "rank2");
  9. // The button's background colour should be blue now
To copy to clipboard, switch view to plain text mode 

QSS
Qt Code:
  1. QPushButton#MyButton[myProperty="rank1"] { background: red; }
  2. QPushButton#MyButton[myProperty="rank2"] { background: blue; }
To copy to clipboard, switch view to plain text mode 

This does work to a certain degree. If I call QApplication::setStyleSheet() after updating myProperty, the style does update correctly. But the style is not updating correctly when I change the property. Is it incorrect to expect the button's background colour to change dynamically when the "myProperty" dynamic property is changed?