Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Convert Qstring to QPixmap
Qt 6.11 is out! See what's new in the release blog

Convert Qstring to QPixmap

Scheduled Pinned Locked Moved General and Desktop
qpixmapqstringqgraphicsitem
10 Posts 4 Posters 9.0k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • P Offline
      P Offline
      pmh4514
      wrote on last edited by
      #2

      what have you tried already?
      You will not be "converting" a QString to QPixmap, rather, you have to drawText(..) to it.

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        I tried to used a qvariant variable to convert. But It's not working. Maybe the syntax was wrong
        Can you elaborate about drawText().

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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 ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          ? 1 Reply Last reply
          0
          • SGaistS SGaist

            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 ?

            ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #5

            @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

            1 Reply Last reply
            0
            • c.savurC Offline
              c.savurC Offline
              c.savur
              wrote on last edited by
              #6

              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.

              Qimage Doc. t

              1 Reply Last reply
              1
              • ? Offline
                ? Offline
                A Former User
                wrote on last edited by
                #7

                How to save as unsigned char and save the size of the image

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  How are you constructing the image from the database ?

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  ? 1 Reply Last reply
                  0
                  • SGaistS SGaist

                    How are you constructing the image from the database ?

                    ? Offline
                    ? Offline
                    A Former User
                    wrote on last edited by A Former User
                    #9

                    @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

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      Does the Drill Down Example work correctly for you ?

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved