I need to write a std::vector< double >
values to a qGraphicsScene
. (values between 0-1, each element represents a pixel - grayscale)
Later i want to access the pixels of the image for replace the color (i don't have time to replace the whole image)
thx. for the answer!
Asked
Active
Viewed 4,242 times
-3
1 Answers
2
If you're wanting to do such low level modification, I'd recommend taking a look at the QImage class. Members such as QImage::setPixel will give you access to individual pixels for modification.
If you need this kind of functionality on a QGraphicsScene, then you could draw to the QImage and then convert that to a QPixmap (with QPixmap::convertFromImage) for use with a QGraphicsPixmapItem, and then place the QGraphicsPixmapItem onto the scene.
You may want to take a look at the generic Qt containers, such as QVector as well.

Eli Hooten
- 994
- 2
- 9
- 23
-
This works well if i load the entire image, but is there any solution to access the pixels after i have loaded the scene? – Denes May 07 '12 at 19:08
-
A quick and dirty approach would store the QImages in some data structure (`QHash
`? I'm not sure what your needs are). When you need to edit, edit the `QImage`, then set the `QPixmap` on the appropriate item to the edited `QImage`. Although this approach might have efficiency drawbacks depending on the implementation. You may benefit from reading about [Qt's implicit sharing](http://doc.qt.nokia.com/4.7-snapshot/implicit-sharing.html) mechanisms. – Eli Hooten May 07 '12 at 22:22 -
Denes, did this help you, was it a suitable answer? If so, please mark your question as answered. – Eli Hooten May 09 '12 at 14:14
-
I try'd this, but this will change the whole image (and calculate the pixmap) every time when i change just one pixel. My problem is like a video, and if i get a new frame (stored in the vector) i would like to show immadiatly on the GUI. – Denes May 09 '12 at 16:54
-
If you're using the Graphics View Framework I cannot think of many other ways to accomplish this. If you need to update parts of a QImage, you can do so by performing a dirty update on just the part of the image that has changed since the last paintEvent of its parent widget. The [Qt Scribble tutorial](http://qt-project.org/doc/qt-4.8/widgets-scribble.html) explains how to do this. I'm not immediately sure if you can pair it with a graphics scene, though. Maybe using the QGraphicsProxyWidget? In this case you'd be working with QImage parented to a QWidget, circumventing QPixmap altogether. – Eli Hooten May 09 '12 at 20:26