ui->Pipe_1->setStyleSheet(ui->Pipe_1->property(\"defaultStyleSheet\").toString() +
\" QProgressBar::chunk { background: #D7DF01; }\");
ui->Pipe_2->setS
You can very easily find all children matching a certain name pattern:
// C++11
auto pipes = findChildren<QProgressBar*>(QRegExp("Pipe_[0-9]+"));
for (pipe : pipes) {
pipe->setStyleSheet(pipe->property("defaultStyleSheet").toString() +
" QProgressBar::chunk { background: #D7DF01; }");
}
// C++98
QList<QProgressBar*> pipes = findChildren<QProgressBar*>(QRegExp("Pipe_[0-9]+"));
foreach (pipe, pipes) {
pipe->setStyleSheet(pipe->property("defaultStyleSheet").toString() +
" QProgressBar::chunk { background: #D7DF01; }");
}
Why do you have 75 progress bars in your UI? Anyway, this is a prime example of why more seasoned Qt UI developers don't use Qt Designer. If you were hand coding your UI, you would just store the pointers in an array as you built them and iterated through later.
As for your current problem you could set the objectName
property in Qt Designer and then use QObject::findChild(..)
to retrieve them dynamically, or use Boost::PreProcessor to build the statements for you, or derive from QProgressBar
and set the stylesheet in the constructor.