Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide Efficient Method to Dynamically Change Control Colors while using qlementinestyle #49

Open
pinojojo opened this issue Jan 10, 2024 · 1 comment
Milestone

Comments

@pinojojo
Copy link

Hi, oclero,

I'm really impressed with this repository, particularly the animations. However, I've encountered a challenge when using the library. There doesn't seem to be a straightforward method for changing the colors of controls, such as the foreground font or background colors. This feature is particularly necessary when differentiating individual buttons among a group, where some buttons require color highlighting for emphasis.

My attempts to use the widget's palette and stylesheet, which are generally considered the standard approach, were unsuccessful. Further investigation into the source code revealed that the buttonBackgroundColor is governed by the theme in qlementinestyle. As I understand it, this theme isn't intended for frequent dynamic updates during the entire application session.

While I could follow the example in the source code and create a qproxystyle to modify the colors, ensuring that the corner radius remains consistent with qlementine, I find this solution rather cumbersome. Is there a simpler method to alter specific colors within the library?

@oclero
Copy link
Owner

oclero commented Jan 11, 2024

Qt's CSS is not supported by choice in Qlementine. When you define CSS on a QWidget, its style becomes QStylesheetStyle, which is painfully slow, buggy (it can't even draw clean rounded corners...) and complex, and can't do animations. I want to avoid that at all costs. This is the raison d'être of Qlementine.

Currently, the theming system is minimal on purpose. The goal is to avoid having a 3000-line CSS file as commonly seen in entreprise Qt projects. Also, a corollary is that it forces developers to use a simple design system instead of making lots of special cases and mixing style code and UI code.

Also, currently, proxy styles are not supported yet, since it adds a whole layer of complexity and could create many bugs in the developer's proxy style code. I would like to add this feature someday, though.

Here are 2 alternative solutions to your problem:

  • If you need to highlight a button among a group, have you thought about making it checked?
  • You can inherit QlementineStyle and override the methods that give the color. These methods act as kind of a proxy to the JSON theme. Set a dynamic QProperty on your button, and check if the value of that property in the method you're overidding, and return a specific color in that case. It won't break the animation system.

@oclero oclero added this to the Backlog milestone Feb 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants