Pseudo-States can't be used to change qproperty-barColor
Description Using CSS pseudo-states in conjunction with qproperty-barColor does not apply it.
To Reproduce
import sys
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QApplication, QMainWindow
from superqt import QLabeledRangeSlider
if __name__ == '__main__':
app = QApplication(sys.argv)
window = QMainWindow()
slider = QLabeledRangeSlider(Qt.Horizontal)
slider.setStyleSheet("""QRangeSlider:focus { qproperty-barColor: #000; }""")
window.setCentralWidget(slider)
window.show()
sys.exit(app.exec_())
- Execute code fragment
- Slider color is not affected by QSS
- Remove pseudo-state
- Bar between handles is black
Expected behavior Pseudo-states should also work to change the bar color.
Desktop (please complete the following information):
- OS: Windows 10, Build 19042.1165
- Qt Backend: PyQt5
- Python: 3.8
thanks for the report!
Sorry, I'm afraid this is a Qt limitation. qproperties don't work with with pseudo-states, as stated in the QtDocs here
the qproperty syntax is evaluated only once, which is when the widget is polished by the style. This means that any attempt to use them in pseudo-states such as QPushButton:hover, will not work.
I'm not sure there's much we can do here... To fix this on our end would require A) parsing the QSS carefully and B) re-implementing all of the hover/focus/etc... events to update the styles with those parsed from the QSS. At that point we're not even really using QSS (and one might as well just apply the styles programmatically). I'm inclined to close this as "unactionable". let me know what you think