Results 1 to 4 of 4

Thread: QGraphicsPixmapItem as an array?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2014
    Posts
    27
    Thanks
    9
    Qt products
    Qt5
    Platforms
    Windows

    Default QGraphicsPixmapItem as an array?

    Hi, I need to save images in an array, but I tried some things, but still not working, need help.
    I'm trying to use and set values to a QGraphicsPixmapItem Array (using C++ arrays) and using QList too.

    My code here:
    Qt Code:
    1. QGraphicsPixmapItem pixmapArray[n*m];
    2. for(int i=0;i<n;i++){
    3. for(int j=0;j<m;j++){
    4. QPixmap *icon = new QPixmap(list.at(biDiArray[i][j])); //list of a QString
    5. image.setPixmap(*icon);
    6. pixmapArray[i*10+j] = image;
    7. }
    8. }
    To copy to clipboard, switch view to plain text mode 

    I tried to use it as QList too, but didn't work.

    Qt Code:
    1. for(int i=0;i<this->n;i++){
    2. for(int j=0;j<this->m;j++){
    3. QPixmap *icon = new QPixmap(list.at(mat[i][j]));
    4. this->pixmapItemList.insert(10*i+j,*image);
    5. }
    6. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    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: QGraphicsPixmapItem as an array?

    If you have an array of items, then you need to call setPixmap on those items, not on local instances.

    If you want to create items in the loop, then use an array or list of the item pointer type.

    Cheers,
    _

    P.S.: don't create QPixmap on the heap unless you really need to, currently you are leaking memory.

Similar Threads

  1. QGraphicsPixmapItem
    By erfan in forum Qt Programming
    Replies: 1
    Last Post: 13th June 2012, 21:54
  2. Cast QString array to std::string array
    By Ishtar in forum Newbie
    Replies: 4
    Last Post: 15th July 2011, 08:28
  3. Replies: 2
    Last Post: 12th November 2010, 14:42
  4. declare an array of QSemaphore and array of slot functions
    By radeberger in forum Qt Programming
    Replies: 11
    Last Post: 2nd May 2010, 13:24
  5. Shape of QGraphicsPixmapItem
    By StefanHirche in forum Newbie
    Replies: 4
    Last Post: 5th September 2007, 15:14

Tags for this Thread

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.