Unsolved Changing QPalette::WindowText by Q_PROPERTY by QSS
-
Hi and welcome to devnet,
Are you sure your style sheet is applied ?
Even if it comes from the resource, you should check that the file is opened properly.
-
@SGaist Thank you,
Style sheet is applied OK, I can modify anything with the QSS file and there is no error in console.
-
@RyuMake
Which part is not working?
is void Theme::setClr(QColor c) called with red ?
Anyway, i wondering if you need
https://wiki.qt.io/Dynamic_Properties_and_Stylesheets
unpolish();
polish(); -
Hi @mrjj,
Specifically it's this part that isn't working.p.setColor(QPalette::WindowText, theme->getClr);
Though log gets spammed with "[widget] does not have a property named [var]".
I'll look into polish.
-
@RyuMake
Hi
But is theme affected by stylesheet?
You seems to give it no parent so even you set stylesheet to qApp
i would suspect :getClr() to return default value for clr since its not under stylesheet effect.
As far as it reads. Could be wrong :) -
@mrjj
Hi, yes theme is affected by style sheet, if I make a random paintEvent (draw a line across the screen) I can change its color from within the style sheet using the qproperty.Basically the idea is to set a color value to qApp style (Fusion) by external style sheet. I wonder if it's not possible? I get no errors, program runs perfectly OK, it just displays black though.
-
@RyuMake
So if you use a theme instance in a paint event
The color set by stylesheet is red ?
Ok. just looked odd. I thought it might not be affected but seems it is then.But getClr IS called ? for your instance?
-
You are getting all these messages because your style sheet applies to all widgets and only Theme provides that property.
-
-
I set some debug messages to my getter and setter, I get messages in the log for both. If I break the style sheet syntax I'll only get the setter message and an error saying style sheet could not be parsed, so it's definitely working, it just won't work with setStyle QPalette. I wonder if it can't be done in main()?
My instance:
int main(int argc, char *argv[]) { QApplication a(argc, argv); QApplication::setStyle(QStyleFactory::create("Fusion")); Theme themeObject; Theme *themePointer = &themeObject; QPalette p; p = qApp->palette(); p.setColor(QPalette::Window, themePointer->bgColor()); // <--- HERE qApp->setPalette(p); return a.exec(); }
-
What OS are you on ?
Depending on the style used, the palette or part of it can be ignored by it.