Results 1 to 4 of 4

Thread: Arrays of QPixmaps and QGraphicsPixmapItems

  1. #1
    Join Date
    Apr 2016
    Posts
    23
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Arrays of QPixmaps and QGraphicsPixmapItems

    I would like to build up a QGraphicsScene using a 10x10 arrangement of QGraphicsPixmapItems (a chessboard with a border). Something like this:

    Pseudocode:

    Qt Code:
    1. QPixmap *pixmap( 10, 10 );
    2. pixmap( 0, 0 ) = new QPixmap( "Image00.png" );
    3. pixmap( 0, 1 ) = new QPixmap( "Image01.png" );
    4. pixmap( 0, 2 ) = new QPixmap( "Image02.png" );
    5. .
    6. .
    7. .
    8. pixmap( 9, 9 ) = new QPixmap( "Image99.png" );
    9.  
    10. QGraphicsPixmapItem pixmapItem( 10, 10 );
    11. pixmapItem( 0, 0 ).setPixmap( *pixmap( 0, 0 ) );
    12. pixmapItem( 0, 0 ).setPos( -370, -370 );
    13. pixmapItem( 0, 1 ).setPixmap( *pixmap( 0, 1 ) );
    14. pixmapItem( 0, 1 ).setPos( -296, -370 );
    15. pixmapItem( 0, 2 ).setPixmap( *pixmap( 0, 2 ) );
    16. pixmapItem( 0, 2 ).setPos( -222, -370 );
    17. .
    18. .
    19. .
    20. pixmapItem( 9, 9 ).setPixmap( *pixmap( 9, 9 ) );
    21. pixmapItem( 9, 9 ).setPos( 296, 296 );
    To copy to clipboard, switch view to plain text mode 

    But there doesn't seem to be any way to make arrays of QPixmaps or arrays of QGraphicsPixmapItems; at least not anywhere that I've seen in the docs.

    Am I missing something?

    Or could anyone suggest a workable line of attack?

  2. #2
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: Arrays of QPixmaps and QGraphicsPixmapItems

    Have you tried something like the following (untested)?

    Qt Code:
    1. QVector< QVector< QPixmap > > pixmap_array;
    2. pixmap_array.resize(10);
    3.  
    4. for (int i = 0; i < pixmap_array.size(); i++)
    5. {
    6. pixmap_array[i].resize(10);
    7. }
    8.  
    9. pixmap_array[0][0] = QPixmap(...);
    10. pixmap_array[0][1] = QPixmap(...);
    11. ...
    12. pixmap_array[9][9] = QPixmap(...);
    To copy to clipboard, switch view to plain text mode 
    I write the best type of code possible, code that I want to write, not code that someone tells me to write!

  3. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Arrays of QPixmaps and QGraphicsPixmapItems

    And don't allocate QPixmap on the heap, that just means you will have to manually delete them again.

    Cheers,
    _

  4. #4
    Join Date
    Apr 2016
    Posts
    23
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Arrays of QPixmaps and QGraphicsPixmapItems

    Yes,

    That looks like it should work.

    I'll give it a try.

    Thanks!

Similar Threads

  1. Replies: 2
    Last Post: 15th August 2012, 00:12
  2. Reusing QPixmaps in QGraphicsPixmapItems - is it possible?
    By Tito in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 5th October 2010, 15:07
  3. Replies: 0
    Last Post: 15th April 2010, 07:42
  4. How to merge two QPixmaps in to one.
    By live_07 in forum Qt Programming
    Replies: 2
    Last Post: 23rd September 2009, 08:19
  5. QGraphicsPixmapItems through QGLWidget - clearing textures?
    By robertson1 in forum Qt Programming
    Replies: 1
    Last Post: 16th October 2008, 23:08

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.