title: Animate Geometry inside QGridLayout in PyQt
body: <p>How to animate geometry change inside QGridLayout. I have QLabel which will be placed inside the QGridlayout. It should expand when the mouse is inside the QLabel and shrink back to the normal state when outside. I managed to animate but, it doesn't expand from all four sides. It instead moves away from the grid.</p>
  <p>MRE:</p>
  <pre><code>import sys
  from PyQt5 import QtWidgets, QtCore
  
  
  class Tile(QtWidgets.QLabel):
  
      def __init__(self, *args, **kwargs):
          super(Tile, self).__init__(*args, **kwargs)
  
          # p = self.palette()
          # p.setColor(self.backgroundRole(), QtCore.Qt.red)
          # self.setPalette(p)
          self.setText(&quot;hello&quot;)
          self.setMinimumSize(100, 100)
          self.setMaximumSize(125, 125)
  
      def enterEvent(self, a0: QtCore.QEvent) -&gt; None:
          super(Tile, self).enterEvent(a0)
  
          self.animation = QtCore.QPropertyAnimation(self, b&quot;geometry&quot;)
          self.animation.setStartValue(QtCore.QRect(self.geometry()))
          self.animation.setEndValue(QtCore.QRect(self.geometry().adjusted(-25, -25, 25, 25)))
          self.animation.setDuration(150)
          self.animation.start(QtCore.QPropertyAnimation.DeleteWhenStopped)
  
      def leaveEvent(self, a0: QtCore.QEvent) -&gt; None:
          super(Tile, self).leaveEvent(a0)
  
          self.animation = QtCore.QPropertyAnimation(self, b&quot;geometry&quot;)
          self.animation.setStartValue(QtCore.QRect(self.geometry()))
          self.animation.setEndValue(QtCore.QRect(self.geometry().adjusted(25, 25, -25, -25)))
          self.animation.setDuration(150)
          self.animation.start(QtCore.QPropertyAnimation.DeleteWhenStopped)
  
  
  class ScrollView(QtWidgets.QWidget):
  
      def __init__(self, *args, **kwargs):
          super(ScrollView, self).__init__(*args, **kwargs)
  
          self.setStyleSheet('border: 1px solid black')
  
          self.setLayout(QtWidgets.QVBoxLayout())
  
          widget = QtWidgets.QWidget()
  
          self.grid_layout = QtWidgets.QGridLayout(widget)
  
          self.scrollArea = QtWidgets.QScrollArea()
          self.scrollArea.setWidget(widget)
          self.scrollArea.setWidgetResizable(True)
  
          self.grid_layout.setSpacing(50)
  
          self.row_width = 4
  
          self._row = 0
          self._column = 0
  
          self.layout().addWidget(self.scrollArea)
  
      def addTile(self):
  
          self.grid_layout.addWidget(Tile(), self._row, self._column)
  
          if self._column == 3:
              self._row += 1
              self._column = 0
  
          else:
              self._column += 1
  
  
  def main():
      app = QtWidgets.QApplication(sys.argv)
  
      win = ScrollView()
  
      for x in range(30):
          win.addTile()
  
      win.show()
      sys.exit(app.exec())
  
  
  if __name__ == &quot;__main__&quot;:
      main()
  </code></pre>