以下代码应创建 QGraphicsView 小部件,该小部件拥有一个 QGraphicsScene,其中包含文本:
#!/usr/bin/python
import sys
from PyQt4.QtGui import *
if __name__ == '__main__':
app = QApplication(sys.argv)
view = QGraphicsView()
scene = QGraphicsScene()
scene.addText("Hello!")
view.setScene(scene)
view.show();
sys.exit(app.exec_())
这会打开窗口,将文本放在那里,但在我关闭窗口后 - python 转储核心并打印出几个问题:
(python:5387): Gtk-CRITICAL **: IA__gtk_container_add: assertion `GTK_IS_CONTAINER (container)' failed
(python:5387): Gtk-CRITICAL **: IA__gtk_widget_realize: assertion `GTK_WIDGET_ANCHORED (widget) || GTK_IS_INVISIBLE (widget)' failed
...clip...
... above message is shown many, many times ...
...clip...
(python:5387): Gtk-CRITICAL **: IA__gtk_widget_realize: assertion `GTK_WIDGET_ANCHORED (widget) || GTK_IS_INVISIBLE (widget)' failed
Segmentation fault (core dumped)
版本:python2.7 2.7.3-0ubuntu3.1 python-qt4 4.9.1-2ubuntu1