0
여기서 내가 뭘 잘못하고 있니? 나는 "image1.jpg"가 내가 클릭 한 위치에 "image.jpg"위에 표시 되길 기대하지만, 그렇지 않습니다. 내가 pixelSelect 방법의 끝에서 self.local_grview.setUpdatesEnabled(True)
및 업데이트하는 장면을 해봤 1QGraphicsPixmapItem이 다른 QGraphicsPixmapItem에 표시되지 않습니다
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()
편집 : self.local_grview.update()
, 아무것도
올바른 경로입니다. 두 번째 이미지 만 표시하려고 시도했지만 문제가있었습니다. 어떤 이유로 그것은 표시되지 않습니다. 나는 똑같은 것을 만들었고 (파란색 사각형 50x50 픽셀 .jpg) 이제 작동합니다. – Aleksandar