質問

I recently implemented an image viewer in my app, based on the example here:

MousePressEvent, position offset in QGraphicsView"

Here is how my subclass of QGraphicsView is written:

from PyQt4 import QtGui, QtCore


class GraphicsViewPerso(QtGui.QGraphicsView):


    def __init__(self,  parent = None):

        super(GraphicsViewPerso, self).__init__(parent)
        self.parent = parent


    def wheelEvent(self, event):

        super(GraphicsViewPerso, self).wheelEvent(event)

        self.setTransformationAnchor(GraphicsViewPerso.AnchorUnderMouse)
        factor = 1.2
        if event.delta() < 0 :
            factor = 1.0 / factor
        self.scale(factor, factor)

But I noticed with this solution, even when my pictures are in high resolution, I have bad rendering. I can zoom, but the picture is not clear, like if I had loaded the low-res version of it.

Any idea why I have this behavior ?

役に立ちましたか?

解決

Ok, after a while, I finally found what was the problem. I was displaying the picture like this:

     w_vue, h_vue = self.vision.width(), self.vision.height() 
    self.current_image = QtGui.QImage(path_mosaic)
    self.pixmap = QtGui.QPixmap.fromImage(self.current_image.scaled(w_vue, h_vue,
                                QtCore.Qt.KeepAspectRatio, 
                                QtCore.Qt.SmoothTransformation)) 

    w_pix, h_pix = self.pixmap.width(), self.pixmap.height()

    self.scene = QtGui.QGraphicsScene()

    self.scene.setSceneRect(0, 0, w_pix , h_pix - 10)
    self.scene.addPixmap(self.pixmap)
    self.vision.setScene(self.scene)

While the pixmap declaration should have been this, simply: self.pixmap = QtGui.QPixmap(self.current_image)

Nothing to do with the QGraphicsView.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top