[Qt-interest] Painting to a QImage of format Format_Indexed8?

Dave Thorup lists at kuwan.net
Wed Jun 10 20:20:15 CEST 2009


I just wanted to bump this.  At the moment I've decided not to use 8- 
bit Indexed QImages but I'd still like to know if it's possible to  
paint into them with a QPainter.  Does anyone know, officially,  
whether it's possible or not?

Thanks


On Jun 3, 2009, at 9:45 PM, Dave Thorup wrote:

I'm trying to paint into an 8-bit indexed QImage with a QPainter but  
this doesn't appear to work at all.  I set up the color table as  
follows:

QVector<QRgb>	colorTable;
QImage * pImg = new QImage( 500, 500, QImage::Format_Indexed8 );
for ( int i = 0; i < 256; i++ )
{
	colorTable.append( qRgb( i, i, i ) );
}
pImg->setColorTable( colorTable );

Then I fill the image with grey and create a QPainter for the image:

pImg->fill( 127 );	//	fill with grey
QPainter painter( pImg );

Next if I try to paint into the image then nothing happens:

painter.fillRect( 50, 50, 300, 300, QBrush( qRgb( 255, 255,  
255 ) ) );	// paint a white square

I then save the QImage to a PNG to view it and all I get is a grey  
image.  If I change the format to Format_RGB32 (and don't set the  
color table) then everything works as I would expect it to.

Is painting into QImages of Format_Indexed8 just not supported?  Any  
suggestions?

Thanks

Qt. 4.4.3, Mac OS X 10.5.7
--
Dave Thorup
Software Engineer
http://bibblelabs.com

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090610/558dd93d/attachment.html 


More information about the Qt-interest-old mailing list