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:
Code:
pixmap
( 0,
0 ) = new QPixmap( "Image00.png" );
pixmap
( 0,
1 ) = new QPixmap( "Image01.png" );
pixmap
( 0,
2 ) = new QPixmap( "Image02.png" );
.
.
.
pixmap( 9,
9 ) = new QPixmap( "Image99.png" );
pixmapItem( 0, 0 ).setPixmap( *pixmap( 0, 0 ) );
pixmapItem( 0, 0 ).setPos( -370, -370 );
pixmapItem( 0, 1 ).setPixmap( *pixmap( 0, 1 ) );
pixmapItem( 0, 1 ).setPos( -296, -370 );
pixmapItem( 0, 2 ).setPixmap( *pixmap( 0, 2 ) );
pixmapItem( 0, 2 ).setPos( -222, -370 );
.
.
.
pixmapItem( 9, 9 ).setPixmap( *pixmap( 9, 9 ) );
pixmapItem( 9, 9 ).setPos( 296, 296 );
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?
Re: Arrays of QPixmaps and QGraphicsPixmapItems
Have you tried something like the following (untested)?
Code:
QVector< QVector<
QPixmap > > pixmap_array;
pixmap_array.resize(10);
for (int i = 0; i < pixmap_array.size(); i++)
{
pixmap_array[i].resize(10);
}
...
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,
_
Re: Arrays of QPixmaps and QGraphicsPixmapItems
Yes,
That looks like it should work.
I'll give it a try.
Thanks!