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

前端 未结 2 1483
北海茫月
北海茫月 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

    You can very easily find all children matching a certain name pattern:

    // C++11
    auto pipes = findChildren(QRegExp("Pipe_[0-9]+"));
    for (pipe : pipes) {
      pipe->setStyleSheet(pipe->property("defaultStyleSheet").toString() +
        " QProgressBar::chunk { background: #D7DF01; }");
    }
    
    // C++98
    QList pipes = findChildren(QRegExp("Pipe_[0-9]+"));
    foreach (pipe, pipes) {
      pipe->setStyleSheet(pipe->property("defaultStyleSheet").toString() +
        " QProgressBar::chunk { background: #D7DF01; }");
    }
    

提交回复
热议问题