[PyQt] image tool

David Boddie dboddie at trolltech.com
Tue Aug 18 12:18:19 BST 2009


On Tue Aug 18 09:18:33 BST 2009, vidyadhar wrote:

> how should i scale the image to fit to the size of dock widget.?
> i have used scaling in pixmap.
>
> here is my code
>
>         self.edit_image=str(self.imagePath)
>         pic=QtGui.QPixmap(self.edit_image)
>         width=self.dockWidget_4.geometry().width()
>         height=self.dockWidget_4.geometry().height()
>
> self.label.setPixmap(pic.scaled(width,height,QtCore.Qt.IgnoreAspectRatio,Qt
>Core.Qt.SmoothTransformation)) self.label.setScaledContents(True)
>
> is some other way out?

Yes, set the scaledContents property of the label instead of scaling the
pixmap yourself:

  self.label.setScaledContents(True)

David


More information about the PyQt mailing list