title: Convert a QImage to grayscale
body: <p>I have a QImage and I need to convert it to grayscale, then later paint over that with colors. I found an <code>allGray()</code> and <code>isGrayScale()</code> function to check if an image is already grayscale, but no <code>toGrayScale()</code> or similarly-named function.</p>
  
  <p>Right now I'm using this code, but it's does not have a very good performance:</p>
  
  <pre><code>for (int ii = 0; ii &lt; image.width(); ii++) {
      for (int jj = 0; jj &lt; image.height(); jj++) {
          int gray = qGray(image.pixel(ii, jj));
          image.setPixel(ii, jj, QColor(gray, gray, gray).rgb());
      }
  }
  </code></pre>
  
  <p>What would be the best way, performance-wise, to convert a QImage to grayscale?</p>