title: QT Layout different for different buttons
body: <p>I have a grid layout that creates a grid no problem.</p>
  
  <p>I have created buttons from A-J which coincide with the grid.</p>
  
  <p>The current display is:</p>
  
  <p><a href="https://i.stack.imgur.com/rMRJX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rMRJX.png" alt="enter image description here"></a></p>
  
  <p>I want to layout the A-J buttons to correspond with the grid.</p>
  
  <p><a href="https://i.stack.imgur.com/b5vTT.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/b5vTT.png" alt="enter image description here"></a></p>
  
  <p>How can I achieve this Layout in PyQt5?</p>
  
  <pre><code>import sys
  from PyQt5.QtWidgets import QLabel, QStyle, QApplication, QWidget, QPushButton, QHBoxLayout, QGroupBox, QDialog, QVBoxLayout, QGridLayout
  from PyQt5.QtGui import QPen, QPainter, QFont, QIcon, QPixmap, QPalette, QLinearGradient, QColor, QBrush, QCursor
  from PyQt5.QtCore import pyqtSlot, Qt
  
  grid = [[0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0]]
  
  BTN ='font-weight: bold; color: {};font-size: 14px; background-color: {}; padding: 20px;border-width: 2px; border-radius: 50px;'
  
  class _QPushButton(QPushButton):
      def __init__(self, parent=None):
          super(_QPushButton, self).__init__(parent)
          self.setCursor(QCursor(Qt.PointingHandCursor))   
  
  class App(QDialog):
  
      def __init__(self):
          super().__init__()
  
          self.left = 10
          self.top = 10
          self.width = 1200
          self.height = 800
          self.initUI()
  
      def initUI(self):
  
          # Background
          p = QPalette()
          gradient = QLinearGradient(0, 0, 0, 400)
          gradient.setColorAt(0.0, QColor('#f1f1f1'))
          gradient.setColorAt(1.0, QColor('#00a1de'))
          p.setBrush(QPalette.Window, QBrush(gradient))
          self.setPalette(p)
          self.setGeometry(self.left, self.top, self.width, self.height)
  
          self.btnA = _QPushButton('A')
          self.btnB = _QPushButton('B')
          self.btnC = _QPushButton('C')
          self.btnD = _QPushButton('D')
          self.btnE = _QPushButton('E')
          self.btnF = _QPushButton('F')
          self.btnG = _QPushButton('G')
          self.btnH = _QPushButton('H')
          self.btnI = _QPushButton('I')
          self.btnJ = _QPushButton('J') 
  
          self.createGridLayout()
  
          windowLayout = QHBoxLayout()
  
          for i in range(len(grid[0])):
              print(i)
              lbl = QLabel()
              lbl.setText(str(i+1))
              windowLayout.addWidget(lbl)
  
          windowLayout.addWidget(self.btnA)
          windowLayout.addWidget(self.btnB)
          windowLayout.addWidget(self.btnC)
          windowLayout.addWidget(self.btnD)
          windowLayout.addWidget(self.btnE)
          windowLayout.addWidget(self.btnF)
          windowLayout.addWidget(self.btnG)
          windowLayout.addWidget(self.btnH)
          windowLayout.addWidget(self.btnI)
          windowLayout.addWidget(self.btnJ)
          windowLayout.addWidget(self.horizontalGroupBox)
          self.setLayout(windowLayout)
          self.center_widget()
  
          self.show()
  
      def createGridLayout(self):
          font = QFont("Sans Serif", )
          font.setPixelSize(18)
  
          self.horizontalGroupBox = QGroupBox()
          self.horizontalGroupBox.setFont(font)
          layout = QGridLayout()
          for i in range(0, len(grid)):
              for j in range(0, len(grid[1])):                
                  try:     
                      btn = _QPushButton(str(grid[i][j][0]))
                      if grid[i][j][1] == 'GREEN':
                          btn.setStyleSheet(BTN.format('white', 'green'))
                          layout.addWidget(btn, i, j)
                      elif grid[i][j][1] == 'RED':
                          btn.setStyleSheet(BTN.format('white', 'red'))
                          layout.addWidget(btn, i, j)
                  except Exception as e:
                      btn = _QPushButton(str(grid[i][j]))
                      btn.setStyleSheet(BTN.format('black', 'white'))
                      layout.addWidget(btn, i, j)
                      # print(grid[i][j][0], e)                
  
  
          self.horizontalGroupBox.setLayout(layout)
  
      def center_widget(self):
          self.window().setGeometry(
                  QStyle.alignedRect(
                      Qt.LeftToRight, 
                      Qt.AlignCenter,
                      self.window().size(), 
                      QApplication.desktop().availableGeometry())        
          )   
  
  
  
  if __name__ == '__main__':
      app = QApplication(sys.argv)
      ex = App()
      sys.exit(app.exec_())
  </code></pre>