Results 1 to 3 of 3

Thread: How to merge qpixmaps in qt4.5

  1. #1
    Join Date
    Jul 2008
    Posts
    18
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default How to merge qpixmaps in qt4.5

    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();
    }

  2. #2
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to merge qpixmaps in qt4.5

    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()

  3. #3
    Join Date
    Jul 2008
    Posts
    18
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to merge qpixmaps in qt4.5

    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.

Similar Threads

  1. How to merge two QPixmaps in to one.
    By babu198649 in forum Newbie
    Replies: 1
    Last Post: 17th August 2008, 13:59
  2. how to merge QPixmaps
    By tommy in forum Qt Programming
    Replies: 2
    Last Post: 27th March 2008, 12:02

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.