Okay I wrote a short script, the code you sent is missing the
connection, plus I don't know what "addPixmap" is, so here is a small
version of what I think you are trying to do.  

If you aren't sublcassing the QGraphicsView, you can do the same thing I
am doing via the .scene() to get the QGraphicsScene


mbs


>Thanks for the hint
>
>but i have QGraphicsview widget not graphicscene, how can i implement
>QgraphicsPixmapItem?
>
>so far i came with this, is it correct?
>files = QFileDialog.getOpenFileNames(self, self.trUtf8("Add
>documentation"),
> QString("/home"), self.trUtf8("Images (*.png *.tiff *.jpg)")) 
>               for file_ in files:
>                       data = ""
>                       f = open(file_)
>                       #data = file.read()
>                       self.listWidget.addItem(file_)
>                self.listWidget.setItemSelected(file_)
>                self.my_list_item.text(file_)
>                self.photosdisplay.addPixmap(file_)
>but nothing happened when i clicked?
import sys
from PyQt4 import QtGui, QtCore

class MainWin(QtGui.QWidget):
    """
        A widget with a list view and a graphics view
    """
    def __init__(self):
        QtGui.QWidget.__init__(self)
        layout = QtGui.QHBoxLayout()
        
        #list view
        self.listwidge = QtGui.QListWidget()
        layout.addWidget(self.listwidge)
        
        #graphics view
        self.gv = MyView()
        layout.addWidget(self.gv)
        
        self.connect(self.listwidge,QtCore.SIGNAL("itemClicked(QListWidgetItem *)"),self.updatePicture)
        
        self.setLayout(layout)
        
        #get image files
        
        files = QtGui.QFileDialog.getOpenFileNames()
        
        self.listwidge.addItems(files)
        
        #create a dictionary of {filename:Qpixmap}
        self.mm = {}
        for item in files:
            new_item = QtGui.QPixmap(item)
            self.mm[str(item)]=new_item
            
    def updatePicture(self,qli):
        """
            use a filename to get the appropriate qimage
        """
        qpix = self.mm[str(qli.text())]
        self.gv.updatePicture(qpix)
        
class MyView(QtGui.QGraphicsView):
    def __init__(self):
        QtGui.QGraphicsView.__init__(self)
        self.scene = QtGui.QGraphicsScene(self)
        
        #current item
        self.item = QtGui.QGraphicsEllipseItem(20, 20, 40, 20)
        self.item.setPos(20,20)
        
        self.scene.addItem(self.item)
        self.setScene(self.scene)
        
    def updatePicture(self,qpix):
        self.scene.removeItem(self.item)
        self.item = QtGui.QGraphicsPixmapItem(qpix)
        self.scene.addItem(self.item)
        
if __name__ == '__main__':
    app = QtGui.QApplication(sys.argv)
    view = MainWin()
    view.show()
    sys.exit(app.exec_())

_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Reply via email to