我试图在 pyside gui 中初始化一个空白 QImage 小部件,但它抛出错误,我无法从文档中弄清楚我应该做什么,有谁知道我需要做什么步骤才能让这个 QImage 小部件工作
import sys
from PySide import QtGui, QtCore
import os
class ms_ImageViewer(QtGui.QWidget):
def __init__(self):
super(ms_ImageViewer, self).__init__()
self.initUI()
def initUI(self):
main_layout = QtGui.QVBoxLayout()
self.setLayout(main_layout)
self.image = QtGui.QImage(50, 50, QtGui.QImage.Format_Indexed8)
self.image.fill(QtGui.qRgb(50,50,50))
button = QtGui.QPushButton('select file', self)
main_layout.addWidget(button)
main_layout.addWidget(self.image)
self.setGeometry(300, 300, 600, 30)
self.setWindowTitle('ms_image_viewer')
self.show()
def main():
app = QtGui.QApplication(sys.argv)
ex = ms_ImageViewer()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
这是我得到的错误:
/projects/Mayaseed/src/tools/ms_image_viewer.py
Traceback (most recent call last):
File "/projects/Mayaseed/src/tools/ms_image_viewer.py", line 34, in <module>
main()
File "/projects/Mayaseed/src/tools/ms_image_viewer.py", line 29, in main
ex = ms_ImageViewer()
File "/projects/Mayaseed/src/tools/ms_image_viewer.py", line 9, in __init__
self.initUI()
File "/projects/Mayaseed/src/tools/ms_image_viewer.py", line 20, in initUI
main_layout.addWidget(self.image)
TypeError: 'PySide.QtGui.QBoxLayout.addWidget' called with wrong argument types:
PySide.QtGui.QBoxLayout.addWidget(PySide.QtGui.QImage)
Supported signatures:
PySide.QtGui.QBoxLayout.addWidget(PySide.QtGui.QWidget, int = 0, PySide.QtCore.Qt.Alignment = 0)