我正在用PyQt4编程一个GUI,并希望嵌入一个Pygame显示作为一个中心小部件。在
我有一个QMainWindow,它使用另一个类中的pygame元素作为中心小部件。我已经尝试过使用pygame曲面,目前为止效果很好。。。但我担心的是,pygame的表面是用来在屏幕上绘制图像的。例如,pygame.display.update()
不能与公共曲面一起工作。在
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()
我只想知道如何在我的PyQt4主窗口中嵌入pygame显示。目前我有一个内部有一个圆圈的表面,但从长远来看,我认为这是行不通的。在
目前没有回答
相关问题 更多 >
编程相关推荐