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. Appending an image to itemList of QFormLayout widgets
Forum Updated to NodeBB v4.3 + New Features

Appending an image to itemList of QFormLayout widgets

Scheduled Pinned Locked Moved Unsolved General and Desktop
51 Posts 4 Posters 6.0k Views 3 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.
  • C Offline
    C Offline
    CEO.
    wrote on last edited by
    #38

    I have finally resolved the issue:

    I decided to make the retrieved data display in the qtablewidget with the image displaying inside the qtablewidget (as a png, or jpg file) as it is retrieved from the database, so the varbinary texts no longer displays in the qtablewidget.

    Then I use the .loadData() method in displaying it there. I was able to resolve the appendSelection function and get the displayed image of the qtablewidget to display also in the qlabel qpixmap reserved for it in the qformlayout. This resolved the appending issue for me:

                                                  if (col == 2) and itemArray:
                                  
                                                      img = itemArray.data(QTableWidgetItem.UserType)
                                  
                                                      pixmap = QPixmap()
                                  
                                                      pixmap.loadFromData(img, 'jpg')
                                  
                                                      itemList[2].setPixmap(pixmap)
    
    mrjjM 1 Reply Last reply
    1
    • C CEO.

      I have finally resolved the issue:

      I decided to make the retrieved data display in the qtablewidget with the image displaying inside the qtablewidget (as a png, or jpg file) as it is retrieved from the database, so the varbinary texts no longer displays in the qtablewidget.

      Then I use the .loadData() method in displaying it there. I was able to resolve the appendSelection function and get the displayed image of the qtablewidget to display also in the qlabel qpixmap reserved for it in the qformlayout. This resolved the appending issue for me:

                                                    if (col == 2) and itemArray:
                                    
                                                        img = itemArray.data(QTableWidgetItem.UserType)
                                    
                                                        pixmap = QPixmap()
                                    
                                                        pixmap.loadFromData(img, 'jpg')
                                    
                                                        itemList[2].setPixmap(pixmap)
      
      mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #39

      @CEO

      Super.
      So it helped not to store it in Linedit first but in a user role and
      hence it was not broken and could convert to image ?

      C 1 Reply Last reply
      0
      • mrjjM mrjj

        @CEO

        Super.
        So it helped not to store it in Linedit first but in a user role and
        hence it was not broken and could convert to image ?

        C Offline
        C Offline
        CEO.
        wrote on last edited by
        #40

        @mrjj yes and I was so happy and exclaimed EUREKA! immediately it worked fine. I now understand the joy Archimedes felt when the idea of upthrust struck him while bathing to the extent he had to run out of his bathroom naked. lol

        mrjjM 1 Reply Last reply
        1
        • C CEO.

          @mrjj yes and I was so happy and exclaimed EUREKA! immediately it worked fine. I now understand the joy Archimedes felt when the idea of upthrust struck him while bathing to the extent he had to run out of his bathroom naked. lol

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #41

          @CEO

          hehe well good :)
          thx for the feedback. I learn by knowing what was wrong so it was as i
          guessed at. the binary stream didn't like to be in lineedit first.

          C 1 Reply Last reply
          0
          • mrjjM mrjj

            @CEO

            hehe well good :)
            thx for the feedback. I learn by knowing what was wrong so it was as i
            guessed at. the binary stream didn't like to be in lineedit first.

            C Offline
            C Offline
            CEO.
            wrote on last edited by CEO.
            #42

            @mrjj

            .

            I wanna update the retrieved image which is displayed in jpg format. How do I go about it plz?

            The image label (i.e the qpixmap label) is self.passlb

             if (col == 2) and itemArray:
                                img = itemArray.data(QTableWidgetItem.UserType)
                                pixmap = QPixmap()
                                pixmap.loadFromData(img, 'jpg')
                                itemList[2].setPixmap((pixmap).scaled(250,250))
            

            So in my sql update statement, I tried:

                         values(self.fullname.text(),
                         self.passlb.pixmap()
            ...)```
            
            It didn't work.
            
            Do you think it should be:
            
                   img.pixmap() or img.text() or img.read()
            Any clue about the method I should use in updating a qpixmap label?
            mrjjM 1 Reply Last reply
            0
            • C CEO.

              @mrjj

              .

              I wanna update the retrieved image which is displayed in jpg format. How do I go about it plz?

              The image label (i.e the qpixmap label) is self.passlb

               if (col == 2) and itemArray:
                                  img = itemArray.data(QTableWidgetItem.UserType)
                                  pixmap = QPixmap()
                                  pixmap.loadFromData(img, 'jpg')
                                  itemList[2].setPixmap((pixmap).scaled(250,250))
              

              So in my sql update statement, I tried:

                           values(self.fullname.text(),
                           self.passlb.pixmap()
              ...)```
              
              It didn't work.
              
              Do you think it should be:
              
                     img.pixmap() or img.text() or img.read()
              Any clue about the method I should use in updating a qpixmap label?
              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by mrjj
              #43

              Hi
              You mean save an actual pixmap back to the database ?`

              But what is the type of field in the db and how did you get the other images in there ?

              Its clear we need to convert it to a binary stream and we can use QBuffer for that

              (c++, could not find python example)

                  QPixmap inPixmap =self.passlb.pixmap(); 
                  QByteArray inByteArray;
                  QBuffer inBuffer( &inByteArray );
                  inBuffer.open( QIODevice::WriteOnly );
                  inPixmap.save( &inBuffer, "PNG" ); // write inPixmap into inByteArray in PNG format
              

              inBuffer can now be saved in DB.

              But I wonder if there is the reverse of io.BytesIO ? we should rather use ?

              C 1 Reply Last reply
              0
              • mrjjM mrjj

                Hi
                You mean save an actual pixmap back to the database ?`

                But what is the type of field in the db and how did you get the other images in there ?

                Its clear we need to convert it to a binary stream and we can use QBuffer for that

                (c++, could not find python example)

                    QPixmap inPixmap =self.passlb.pixmap(); 
                    QByteArray inByteArray;
                    QBuffer inBuffer( &inByteArray );
                    inBuffer.open( QIODevice::WriteOnly );
                    inPixmap.save( &inBuffer, "PNG" ); // write inPixmap into inByteArray in PNG format
                

                inBuffer can now be saved in DB.

                But I wonder if there is the reverse of io.BytesIO ? we should rather use ?

                C Offline
                C Offline
                CEO.
                wrote on last edited by CEO.
                #44

                @mrjj sorry,

                See this function, it's for uploading images in the form for update:

                def openfile(self):
                    try:
                        fname, _ = QFileDialog.getOpenFileName(self, 'Open', 'c:\\', "image Files (*.jpg *.png)")
                        self.passlb.setPixmap(QPixmap(fname).scaled(250, 250))
                        self.img = open(fname, 'rb')
                        self.psptpath.setText(fname)
                        # self.pixL.setText(strfn)
                        print(self.pixlb.setText(''))
                

                This function is for appending the jpg to the qlabel self.passlb from the qtable after it's been retrieved from the database:

                       if (col ==2):
                       img = itemArray.data(QTableWidgetItem.UserType)
                                               pixmap = QPixmap()
                                               pixmap.loadFromData(img, 'jpg')
                                               itemList[2].setPixmap((pixmap).scaled(250,250))
                

                Then here is my sql statement updating the image:
                (The usual update statement is here)
                values (self.fullname.text(),
                self.img.read()
                )

                This is saying my program objects has no attribute 'img'

                mrjjM C 3 Replies Last reply
                0
                • C CEO.

                  @mrjj sorry,

                  See this function, it's for uploading images in the form for update:

                  def openfile(self):
                      try:
                          fname, _ = QFileDialog.getOpenFileName(self, 'Open', 'c:\\', "image Files (*.jpg *.png)")
                          self.passlb.setPixmap(QPixmap(fname).scaled(250, 250))
                          self.img = open(fname, 'rb')
                          self.psptpath.setText(fname)
                          # self.pixL.setText(strfn)
                          print(self.pixlb.setText(''))
                  

                  This function is for appending the jpg to the qlabel self.passlb from the qtable after it's been retrieved from the database:

                         if (col ==2):
                         img = itemArray.data(QTableWidgetItem.UserType)
                                                 pixmap = QPixmap()
                                                 pixmap.loadFromData(img, 'jpg')
                                                 itemList[2].setPixmap((pixmap).scaled(250,250))
                  

                  Then here is my sql statement updating the image:
                  (The usual update statement is here)
                  values (self.fullname.text(),
                  self.img.read()
                  )

                  This is saying my program objects has no attribute 'img'

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #45

                  @CEO
                  ah well its better with such logical bug than something that just don't work :)

                  C 1 Reply Last reply
                  0
                  • C CEO.

                    @mrjj sorry,

                    See this function, it's for uploading images in the form for update:

                    def openfile(self):
                        try:
                            fname, _ = QFileDialog.getOpenFileName(self, 'Open', 'c:\\', "image Files (*.jpg *.png)")
                            self.passlb.setPixmap(QPixmap(fname).scaled(250, 250))
                            self.img = open(fname, 'rb')
                            self.psptpath.setText(fname)
                            # self.pixL.setText(strfn)
                            print(self.pixlb.setText(''))
                    

                    This function is for appending the jpg to the qlabel self.passlb from the qtable after it's been retrieved from the database:

                           if (col ==2):
                           img = itemArray.data(QTableWidgetItem.UserType)
                                                   pixmap = QPixmap()
                                                   pixmap.loadFromData(img, 'jpg')
                                                   itemList[2].setPixmap((pixmap).scaled(250,250))
                    

                    Then here is my sql statement updating the image:
                    (The usual update statement is here)
                    values (self.fullname.text(),
                    self.img.read()
                    )

                    This is saying my program objects has no attribute 'img'

                    C Offline
                    C Offline
                    CEO.
                    wrote on last edited by
                    #46

                    @mrjj please see this.

                    1 Reply Last reply
                    0
                    • C CEO.

                      @mrjj sorry,

                      See this function, it's for uploading images in the form for update:

                      def openfile(self):
                          try:
                              fname, _ = QFileDialog.getOpenFileName(self, 'Open', 'c:\\', "image Files (*.jpg *.png)")
                              self.passlb.setPixmap(QPixmap(fname).scaled(250, 250))
                              self.img = open(fname, 'rb')
                              self.psptpath.setText(fname)
                              # self.pixL.setText(strfn)
                              print(self.pixlb.setText(''))
                      

                      This function is for appending the jpg to the qlabel self.passlb from the qtable after it's been retrieved from the database:

                             if (col ==2):
                             img = itemArray.data(QTableWidgetItem.UserType)
                                                     pixmap = QPixmap()
                                                     pixmap.loadFromData(img, 'jpg')
                                                     itemList[2].setPixmap((pixmap).scaled(250,250))
                      

                      Then here is my sql statement updating the image:
                      (The usual update statement is here)
                      values (self.fullname.text(),
                      self.img.read()
                      )

                      This is saying my program objects has no attribute 'img'

                      C Offline
                      C Offline
                      CEO.
                      wrote on last edited by
                      #47

                      @CEO said in Appending an image to itemList of QFormLayout widgets:

                      @mrjj sorry,

                      See this function, it's for uploading images in the form for update:

                      def openfile(self):
                          try:
                              fname, _ = QFileDialog.getOpenFileName(self, 'Open', 'c:\\', "image Files (*.jpg *.png)")
                              self.passlb.setPixmap(QPixmap(fname).scaled(250, 250))
                              self.img = open(fname, 'rb')
                              self.psptpath.setText(fname)
                              # self.pixL.setText(strfn)
                              print(self.pixlb.setText(''))
                      

                      This function is for appending the jpg to the qlabel self.passlb from the qtable after it's been retrieved from the database:

                             if (col ==2):
                             img = itemArray.data(QTableWidgetItem.UserType)
                                                     pixmap = QPixmap()
                                                     pixmap.loadFromData(img, 'jpg')
                                                     itemList[2].setPixmap((pixmap).scaled(250,250))
                      

                      Then here is my sql statement updating the image:
                      (The usual update statement is here)
                      values (self.fullname.text(),
                      self.img.read()
                      )

                      This is saying my program objects has no attribute 'img'

                      @mrjj

                      1 Reply Last reply
                      0
                      • mrjjM mrjj

                        @CEO
                        ah well its better with such logical bug than something that just don't work :)

                        C Offline
                        C Offline
                        CEO.
                        wrote on last edited by
                        #48

                        @mrjj I did some testing and discovered it works fine only when I update the photo. Updating any other column without updating the image (photo) produces an error saying no object found for the image column.

                        mrjjM 1 Reply Last reply
                        0
                        • C CEO.

                          @mrjj I did some testing and discovered it works fine only when I update the photo. Updating any other column without updating the image (photo) produces an error saying no object found for the image column.

                          mrjjM Offline
                          mrjjM Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on last edited by
                          #49

                          @CEO
                          But does it says that self.img don't exists ?

                          but in def openfile(self):

                          self.img = open(fname, 'rb')

                          works

                          so is the function that uses the SQL, also part of the same class ?

                          C 1 Reply Last reply
                          0
                          • mrjjM mrjj

                            @CEO
                            But does it says that self.img don't exists ?

                            but in def openfile(self):

                            self.img = open(fname, 'rb')

                            works

                            so is the function that uses the SQL, also part of the same class ?

                            C Offline
                            C Offline
                            CEO.
                            wrote on last edited by
                            #50

                            @mrjj the function that uses the SQL is part of the class. It works fine when in my update I upload a photo but comes up with that error "object has no attribute 'img' " if I don't upload a photo (i.e when I leave the photo retrieved from the database). Meaning even if I upload the same photo there, it will work. It just wants the upload to be done in that pixmap field

                            mrjjM 1 Reply Last reply
                            0
                            • C CEO.

                              @mrjj the function that uses the SQL is part of the class. It works fine when in my update I upload a photo but comes up with that error "object has no attribute 'img' " if I don't upload a photo (i.e when I leave the photo retrieved from the database). Meaning even if I upload the same photo there, it will work. It just wants the upload to be done in that pixmap field

                              mrjjM Offline
                              mrjjM Offline
                              mrjj
                              Lifetime Qt Champion
                              wrote on last edited by
                              #51

                              So when loading from db, you need to both set the UserRole and the pixmap field
                              it sounds like even the error "object has no attribute 'img' " is very confusing
                              if it is indeed a class member.

                              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