[PyQt] Help me please. About PIL.Image PyQt QGraphicsView MDIArea

chaow pchaow at gmail.com
Mon Jul 4 19:07:35 BST 2011


I want to create an Image Processing Program, just like Photoshop. 
I use  MDIArea, and SubWindows to show an image.

first i call function from main ui when i press a button.

def bnLoadImageClicked(self):
       imgFile = QtGui.QFileDialog.getOpenFileName(
                       self,
                       "Open Image File",
                       "D:/qtproject/ocr",
                       "ImCGraphicsViewage Files (*.jpg *.jpeg *.png)"
                   )
       if imgFile :               
            
           subwin = QtGui.QMdiSubWindow()
           curWidget = CImageWidget(subwin)
           subwin.setWidget(curWidget)
           subwin.setAttribute(QtCore.Qt.WA_DeleteOnClose)
           self.maMain.addSubWindow(subwin)    
           curWidget.show()
           curWidget.imgFile = imgFile
           curWidget.loadImage()

and CImageWidget.loadImage() the result : Image is show.
def loadImage(self):
       self.gvImage.resetCachedContent()
       #pixmap = QtGui.QPixmap(self.imgFile)
       scene.addItem(QtGui.QGraphicsPixmapItem(pixmap))   
       self.gvImage.setScene(scene)
       self.gvImage.show()

but when i modify this function to show image from PIL.Image, It dosn't
work!!!!.

def loadImage(self):
       self.gvImage.resetCachedContent()
       img = Image.open(str(self.imgFile))
       scene = QtGui.QGraphicsScene(self.gvImage)
       #scene.setSceneRect(self.gvImage.rect())
       img2 = ImageQt.ImageQt(img)
       img3 = QtGui.QImage(img2)
       pixmap = QtGui.QPixmap.fromImage(img2)
       #pixmap = QtGui.QPixmap(self.imgFile)
       scene.addItem(QtGui.QGraphicsPixmapItem(pixmap))
        
       self.gvImage.setScene(scene)
       self.gvImage.show()

please help me. I want to display an image from pil image because i want to
use numpy's array to manipulate that image.
-- 
View this message in context: http://old.nabble.com/Help-me-please.-About-PIL.Image-PyQt-QGraphicsView-MDIArea-tp31990915p31990915.html
Sent from the PyQt mailing list archive at Nabble.com.



More information about the PyQt mailing list