I am programming a GUI with PyQt4 and want to embed a Pygame display as a central widget.
I have a QMainWindow which uses a pygame element from another class as a central Widget. I already tried to use a pygame surface and it worked so far... but I'm worried about the fact, that pygame surface is made for drawing images to the screen. For example pygame.display.update()
doesn't work with a common surface.
class GameWidget(QWidget):
def __init__(self, width, height, parent=None):
super(GameWidget, self).__init__(parent)
pygame.init()
surface = pygame.Surface((width * 1.3, height * 0.4))
surface.fill((64, 128, 192, 224))
w=surface.get_width()
h=surface.get_height()
pygame.draw.circle(surface, (255, 255, 255, 255), (300, 300), 50)
self.data=surface.get_buffer().raw
self.image=QtGui.QImage(self.data,w,h,QtGui.QImage.Format_RGB32)
def paintEvent(self,event):
qp=QtGui.QPainter()
qp.begin(self)
qp.drawImage(width / 7, height / 6, self.image)
qp.end()
class MainWindow(QtGui.QMainWindow):
def __init__(self, width, height, parent=None):
super(MainWindow, self).__init__(parent)
self.setCentralWidget(GameWidget(height, width))
self.setGeometry(200, 50, width, height)
self.show()
I just want to know how to embed a pygame display in my PyQt4 MainWindow. At the moment I have a surface with a circle inside but on the long run I think this won't work.