我一直在使用Qt設計建立一個GUI,桂有一箇中央物件是一個水平佈局,和孩子這是QGraphicView(名稱leftImage和右圖)Qt設計的QGraphicsView負荷圖像
在菜單欄中我'已經創建了兩個按鈕 - 「打開左側圖像」和「打開右側圖像」
我已經設法使用這個按鈕(它打開打開對話框並正確選擇正確的文件),但我看不到GUI上的圖像。
這是我的代碼:
#!/usr/bin/env python
import sys
from PyQt4 import QtCore, QtGui, uic
form_class = uic.loadUiType("try2gui.ui")[0]
class MyWindowClass(QtGui.QMainWindow, form_class):
def __init__(self, parent=None):
QtGui.QMainWindow.__init__(self, parent)
self.setupUi(self)
self.initMenu()
image = QtGui.QImage('image.pgm')
self.LeftImage = QtGui.QPixmap(image)
self.RightImage = QtGui.QPixmap(image)
self.show()
def initMenu (self):
self.actionOpen_Left.triggered.connect(self.open_left)
self.actionOpen_Right.triggered.connect(self.open_Right)
self.actionExit.triggered.connect(self.close)
def open_left(self):
fileName = QtGui.QFileDialog.getOpenFileName(self, "Open File", QtCore.QDir.currentPath())
if fileName:
image = QtGui.QImage(fileName)
if image.isNull():
QtGui.QMessageBox.information(self, "Image Viewer", "Cannot load %s." % fileName)
return
self.centralwidget.LeftImage = QtGui.QPixmap(image)
self.scaleFactor = 1.0
print fileName
def open_Right(self):
fileName = QtGui.QFileDialog.getOpenFileName(self, "Open File", QtCore.QDir.currentPath())
if fileName:
image = QtGui.QImage(fileName)
if image.isNull():
QtGui.QMessageBox.information(self, "Image Viewer", "Cannot load %s." % fileName)
return
self.RightImage = QtGui.QPixmap(image)
self.scaleFactor = 1.0
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
myWindow = MyWindowClass(None)
myWindow.show()
app.exec_()
我怎樣才能更新GUI看到加載的圖像?