Support #5865


Adding and Removing Rules with WCssStyleSheet

Added by Heiko Gerdau over 6 years ago. Updated over 6 years ago.

Target version:
Start date:
Due date:
% Done:


Estimated time:



I'm trying to use the internal stylesheet to dynamically update the appearence of a template (divs that are not mapped to Wt widgets). I'm probably missing something as you can see from the following questions:

When adding a rule to the internal stylesheet one might supply a name which may be used to detect (WCssStyleSheet::isdefined()) wether it is already set.

But after removing that rule WCssStyleSheet::isdefined() still returns true. Is that a bug?

How can I change a rule? There is a function WCssRule::modified() but I found no way to achieve the modification.

To remove a rule I have to keep track of the pointers returned from "WCssStyleSheet::addRule". I would have expected a getter like "getRuleByName" and a way to change the declarations of a rule.

What do I miss?

The widgets I want to style in this way are divs of complex flex layouts which - as far as I know - can not be mapped to Wt-widgets if I do not use Wt-layouts to manage their content. That's why I do not use external stylesheets and addStyleClass in this case.

Thanks for any advice?



Actions #1

Updated by Wim Dumon over 6 years ago

Hello Heiko,

We usually don't edit stylesheets to modify the looks of a widget, but add CSS rules for the possible visual states and apply the appropriate style classes to widgets when they should be displayed differently. In many cases, the use of an appropriate CSS selector will allow you to modify the style class on the WTemplate so that a div (with a styleclass) inside the WTemplate changes appearance. If you need more fine-grained control, you can set a style class that is a var and use bindstring to modify the style class:

<message ..>
  <div class="${div-class}">blah</div>

if (...)
  template->bindString("div-class", "important");
  template->bindString("div-class", "not-so-important");

I see that using the WCssStyleSheet class to modify stylesheets can be confusing. Originally it wasn't intended to be used in such a way, but all methods seem to be present to allow it, a bit poorly.

Best regards,


Actions #2

Updated by Heiko Gerdau over 6 years ago

Many thanks Wim,

I wasn't aware that I may use WTemplate::bindString dynamically again and again on the same variable. Nice.

Although this solves my problems I still think WCssStyleSheet::isdefined() should be based on a map not on a set which looses the name<->rule connection.




Also available in: Atom PDF