0

What am I doing wrong here? I expect that "image1.jpg" is shown over "image.jpg" ,at position where I've clicked, but it does not. Here is my code (image1.jpg is 10 times smaller then image.jpg):

import sys
from PyQt4 import QtGui, QtCore
from PyQt4.QtGui import *
from PyQt4.QtCore import * 

class DrawImage(QMainWindow): 
    def __init__(self, parent=None):
        super(QMainWindow, self).__init__(parent)
        self.setWindowTitle('Select Window')
        self.local_image = QImage('image.JPG')
        self.local_grview = QGraphicsView()
        self.setCentralWidget( self.local_grview )
        self.local_scene = QGraphicsScene()
        self.image_format = self.local_image.format()
        self.pixMapItem = QGraphicsPixmapItem(QPixmap(self.local_image), None, self.local_scene)
        self.pixMapItem.setZValue(10.0)
        self.local_grview.setScene( self.local_scene )
        self.pixMapItem.mousePressEvent = self.pixelSelect

    def pixelSelect( self, event ):
        position = QPoint( event.pos().x(),  event.pos().y())
        local_image = QImage('image1.JPG')
        pixMapItem = QGraphicsPixmapItem(QPixmap(local_image), self.pixMapItem, self.local_scene)
        pixMapItem.setZValue(100.0)
        pixMapItem.setPos(position.x(), position.y());
        print position, self.pixMapItem.zValue(), pixMapItem.zValue()

def main():
    app = QtGui.QApplication(sys.argv)
    form = DrawImage()
    form.show()
    app.exec_()

if __name__ == '__main__':
    main()

Edit 1 I've tried self.local_grview.setUpdatesEnabled(True) and updating scene at the end of pixelSelect method: self.local_grview.update() , nothing changed

Aleksandar
  • 3,541
  • 4
  • 34
  • 57

1 Answers1

0

Your code looks correct and works as expected for me ie. the second smaller image displays over the first.

Have you tried displaying just the second image? Perhaps you have an incorrect path which is causing your second image not to show.

Tim Wakeham
  • 1,029
  • 1
  • 8
  • 12
  • Path is correct. I've tried displaying second image only and there was a problem. For some reason it won't display. I've created exactly the same one (blue square 50x50 pixels .jpg) and it works now. – Aleksandar Sep 02 '13 at 07:39