title: How to draw & export a transparent image with Nokia Qt C++?
body: <p>I have a piece of code intended for drawing &amp; exporting a transparent image with Nokia Qt. However, it does not work. I always see black background with lots of noise. I must fill the background with White color but I want transparency, not white color. Please kindly advise.</p>
  
  <pre><code>#include &lt;QtGui/QApplication&gt;
  #include &lt;QtGui&gt;
  
  int main(int argc, char *argv[])
  {
      QApplication app(argc, argv);
  
      {
          QImage pix(260, 50, QImage::Format_ARGB32_Premultiplied);
  
          QPainter painter(&amp;pix);
          painter.setBackgroundMode(Qt::TransparentMode);
          painter.setRenderHint(QPainter::Antialiasing, true);
          painter.setRenderHint(QPainter::TextAntialiasing, true);
          painter.setPen(QColor(0x00, 0x00, 0x00, 0xff));
          painter.setBrush(QColor(0x00, 0x00, 0x00, 0xff));
          painter.setFont(QFont("AvantGarde Md BT", 32));
          painter.setBackgroundMode(Qt::TransparentMode);
  
          // I don't like the white color, but I must put otherwise you'll see dumb &amp; black background
          painter.fillRect(0, 0, pix.width(), pix.height(), QColor(0xff, 0xff, 0xff, 0xff));
  
          QString text("My Text");
          QFontMetrics fm(painter.font());
  
          int w = fm.width(text);
          int h = fm.height();
  
          painter.drawText((pix.width() - w)/2, (pix.height() + h/2)/2, text);
          pix.save(QString("mytext.png"));
      }
  }
  </code></pre>