PDA

View Full Version : Cannot assign to pixmap during painting



fanatos
7th September 2010, 12:37
How can i fix this problem ?



QPixmap *bImage = new QPixmap(":/Tromso1.jpg");

QGraphicsPixmapItem *image;

image->setPixmap(QPixmap(bImage->scaled(QSize(200,160), Qt::KeepAspectRatio)));

scene.addItem(image);

Lykurg
7th September 2010, 12:40
What error do you get? And there is no need to create a temporary pixmap on the heap. And you are surely looking for
.

fanatos
7th September 2010, 12:45
Error msg that i get is fallowing:

QPixmap::operator=: Cannot assign to pixmap during painting

I started C++ and Qt just few weeks ago.



QPixmap *bImage = new QPixmap(":/Tromso1.jpg");

QGraphicsPixmapItem *image;

image->setPixmap(QPixmap(bImage->scaled(QSize(200,160), Qt::KeepAspectRatio)));

scene.addItem(image);

Lykurg
7th September 2010, 12:49
Whats about
image->setPixmap(bImage->scaled(QSize(200,160), Qt::KeepAspectRatio));
or
QPixmap bImage(":/Tromso1.jpg");
bImage.scale(QSize(200,160), Qt::KeepAspectRatio);
image->setPixmap(bImage);

fanatos
7th September 2010, 12:56
same problem...

i was googling and found that i am not the only one with this problem but didn't see any solutions to this.

fanatos
7th September 2010, 13:46
Also, i do this inside constructor.

aamer4yu
7th September 2010, 14:17
Where are you creating image ?
QGraphicsPixmapItem *image = new QGraphicsPixmapItem(); :rolleyes:

fanatos
9th September 2010, 16:52
i found what was the problem :)

Songg
22nd February 2016, 11:01
In my case, I called scene()->clear() before setPixmap(). So, all pointers to items becomes invalid;

d_stranz
22nd February 2016, 18:56
I am sure the original poster is delighted to see this answer, 5 1/2 years later.