Solved Problem with global stylesheet
-
I'm trying to set a global stylesheet for all my buttons.
Doing it for a specific button like the following, works:button->setStyleSheet(QString("QPushButton:focus {") + "outline: 0;" + "background-color: #" + BUTTON_HIGHLIGHT_BG_COLOR + "; " + "color: #" + BUTTON_HIGHLIGHT_TXT_COLOR + "; " + "}");
But if I make it global, in the main.cpp, like this:
qApp->setStyleSheet(QString("QPushButton:focus {") + "outline: 0;" + "background-color: #" + BUTTON_HIGHLIGHT_BG_COLOR + "; " + "color: #" + BUTTON_HIGHLIGHT_TXT_COLOR + "; " + "}");
[the following sentence was edited]
the focused buttons get the correct font color, but always with no background (transparent?), no matter the parameter I set for the background.How can I fix this?
Thanks -
@AlaaM
if possible try to set the stylesheet on your very toplevel window (mainwindow?)
Also what Qt version are you using? -
@raven-worx
Please see my edit.
The font color works. It's only the highlighted background that doesn't.
I do this in my main window.
Qt version 5.5.1 -
@AlaaM
i know, but i was thinking of some issue in style inheritance maybe. -
Answer here:
http://stackoverflow.com/questions/35018958/global-stylesheet-isnt-fully-working(in short: I had a
stackedWidget->setStyleSheet("background-color: white;")
on the loading screen. It needed to be removed or changed to:stackedWidget->setStyleSheet("QStackedWidget { background-color: white; }");
)