Struggling to figure out how to dynamically apply a stylesheet to multiple or all widgets in Qt Creator 4.1 (Qt 5.7) using C++.
For instance, if I have 3 progress bar widgets, currently I am setting the same stylesheet for each one individually with CSS:
ui->c1->setStyleSheet("QProgressBar {"
"background-color: #74c8ff;"
"color: #0a9dff;"
"border-style: outset;"
"border-width: 2px;"
"border-color: #74c8ff;"
"border-radius: 7px;"
"text-align: left; }"
"QProgressBar::chunk {"
"background-color: #010327; }");
// Repeated for ui->c2 and ui->c3 as well
I want to utilize Qt Stylesheets to streamline the process and eliminate repetition of code.
According to the documentation, the syntax should look like this:
QProgressBar
{
background: #74c8ff;
color: #0a9dff;
border-style: outset;
border-width: 2px;
border-color: #74c8ff;
border-radius: 7px;
text-align: left;
}
QProgressBar::chunk
{
background-color: #010327;
}
However, you cannot directly adapt parameter names from setStylesheet to the above syntax.
I also attempted something like this:
QProgressBar.setStyleSheet("QProgressBar {"
"background-color: #74c8ff;"
"color: #0a9dff;"
"border-style: outset;"
"border-width: 2px;"
"border-color: #74c8ff;"
"border-radius: 7px;"
"text-align: left; }"
"QProgressBar::chunk {"
"background-color: #010327; }");
Unfortunately, both methods failed due to undeclared identifiers and syntax errors.
Is there an example available on how to define a single stylesheet with these parameters for all widgets? Any resource explaining the available parameters would be greatly appreciated.
Lastly, if a stylesheet is created for all progress bars, how can I exclude one progressBar (or any widget) from that stylesheet and apply a different one instead?