PDA

View Full Version : How to merge qpixmaps in qt4.5



newqtuser
26th March 2009, 01:19
I was wondering if anyone here could look at this code and tell me what would be the best container to use for merging pixmaps and still be fast and efficient.
This code is from the practical qt book and had to modified to work with qt4.
I noticed in assistant it says that a Q3ValueList is provided to keep old code working and they strongly advise not to use it. What would be a good replacement?. Here is the code. Thanks


#include <qapplication.h>
#include <qpixmap.h>
#include <q3valuelist.h>
#include <qlabel.h>

typedef Q3ValueList<QPixmap> PixmapList;

QPixmap pixmapMerge( const PixmapList& pixmaps )
{
int width = 0;
int height = 0;

for ( PixmapList::ConstIterator it = pixmaps.begin(); it != pixmaps.end(); ++it )
{
height += (*it).height();
width = QMAX( width, (*it).width() );
}

QPixmap NewImage( width, height );

int x = 0;

for ( PixmapList::ConstIterator it2 = pixmaps.begin(); it2 != pixmaps.end(); ++it2 )
{
bitBlt( &NewImage, 0, x, &(*it2) );
x += (*it2).height();
}

return NewImage;
}

int main( int argc, char** argv )
{
QApplication app( argc, argv );

QPixmap pixmap1( "./image1.png" );
QPixmap pixmap2( "./image2.png" );
QPixmap pixmap3( "./image3.png" );


PixmapList list;

list.append(pixmap1);
list.append(pixmap2);
list.append(pixmap3);

QPixmap p = pixmapMerge( list );

QLabel* label = new QLabel( 0 );
label->setPixmap( p );
label->resize( p.size() );
label->show();

return app.exec();
}

talk2amulya
26th March 2009, 06:47
well, i guess u could use the qt3to4.exe utility that qt4 ships with..if you need more info, u should look at the article

http://doc.trolltech.com/4.0/porting4.html

for immediate answers to your query, u should use QList in ur case as the container..and also bitblt() wont work in qt4, u should use QPainter's drawPixmap()

newqtuser
26th March 2009, 14:59
Thanks for the tip. For now i switched it to a QList and it seems to be working fine. I just wasnt sure if there was anything explicitly for qpixmaps in qt4.