title: Qt Stylesheet for custom widget
body: <p>I have several custom widget in my current project. I wish to apply stylesheets to them and when I do so inside Qt Creator, it appears to work. However, when executing the program, no stylesheet is used. The stylesheets for the Qt widgets are working normally.</p>
  <p>Does anyone have any advice?</p>
  <p>WidgetUnits.h</p>
  <pre><code>#ifndef WIDGETUNITS_H
  #define WIDGETUNITS_H
  
  #include &lt;QList&gt;
  
  #include &lt;QWidget&gt;
  #include &lt;QPainter&gt;
  
  #include &lt;Widgets/JECButton.h&gt;
  
  #include &lt;Unit.h&gt;
  #include &lt;Time.h&gt;
  
  namespace Ui
  {
      class WidgetUnits;
  }
  
  class WidgetUnits : public QWidget
  {
      Q_OBJECT
  
  public:
      explicit WidgetUnits(QWidget *parent = 0);
      ~WidgetUnits();
  
      void setNumTimes(const int&amp; numTimes);
  
  public slots:
      void updatePictures(const Time* time);
  
  protected:
      void paintEvent(QPaintEvent *event);
  private:
      void checkNewQueue(const QList&lt;QList&lt;Unit*&gt;*&gt;* units);
      Ui::WidgetUnits *ui;
  
      const int pictureWidth;                         // The width of the Unit pictures.
      const int pictureHeight;                        // The height of the Unit pictures.
  
      QList&lt;QList&lt;JECButton*&gt;*&gt; buttonPictures;       // The Units' pictures. The outer QList stores the QList of pictures for a given tick.
                                                      // The inner QList stores the JECButtons for the specific tick.
  };
  </code></pre>
  <p>WidgetUnits.cpp</p>
  <pre><code>#include &quot;WidgetUnits.h&quot;
  #include &quot;ui_WidgetUnits.h&quot;
  
  WidgetUnits::WidgetUnits(QWidget *parent):
      QWidget(parent),
      ui(new Ui::WidgetUnits),
      pictureWidth(36),
      pictureHeight(36)
  {
      ui-&gt;setupUi(this);
  }
  
  WidgetUnits::~WidgetUnits()
  {
      delete ui;
  }
  
  void WidgetUnits::updatePictures(const Time *time)
  {
      // Only showing units that started to get built this turn.
      checkNewQueue(time-&gt;getUnits());
      checkNewQueue(time-&gt;getBuildings());
      checkNewQueue(time-&gt;getUpgrades());
  
      // Updating the position of the remaining pictures (after some were removed).
      // Checking the maximum number of Units made in one tick.
      int maxNewQueue = 0;
      for (int a = 0; a &lt; buttonPictures.length(); ++a)
      {
          if (buttonPictures.at(a)-&gt;length() &gt; maxNewQueue)
          {
              maxNewQueue = buttonPictures.at(a)-&gt;length();
          }
      }
  
      if (buttonPictures.length() &gt; 0)
      {
          this-&gt;setGeometry(0, 0, buttonPictures.length() * 130,
                            maxNewQueue * (pictureWidth + 10) + 20);
  
          QList&lt;JECButton*&gt;* tickButtons = 0;
          for (int a = 0; a &lt; buttonPictures.length(); ++a)
          {
              tickButtons = buttonPictures.at(a);
              for (int b = 0; b &lt; tickButtons-&gt;length(); ++b)
              {
                  tickButtons-&gt;at(b)-&gt;move(a * 130, b * (pictureHeight + 10));
              }
          }
      }
      update();
  }
  
  void WidgetUnits::checkNewQueue(const QList&lt;QList&lt;Unit *&gt; *&gt; *units)
  {
      if (units != 0)
      {
          const Unit* currentUnit = 0;
          JECButton* currentButton = 0;
          for (int a = 0; a &lt; units-&gt;length(); ++a)
          {
              buttonPictures.append(new QList&lt;JECButton*&gt;());
  
              for (int b = 0; b &lt; units-&gt;at(a)-&gt;length(); ++b)
              {
                  currentUnit = units-&gt;at(a)-&gt;at(b);
  
                  // Verifying that there is an item in the queue and the queue action was started this turn.
                  if (currentUnit-&gt;getQueue() != 0 &amp;&amp; currentUnit-&gt;getAction()-&gt;getTimeStart() == currentUnit-&gt;getAction()-&gt;getTimeCurrent()
                          &amp;&amp; (currentUnit-&gt;getAction()-&gt;getType() == Action::BUILD || currentUnit-&gt;getAction()-&gt;getType() == Action::TRAIN ||
                              currentUnit-&gt;getAction()-&gt;getType() == Action::UPGRADE))
                  {
                      buttonPictures.last()-&gt;append(new JECButton(this));
                      currentButton = buttonPictures.last()-&gt;last();
  
                      QImage* image = new QImage(currentUnit-&gt;getQueue()-&gt;getUnitBase()-&gt;getImage().scaled(pictureWidth, pictureHeight));
                      currentButton-&gt;setImage(*image);
                      currentButton-&gt;setGeometry(0, 0, currentButton-&gt;getImage().width(),
                                                         currentButton-&gt;getImage().height());
                      currentButton-&gt;setColorHover(QColor(0, 0, 225));
                      currentButton-&gt;setColorPressed(QColor(120, 120, 120));
                      currentButton-&gt;setImageOwner(true);
                      currentButton-&gt;setVisible(true);
                  }
              }
          }
      }
  }
  
  void WidgetUnits::setNumTimes(const int &amp;numTimes)
  {
      // Appending new button lists for added ticks.
      for (int a = buttonPictures.length(); a &lt; numTimes; ++a)
      {
          buttonPictures.append(new QList&lt;JECButton*&gt;());
      }
  }
  
  void WidgetUnits::paintEvent(QPaintEvent *event)
  {
      QWidget::paintEvent(event);
  }
  </code></pre>
  <p>The widget is visible- I set a tooltip which it showed me (It's just the same color of the <code>QScrollArea</code> it's sitting in).</p>