Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Get rid of the</p> <pre><code>self.myLabel.setScaledContents(True) </code></pre> <p>call (or set it to False). It is filling your widget with the pixmap without caring about the aspect ratio.</p> <p>If you need to resize a <code>QPixmap</code>, as you have found, <code>scaled</code> is the required method. But you are invoking it wrong. Let's look at the definition:</p> <pre><code>QPixmap QPixmap.scaled (self, int width, int height, Qt.AspectRatioMode aspectRatioMode = Qt.IgnoreAspectRatio, Qt.TransformationMode transformMode = Qt.FastTransformation) </code></pre> <p>Return type of this function is <code>QPixmap</code>, so it returns a scaled <em>copy</em> of the original pixmap.</p> <p>Then you need a <code>width</code> and a <code>height</code>, describing the (maximum) final size of the pixmap.</p> <p>Two more optional parameters. <code>aspectRatioMode</code> deals with the, well aspect ratio. The <a href="http://developer.qt.nokia.com/doc/qt-4.8/qpixmap.html#scaled">documentation</a> details the different options and their effects. <code>transformMode</code> defines how (which algorithm) the scaling is done. It might change the final quality of your image. You probably don't need this one.</p> <p>So, putting it together you should have (<code>Qt</code> namespace is inside <code>QtCore</code>):</p> <pre><code># substitute the width and height to desired values self.myLabel.setPixmap(QtGui.QPixmap(_fromUtf8(directory + '\\' + tempName)).scaled(width, height, QtCore.Qt.KeepAspectRatio)) </code></pre> <p>Alternatively, if you have a fixed size <code>QLabel</code>, you could call the <code>.size()</code> method to get the size from it:</p> <pre><code>self.myLabel.setPixmap(QtGui.QPixmap(_fromUtf8(directory + '\\' + tempName)).scaled(self.myLabel.size(), QtCore.Qt.KeepAspectRatio)) </code></pre> <p><strong>Note</strong>: You might want to use <code>os.path.join(directory, tempName)</code> for the <code>directory + '\\' + tempName</code> part.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload