I've build a GUI using Qt Designer, the Gui have a central widget which is a horizontal layout, and children which are QGraphicView (name leftImage and RightImage)
In the menu bar I've created two buttons - "open left image" and "open right image"
I've manage to use this buttons (it opens the open dialog and choose the right file correctly), but I can't see the images on the GUI.
This is my code:
#!/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_()
How can I update the GUI to see the loaded Image?
I've found a solution:
I've changed the open-left function to be: (same goes to open_right):
and it works now