How to apply changes to multiple ui controls fitting a certain name pattern?

前端 未结 2 1472
北海茫月
北海茫月 2021-01-24 03:18
ui->Pipe_1->setStyleSheet(ui->Pipe_1->property(\"defaultStyleSheet\").toString() +
\" QProgressBar::chunk { background: #D7DF01; }\");
ui->Pipe_2->setS         


        
2条回答
  •  时光取名叫无心
    2021-01-24 03:56

    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.

提交回复
热议问题