Support #7740
setValueStyleClass has no visual effect
Added by Mahmudul Hasan almost 2 years ago.
Updated over 1 year ago.
Description
Trying to change progress bar progress color based on progress value.
But i see it has no immediate effect. It requires page refresh.
Is it supposed to be like this or I am doing something wrong?
Please see below :
auto style = VELOCITY_MODEL.Overrange() ? "progress bg-danger-Polytec" : "progress bg-info-polytec";
m_velocityProgressBar->setValueStyleClass(style);
Wt::WApplication::instance()->triggerUpdate();
- Description updated (diff)
- Assignee changed from Koen Deforche to Korneel Dumon
- Priority changed from Immediate to Normal
Korneel Dumon wrote in #note-1:
Hi,
could be a few things. Do you see the style-class in the browser debugger? Or do you think triggerUpdate() does nothing?
To make server updates, you need to do a few things:
- call WApplication::enableUpdates() before-hand to make sure Wt keeps an open line to the client
- grab the update-lock (or use WServer::post)
- triggerUpdate() as you do
See also: https://webtoolkit.eu/wt/doc/reference/html/classWt_1_1WApplication.html#ad9631ca64e68d30d40cb49c90e55223d
I see the style is not changed. It's always as initiated(progress bg-info-polytec). But other properties are updated Like the progress value.
It seems WProgressBar::setValueStyleClass()
is not part of the public API (as it is not documented). After checking the code, I noticed that this function
does not trigger a repaint, which explains the behavior you see.
You're better off changing the style class on progress bar itself and making style rules that combine classes.
Korneel Dumon wrote in #note-3:
It seems WProgressBar::setValueStyleClass()
is not part of the public API (as it is not documented). After checking the code, I noticed that this function
does not trigger a repaint, which explains the behavior you see.
You're better off changing the style class on progress bar itself and making style rules that combine classes.
I am not sure if I understood your properly. Can you give me bit hint what you mean by making style rule?
I tried using the setStyleClass. But the danger color looks goes to the background.
auto style = m_velocityModel.Overrange() ? "bg-danger" : "bg-info";
m_velocityProgressBar->setStyleClass(style);
The style-rule should be something like:
.bg-danger .progress-bar { background-color: red; }
.bg-info .progress-bar { background-color: green; }
Note that I didn't test this, just trying to show you the idea.
Also available in: Atom
PDF