superqt icon indicating copy to clipboard operation
superqt copied to clipboard

Pseudo-States can't be used to change qproperty-barColor

Open mtunix opened this issue 4 years ago • 2 comments

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_())
  1. Execute code fragment
  2. Slider color is not affected by QSS
  3. Remove pseudo-state
  4. 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

mtunix avatar Aug 27 '21 14:08 mtunix

thanks for the report!

tlambert03 avatar Aug 31 '21 23:08 tlambert03

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

tlambert03 avatar Sep 11 '21 02:09 tlambert03