我正在使用带有 Eric5 和 QTDesigner 的 Python 3.2 来尝试在 QGraphicsView 场景中显示 jpg。以下代码给了我一个 无法打开的文件。原因:[Errno 22] Invalid argument:" error on the first pass and end with a 调试程序引发异常未处理的 AttributeError "'MyForm' 对象没有属性 'QGraphicsView'" 文件:,行:17
引用的 screentest.ui 文件只是表单上的一个简单的 QGraphicsView 对象框。
非常感谢任何建议。
#UIGraphicTest.py
import sys
# from PyQt4 import QtCore
from PyQt4 import QtGui
from screentest import Ui_MainWindow
class MyForm(QtGui.QMainWindow):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
myapp = MyForm()
grview = myapp.QGraphicsView()
scene = myapp.QGraphicsScene()
scene.addPixmap(QtGui.QPixmap('att-logo.jpg'))
grview.setScene(scene)
myapp.show()
sys.exit(app.exec_())