Convert Qstring to QPixmap
I am working on project where I have to display image saved in my database into different scene using QGraphicScene. The images are query in string but I am not able to display them in the different scene.
pmh4514 last edited by
what have you tried already?
You will not be "converting" a QString to QPixmap, rather, you have to drawText(..) to it.
I tried to used a qvariant variable to convert. But It's not working. Maybe the syntax was wrong
Can you elaborate about drawText().
@Gillou_beginqt how did you save these images ? What format to they have ?
if (!file.open(QIODevice::ReadOnly)) return;
QByteArray byteArray = file.readAll();
query.prepare("INSERT INTO images(image_id,image_name,images) VALUES (?,?,?)");
query.addBindValue(id); query.addBindValue(img_name); query.addBindValue(byteArray); query.exec();
This is the code I used to saved the images in my database. They are in QBytearray
c.savur last edited by
when you save the image to database, save as unsigned char and save size of the image then you can generate image by following :
QImage(const uchar * data, int width, int height, Format format);
then you can convert the QPixmap
QPixmap pixmap = QPixmap::fromImage(img);
After you have Qpixmap you can add to scene by using QGraphicsPixmapItem.
How to save as unsigned char and save the size of the image
How are you constructing the image from the database ?
Gillou_beginqt last edited by Gillou_beginqt
@SGaist I was planning to use the code of the drill down example but I am not able to display the pictures from my database
Does the Drill Down Example work correctly for you ?