ColinDuquesnoy / QDarkStyleSheet

A dark style sheet for QtWidgets application
Other
2.85k stars 731 forks source link

Get color palette from app.palette #171

Open dridk opened 5 years ago

dridk commented 5 years ago

Information about your current environment setup:

Qt bindings available:

Description / Steps to Reproduce

I cannot access palette color of the current style. For example, if I try to access the text color supposed to be light, I get only the dark color from standard light theme.

app = QApplication(sys.argv)
app.setStyleSheet(qdarkstyle.load_stylesheet_pyside2())

# This line should return the light text color of darktheme style.  But it doesn't .
# It returns only the default light theme palette
print(app.palette().color(QPalette.Text).name()) 
goanpeca commented 5 years ago

@dridk I do not think that you can get those values from the qpalette. If you need to access the palette programmatically you can use

https://github.com/ColinDuquesnoy/QDarkStyleSheet/blob/master/qdarkstyle/palette.py

from qdarkstyle.palette import DarkPalette
dridk commented 5 years ago

Hi, Thanks for your reply . I just swtiched to qtmodern . I think you must follow the same pattern. They first set a QPalette from Python and secondly access colors from qss file using the "palette" keyword .

QGroupBox {
  background-color: palette(alternate-base);
  border: 1px solid palette(midlight);
  margin-top: 25px;
}

https://github.com/gmarull/qtmodern/blob/master/qtmodern/resources/style.qss

So now, I can be agnostic from the style and get color from QPalette.

goanpeca commented 5 years ago

Thanks for pointing to th-at . resource. Thoughts @dpizetta

dpizetta commented 5 years ago

I'll take a look. Tks