title: QPixmap with a transparent part
body: <p>I'm making a simple puzzle game. The piece is a square and it contains the corresponding part of an image. What I need to do is to change the shape from the square to the common puzzle shape. I've made a template in Photoshop:</p>
  
  <p>Corner piece</p>
  
  <p><img src="https://i.stack.imgur.com/694rS.png" alt=""></p>
  
  <p>Now I need somehow to use it as a mask to change the shape of my square piece. I tried the following:</p>
  
  <pre><code>QImage temp;
  temp.load("://Templates/c1.png");
  temp = temp.convertToFormat(QImage::Format_Mono);
  QBitmap bit;
  bit = QBitmap::fromImage(temp);
  puz-&gt;img.setMask(bit);
  </code></pre>
  
  <p>Where <code>puzzle-&gt;img</code> is my square piece. It works, but I get "rough corners" in the connectors. I suppose all of half-transparent pixels become fully filled with a color (or fully transparent?), so that's why it doesn't look smooth.</p>
  
  <p>Is there a way to make it smoothier? </p>
  
  <p>UPDATE: I tried a different approach: since <code>setAlphaChannel()</code> is an obsolete function, documentation says that I need to use <code>QPainter::CompositionMode</code>. I tried the following </p>
  
  <pre><code>void puzzle::paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget )
  {
     painter-&gt;setCompositionMode(QPainter::CompositionMode_Source);
     painter-&gt;fillRect(x, y, 90, 90, Qt::transparent);
     painter-&gt;setCompositionMode(QPainter::CompositionMode_SourceOver);
     painter-&gt;drawPixmap(x, y, 90, 90, img);
     painter-&gt;setCompositionMode(QPainter::CompositionMode_DestinationIn);
     painter-&gt;drawImage(x,y, mask);
  }
  </code></pre>
  
  <p>It works like that in <a href="http://doc.qt.io/qt-5/qtwidgets-painting-imagecomposition-example.html" rel="nofollow noreferrer">Image Composition example</a>, but I get black pixels instead of transparent in my project: <a href="https://i.stack.imgur.com/LrdHL.png" rel="nofollow noreferrer">Output</a>. Can't figure out, what's wrong. <code>mask</code> initialization:</p>
  
  <pre><code>mask.load("://Templates/c1.png");
  mask = mask.scaled(90, 90, Qt::KeepAspectRatio, Qt::SmoothTransformation);
  mask = mask.convertToFormat(QImage::Format_ARGB32_Premultiplied);
  </code></pre>