How to use setThemeStyleEnabled() and setStyleClass() methods?
Added by Ali Ali about 1 month ago
Hello
I am using these methods as follows:
servicesMenu = std::move (std::make_unique<Wt::WPopupMenu>());
servicesMenu->setStyleClass ("test");
servicesMenu->addItem (Wt::WText().tr("onlineConsultation"))->setThemeStyleEnabled (false);
servicesMenu->addItem (Wt::WText().tr("support"))->setThemeStyleEnabled (false);
- Should "setStyleClass()" replace existing classes with "test"? If yes, it won't work!
- "setThemeStyleEnabled (false)" doesn't remove the "active" class of the selected item. I checked the documentation and found this: > This should be changed after the widget is created but before it is rendered. What does this mean?
Replies (1)
RE: How to use setThemeStyleEnabled() and setStyleClass() methods? - Added by Matthias Van Ceulebroeck 30 days ago
Hello Ali,
that is indeed the way it ought to work, and also a tricky case to ensure it works correctly. Not all widgets' content is immediately defined, as in some widgets define content the moment they are rendered, this function follows the inverse caveat as
setThemeStyleEnabled()
, namely that rendering can have side-effects of setting styleclasses.the caveat means that there is two ways to think about the widget. Creation is done on the server side, rendering on the client side. Meaning that as long as the
setThemeStyleEnabled()
is called before the http request is performed, all is fine. If the server sends a response to the client, and the server THEN callssetThemeStyleEnabled()
, it will no longer change anything.
Now, I do think I see a case that violates the principle of setThemeStyleEnabled()
in WMenuItem
.
For 1. it is a little more complicated, and since it was used wrongly before, is likely to break some existing code.
Ticket #13569 is used to track the second issue.
Best,
Matthias