Convert Qstring to QPixmap
-
Hello,
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. -
I tried to used a qvariant variable to convert. But It's not working. Maybe the syntax was wrong
Can you elaborate about drawText(). -
Hi,
@pmh4514 @Gillou_beginqt means that he has full images saved in his database, not that he wants to draw text coming from his database.
@Gillou_beginqt how did you save these images ? What format to they have ?
-
@SGaist
@@
QFile file(fileName);
if (!file.open(QIODevice::ReadOnly)) return;
QString img_id,img_name;
img_id=ui->imgId->text();
int id=img_id.toInt();
img_name=ui->imgName->text();
QByteArray byteArray = file.readAll();QSqlQuery query;
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 -
Hello,
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 ?
-
Does the Drill Down Example work correctly for you ?