[PyQt] How: more images in Graphics View

p_tierchen 1JoS at sms.at
Wed Sep 30 18:01:31 BST 2009


Dear reader,

i recently started to develop an application in python using pyqt4 as my
first project in python. this app when feature complete should allow to
annotate photographic images with year, author, occasion, ...
right now i do some experiments on how to implement certain features. as my
research in the reference and div. other internet platforms did not yield
any usable result i would like to ask you.

one of these tests deals with loading and displaying multiple images in the
program window. is it possible to use QGraphicsScene and QGraphicsView for
this job? I tried to add images as Items to a Scene. but the only thing i
can see is the last image i added (even without list[-1]). I also tried to
use lists of Items, however it is not possible to add such list to a Scene.

The following code is the result of what i got so far:

import sys
from PyQt4 import QtGui, QtCore
from set_widget_pos_graphicslayout import Ui_MainWindow

class StartGui (QtGui.QMainWindow):
    def __init__(self, parent=None):
      QtGui.QWidget.__init__(self, parent)
      self.ui = Ui_MainWindow()
      self.ui.setupUi(self)
      self.pixmp=QtGui.QPixmap()
      self.pixitem=QtGui.QGraphicsPixmapItem()
      self.scene=QtGui.QGraphicsScene()
      self.grview=QtGui.QGraphicsView(self.ui.centralwidget)
      self.grali=[]

     
QtCore.QObject.connect(self.ui.loadButton,QtCore.SIGNAL("clicked()"),self.addIm)

    def addIm(self):
      fileName = QtGui.QFileDialog.getOpenFileName(self,
       "Open Image", "/home/jos/Fotos", "Image Files (*.png *.jpg *.bmp)");
      if fileName:
          self.pixmp.load(fileName)
          klbild=self.pixmp.scaledToHeight(200)
          self.pixitem.setPixmap(klbild)
          self.grali.append(self.pixitem)
          self.scene.addItem(self.grali[-1]) # dirty: no progress, just to
have a working code using a  list (i did not want to rewrite the code to get
rid of the list)
          self.grview.setScene(self.scene)
          self.grview.show()


if __name__ == "__main__":
    app = QtGui.QApplication(sys.argv)
    myapp = StartGui()
    myapp.show()
    sys.exit(app.exec_())

------ end code ------

i am looking forward to your advice, many thanks in advance
kind regards
Jo
-- 
View this message in context: http://www.nabble.com/How%3A-more-images-in-Graphics-View-tp25685137p25685137.html
Sent from the PyQt mailing list archive at Nabble.com.



More information about the PyQt mailing list