[PyQt] Re: Zoom or scale into an QImage

Markus Feldmann feldmann_markus at gmx.de
Thu Feb 12 20:31:31 GMT 2009


I got an error Message:
unhandled AttributeError "imgLabel"

I think he can not find this Attribute, but i am not sure.
I have defined "imgLabel" in the <__init__(self, parent=None)> Class-Method.

Do i have to make <self.imgLabel> a Class-Attribute to
call it from another Class-Method ?
What should be Class Attributes ?

Here comes a snippet of my Code:
#################################################
     def __init__(self, parent=None):
         QMainWindow.__init__(self, parent)
...

         self.scrollArea = QScrollArea()
         self.imgLabel = QLabel()
         self.image = QImage("./media/images/aventurien.jpg")
         self.imgLabel.setBackgroundRole(QPalette.Dark)
         self.imgLabel.setScaledContents(True)
         self.imgLabel.setPixmap(QPixmap.fromImage(self.image))
         self.scrollArea.setWidget(self.imgLabel)
         self.scrollArea.setBackgroundRole(QPalette.Dark)
         self.setCentralWidget(self.scrollArea)
...


     def scaleImage(self, factor):
         assert self.imgLabel.pixmap() is not None
         self.scalefactor *= factor
         self.imgLabel.resize(scalefactor * self.imgLabel.pixmap().size())
         self.adjustScrollBar(self.scrollArea.horizontalScrollBar(), factor)
         self.adjustScrollBar(self.scrollArea.verticalScrollBar(), factor)
         self.zoomInAct.setEnabled(scaleFactor < 3.0)
         self.zoomOutAct.setEnabled(scaleFactor > 0.333)
...
##############################################################################



More information about the PyQt mailing list