So this is what I have. I'm trying your last comment Anda, but I'm doing something wrong.
I have a few labels, which I put inside a QGridLayout, and then I'm trying to put it into the scroll area, but I'm getting an error on line 34
The Error says
TypeError: scrollArea.setWidget(QWidget) : argument 1 has unexpected type (QGridLayout)
Qt Code:
  1. class ViewerLabel(QLabel):
  2. def __init__(self, parent=None):
  3. super(ViewerLabel, self).__init__(parent)
  4. self.setMouseTracking(True)
  5. self.setAlignment(Qt.AlignCenter)
  6.  
  7. def enterEvent(self,event):
  8. button.setStyleSheet("background-color:#45b545;")
  9.  
  10. def leaveEvent(self,event):
  11. button.setStyleSheet("background-color:yellow;")
  12.  
  13. def main():
  14.  
  15. layout = QGridLayout()
  16. scrollArea = QScrollArea()
  17.  
  18. label_01 = ViewerLabel(“label 01”)
  19. label_02 = ViewerLabel(“label 02”)
  20. label_03 = ViewerLabel(“label 03”)
  21. label_04 = ViewerLabel(“label 04”)
  22. label_05 = ViewerLabel(“label 05”)
  23. label_06 = ViewerLabel(“label 06”)
  24.  
  25. layout.addwidget(label_01, 0, 1)
  26. layout.addwidget(label_02, 0, 2)
  27. layout.addwidget(label_03, 1, 1)
  28. layout.addwidget(label_04, 1, 2)
  29. layout.addwidget(label_05, 2, 1)
  30. layout.addwidget(label_06, 2, 2)
  31.  
  32. layout.setSpacing(10)
  33.  
  34. scrollArea.setWidget(layout)
  35. window.setLayout(scrollArea)
  36.  
  37. window.setFixedSize(400,500)
  38. window.show()
  39.  
  40. return app.exec_()
  41.  
  42.  
  43. if __name__ == __main__:
  44. main()
To copy to clipboard, switch view to plain text mode