Qt KDE theme stylesheet - c++

I am using KDE theme Breeze Dark. Since all my Qt applications have changed its colors. Earlier my applications wasn't altered by KDE themes but now I am receiving message: "kf5.kiconthemes: "Theme tree: (Breeze)". I was changing background colors in my apps using stylesheets. Now due to changed fonts colors it is impossible to read (white text on very bright background). What is more I am not able to get default background color.
qDebug() << qApp->styleSheet(); gives me empty string.
How to get background color? I would like to use it setting my own backgrounds (showing priority of a task, little more reddish background and so on).

You can access to default theme colors via QPalette.
If you want just to change colors of your widgets - QSS is overkill. QPalette is more than enough.

Related

How Do I Change NavigationBar Color For WatchOS?

I am building watchOS app and I am trying to change navigationBar background color from black to transparent, but I am not able to find anything. I saw this question which was asked in 2015, according to which it is impossible to change navigationBar color in watchOS. I was wondering if now there is any API for that.
Thanks for any help.
This is about Color in the human-interface-guidelines from apple:
Make sure your app’s colors work well in both light and dark
appearance modes. With the exception of watchOS, which always uses a
pure black background, the platforms offer a dark alternative to the
default light appearance. Dark Mode uses a darker color palette for
all screens, views, menus, and controls, and can increase vibrancy — a
subtle effect that dynamically blends foreground and background colors
— to make foreground content stand out against darker backgrounds.
System colors automatically support both appearances; if you use a
custom color, you need to supply both light and dark variants. For
guidance, see Dark Mode.

QtWidget background image issue (Qt Creator)

I want to add a background image to a Qt Widget. I am using Qt Creator 4.0.2 on Linux 64-bit.
The issue is when I am choosing a background image, it doesn't show (although a part of image can be seen around the PushButtons I have on page) when I run the program. However when choosing a background color works perfect.
(Using CSS)
Here are the screens :
With background-image
With background-color
Try and set it through the style sheet:
yourWidget->setStyleSheet("background-image: url(<path-to-image>/image.png)")
It works for me.

How to recognize that an application is running in dark theme on Linux?

I've developed an application which uses qscintilla as a text editor. I also implemented custom lexer to highlight language specific keywords. So far styles for highlighted keywords are hardcoded in mine application and it looks quite ok in the default theme on Windows/Linux(Ubuntu)/Mac.
The problems appears when user chooses a dark theme (on Linux). Depending on QScintilla version some parts of editor do reflect current theme colors while other don't. Moreover mine custom styles render dark blue letters on dark grey background.
I'm looking for some Qt class, which will allow me access of the current system theme. I do not want to define styles for mine application widgets.
I want to know what is system default non-proportional font, what is it's size, color, ... If I knew that dark scheme is used I would choose complementary colors for keyword highlighting.
I checked docs for QStyle, QPlatformTheme and other qt classes and it seems to me that these serve more for defining of new styles, then for describing the current style.
For the system colours, you can use the group/role of the QPalette class.
For the system fonts, you can create a QFont using e.g. "Serif", "Sans Serif", "Monospace", etc with an appropriate style hint to discover the defaults.
NB:
From the Qt Docs:
Warning: Some styles do not use the palette for all drawing, for
instance, if they make use of native theme engines. This is the case
for both the Windows Vista and the macOS styles.
Here is some python code using QPalette that works for me on Linux:
label = QLabel("am I in the dark?")
text_hsv_value = label.palette().color(QPalette.WindowText).value()
bg_hsv_value = label.palette().color(QPalette.Background).value()
dark_theme_found = text_hsv_value > bg_hsv_value

How to change the color of the green background present when compiling apps using Emscripten-qt (behind the window)

I am using Emscripten-qt to compile Native Qt apps into Javascript. The application is simple and works fine. The only problem I am having is that the Canvas has a green background that displays behind the Window. I want to know how I can change that green background to a different color in order to stick with my color scheme.
Thanks..
mike

swapping background colors in gtk text field (gtkmm C++)

Within my GUI (C++, GTKMM 3), i have a text field that is providing some status information. i'd like to change the background color of this field (along with the text, which i can easily do), based upon the status.
there's not a lot out there on how to do this with GTKMM 3.X. i know i need to use the CssProvider class, and have found some examples on how to load one into the program. but the examples show how to set the properties one time.
but what i haven't figured out is how i can use the CSS properties to change the color of the background, based upon a state (not a state as in 'hover' or anything like that. i want to be able to swap the background from red to green whenever i please). if the CSS is written in terms of using the name of the widget, or the type of widget, how do you handle a changing state with the widget to change its properties?
if anyone has any clues, or knows of any examples, i could really use some help. the purpose of this is to give the user some immediate feedback at a glance. in a rush, they won't have to read the status of the box (or from a distance). the color will allow them to gauge what is going on at a glance.
Adding code
this is what i have tried so far (condensed):
std::string style_sheet = ".red_bg {background: #FF0000; color: #000000; } ";
style_sheet += ".green_bg {background: #33FF33; color: #000000; }";
Glib::RefPtr<Gtk::StyleContext> stylecontext = my_text_field->get_style_context();
Glib::RefPtr<Gtk::CssProvider> cssprov = Gtk::CssProvider::create();
cssprov->load_from_data(style_sheet);
stylecontext->add_provider(cssprov, GTK_STYLE_PROVIDER_PRIORITY_USER);
stylecontext->add_class("red_bg");
stylecontext->context_save();
so that works. when the program fires up, i get a text entry with a red background.
but later on, if i do the following, nothing happens:
Glib::RefPtr<Gtk::StyleContext>stylecontext = my_text_field->get_style_context();
stylecontext->remove_class("red_bg");
stylecontext->context_save(); // probably not necessary
stylecontext->add_class("green_bg");
stylecontext->context_save();
at that point, the background stays red. no transition from red to green. i've seen suggestions to use the override_background_color function in the GtkWidget object, but that doesn't work. that only changes the color that is used when you highlight the text in the widget. i'd still like to see it done the CSS way.
You could do away with the CSS and just use override_background_color, a standard GTK widget method:
override_background_color (StateFlags state, RGBA color)
Sets the background color to use for a widget.
All other style values are left untouched.
Note:
This API is mostly meant as a quick way for applications to change a widget appearance. If you are developing a widgets library and intend this change to be themeable, it is better done by setting meaningful CSS classes and regions in your widget/container implementation through add_class and add_region.
This way, your widget library can install a CssProvider with the STYLE_PROVIDER_PRIORITY_FALLBACK priority in order to provide a default styling for those widgets that need so, and this theming may fully overridden by the user's theme.
Note:
Note that for complex widgets this may bring in undesired results (such as uniform background color everywhere), in these cases it is better to fully style such widgets through a CssProvider with the STYLE_PROVIDER_PRIORITY_APPLICATION priority.
Parameters:
StateFlags state the state for which to set the background color
RGBA color the color to assign, or null to undo the effect of previous calls to override_background_color