How to add a pixmap drawn in QGraphicsItem to QGraphicsScene in the following example?

Qt Code:
  1. #!/usr/bin/env python
  2.  
  3. from PyQt5.QtCore import (QLineF, QPointF, QRectF, pyqtSignal)
  4. from PyQt5.QtGui import (QIcon, QBrush, QColor, QPainter, QPixmap)
  5. from PyQt5.QtWidgets import (QAction, QMainWindow, QApplication, QGraphicsObject, QGraphicsView, QGraphicsScene, QGraphicsItem,
  6.  
  7. class TicTacToe(QGraphicsItem):
  8. def __init__(self, helper):
  9. super(TicTacToe, self).__init__()
  10.  
  11. self.mypixmap = QPixmap("exit.png")
  12.  
  13. self.painte = QPainter()
  14.  
  15. def paint(self, painter, option, widget):
  16. self.painte.setOpacity(0.1)
  17. self.painte.drawPixmap(0,0, 300, 300, self.mypixmap)
  18.  
  19.  
  20. def boundingRect(self):
  21. return QRectF(0,0,300,300)
  22.  
  23.  
  24. class MyGraphicsView(QGraphicsView):
  25. def __init__(self):
  26. super(MyGraphicsView, self).__init__()
  27. scene = QGraphicsScene(self)
  28.  
  29. self.tic_tac_toe = TicTacToe(self)
  30.  
  31. scene.addItem(self.tic_tac_toe)
  32.  
  33. scene.addPixmap(self.tic_tac_toe)
  34.  
  35. self.setScene(scene)
  36.  
  37. class Example(QMainWindow):
  38. def __init__(self):
  39. super(Example, self).__init__()
  40.  
  41. self.y = MyGraphicsView()
  42. self.setCentralWidget(self.y)
  43.  
  44. if __name__ == '__main__':
  45. import sys
  46. app = QApplication(sys.argv)
  47. w = Example()
  48. w.show()
  49. sys.exit(app.exec_())
To copy to clipboard, switch view to plain text mode