title: Qt stylesheet for all QProgressBars programmatically (C++)
body: <p>Having trouble understanding how to <strong>programmatically set a stylesheet to be applied on several (or even all) widgets</strong> in Qt Creator 4.1 (Qt 5.7) with C++.</p>
  <p>For example, say I have 3 progress bar widgets; I have explicitly set each with the same stylesheet with <strong>css</strong> like so:</p>
  <pre><code>ui-&gt;c1-&gt;setStyleSheet(&quot;QProgressBar {&quot;
                            &quot;background-color: #74c8ff;&quot;
                            &quot;color: #0a9dff;&quot;
                            &quot;border-style: outset;&quot;
                            &quot;border-width: 2px;&quot;
                            &quot;border-color: #74c8ff;&quot;
                            &quot;border-radius: 7px;&quot;
                            &quot;text-align: left; }&quot;
  
                            &quot;QProgressBar::chunk {&quot;
                            &quot;background-color: #010327; }&quot;);
  
  ui-&gt;c2-&gt;setStyleSheet(&quot;QProgressBar {&quot;
                            &quot;background-color: #74c8ff;&quot;
                            &quot;color: #0a9dff;&quot;
                            &quot;border-style: outset;&quot;
                            &quot;border-width: 2px;&quot;
                            &quot;border-color: #74c8ff;&quot;
                            &quot;border-radius: 7px;&quot;
                            &quot;text-align: left; }&quot;
  
                            &quot;QProgressBar::chunk {&quot;
                            &quot;background-color: #010327; }&quot;);
  
  ui-&gt;c3-&gt;setStyleSheet(&quot;QProgressBar {&quot;
                            &quot;background-color: #74c8ff;&quot;
                            &quot;color: #0a9dff;&quot;
                            &quot;border-style: outset;&quot;
                            &quot;border-width: 2px;&quot;
                            &quot;border-color: #74c8ff;&quot;
                            &quot;border-radius: 7px;&quot;
                            &quot;text-align: left; }&quot;
  
                            &quot;QProgressBar::chunk {&quot;
                            &quot;background-color: #010327; }&quot;);
  </code></pre>
  <p>I would like to use the <a href="http://doc.qt.io/qt-5/stylesheet.html" rel="nofollow noreferrer">Qt Stylesheets</a> to create a stylesheet for my widgets and avoid all this code suplication.</p>
  <p>After reading the docs, the syntax would be like this :</p>
  <pre><code>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;
  }
  </code></pre>
  <p>but, apparently you cannot copy the parameter names as used in a <code>setStylesheet</code> with css directly to a syntax like the one above.</p>
  <p>I also tried something like this</p>
  <pre><code>QProgressBar.setStyleSheet(&quot;QProgressBar {&quot;
                             &quot;background-color: #74c8ff;&quot;
                             &quot;color: #0a9dff;&quot;
                             &quot;border-style: outset;&quot;
                             &quot;border-width: 2px;&quot;
                             &quot;border-color: #74c8ff;&quot;
                             &quot;border-radius: 7px;&quot;
                             &quot;text-align: left; }&quot;
  
                             &quot;QProgressBar::chunk {&quot;
                             &quot;background-color: #010327; }&quot;);
  </code></pre>
  <p>None of the above worked (undeclared identifiers and syntax errors).</p>
  <p>Could someone provide an example of how you can achieve defining a single stylesheet with the above parameters to be applied for all widgets? If you could point to a resource (I could not find anything!) that explains the available parameters to achive my goal, that would be as good).</p>
  <p>Finally, if such a stylesheet is created for all progress bars, <strong>how can I exclude one progress bar</strong> (or any widget for that matter) from having that stylesheet and have instead a different one?</p>