title: How to draw 8 bit grayscale picture on a QPainter by reading the data from a byte array in Qt?
body: <p>I have a byte (unsigned char) array which contains some data. I have passed this buffer to a QImage and then to a QPainter. But how to get the Grayscale image? I have tried the following code in paintEvent. Please help</p>
  
  <pre><code> QPainter painter(this);
   unsigned char buf[50 * 100] = {100};
   QImage image(buf, 50, 100, 50, QImage::Format_Indexed8);
   image.setColorCount(256);
   QRect r;
   r.setX(0);
   r.setY(0);
   r.setWidth(50);
   r.setHeight(100);
   painter.drawImage(r,image,image.rect());
  </code></pre>