title: QPainter fillRect over geometry of widget in grid cell
body: <p>I've gone about customizing the <code>QPushButton</code> widget such that an animated flash of white appears above the widget when clicked. This works fine for the button I have located in cell (0, 0) of my grid. As for my button located at (2, 0) it appears that it doesn't paint a rect at all. This behavior can be seen in this video I've uploaded, with the corresponding <code>qDebug</code> output (button name &amp; geometry). The flash appears over "Registry" when clicked, but not "Exit":
  <a href="https://youtu.be/j5gE_5jeMtg" rel="nofollow">https://youtu.be/j5gE_5jeMtg</a></p>
  
  <p>Now for the code (if you see something that can be optimized, please feel free to provide me some tips):</p>
  
  <p><strong>pushbutton.h</strong></p>
  
  <pre><code>#ifndef PUSHBUTTON
  #define PUSHBUTTON
  
  #include &lt;QtCore&gt;
  #include &lt;QPushButton&gt;
  #include &lt;QPainter&gt;
  
  class PushButton : public QPushButton
  {
      Q_OBJECT
  
  public:
      explicit PushButton(QString text, QWidget *parent = 0);
  
  protected:
      virtual void paintEvent(QPaintEvent *);
  
  public slots:
      void OnClick();
      void OnTick();
  
  private:
      enum States
      {
          NONE = 0,
          RESET,
          DRAW
      } state = NONE;
  
      QTimer *timer;
  
      float delta = 0.0f;
  };
  
  #endif
  </code></pre>
  
  <p><strong>pushbutton.cpp</strong></p>
  
  <pre><code>#include "pushbutton.h"
  
  PushButton::PushButton(QString text, QWidget *parent) : QPushButton(text, parent)
  {
      timer = new QTimer(this);
  
      QObject::connect(this, SIGNAL(clicked(bool)), this, SLOT(OnClick()));
      QObject::connect(timer, SIGNAL(timeout()), this, SLOT(OnTick()));
  }
  
  void PushButton::paintEvent(QPaintEvent *e)
  {
      QPushButton::paintEvent(e);
  
      if(state == States::NONE)
      {
          return;
      }
  
      QPainter painter(this);
  
      if(state == States::RESET)
      {
          state = States::NONE;
  
          painter.eraseRect(geometry());
  
          update();
      }
      else
      {
          painter.fillRect(geometry(), QColor(200, 200, 200, 200 * (delta &lt; 1.0f ? delta : 2.0f - delta)));
      }
  }
  
  void PushButton::OnClick()
  {
      qDebug() &lt;&lt; text() &lt;&lt; geometry();
  
      state = States::DRAW;
  
      delta = 0.0f;
  
      timer-&gt;start(20);
  }
  
  void PushButton::OnTick()
  {
      delta += 0.2f;
  
      if(delta &gt; 2.0f)
      {
          state = States::RESET;
  
          timer-&gt;stop();
      }
  
      update();
  }
  </code></pre>
  
  <p><strong>mainwindow.cpp</strong></p>
  
  <pre><code>MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
  {
      ui-&gt;setupUi(this);
  
      registryButton = new PushButton("Registry");
      exitButton = new PushButton("Exit");
  
      registryButton-&gt;setStyleSheet("* { font-size: 16pt; font-family: Segoe360;"
                                    "border: none;"
                                    "color: rgba(240, 240, 240, 255);"
                                    "background: qlineargradient(x1:0 y1:0, x2:0 y2:1, stop:0 rgba(160, 169, 212, 255), stop:1 rgba(137, 151, 216, 255)); }");
  
      exitButton-&gt;setStyleSheet("* { font-size: 16pt; font-family: Segoe360;"
                                    "border: none;"
                                    "color: rgba(240, 240, 240, 255);"
                                    "background: qlineargradient(x1:0 y1:0, x2:0 y2:1, stop:0 rgba(191, 78, 78, 255), stop:1 rgba(199, 53, 53, 255)); }");
  
      ui-&gt;gridLayout-&gt;addWidget(registryButton, 0, 0, Qt::AlignTop);
      ui-&gt;gridLayout-&gt;addWidget(exitButton, 2, 0, Qt::AlignBottom);
  }
  </code></pre>
  
  <p>My only assumption toward this behavior is that there is more to working with grids than I'm aware of.</p>