Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. QImage to QPixmap where should I add scale() If I want to set to QLable
Forum Updated to NodeBB v4.3 + New Features

QImage to QPixmap where should I add scale() If I want to set to QLable

Scheduled Pinned Locked Moved Solved Qt for Python
18 Posts 3 Posters 2.2k 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.
  • S Offline
    S Offline
    SGaist
    Lifetime Qt Champion
    wrote on 8 Jun 2021, 18:29 last edited by
    #4

    Hi,

    That's what the @mrjjle answer suggested: do not set it to true if you want to handle the resize yourself.

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

    D 1 Reply Last reply 9 Jun 2021, 09:12
    1
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 8 Jun 2021, 21:28 last edited by
      #5

      Hi
      Also scaling the bitmap to its own size won't show anything

      say if you had to labels
      alt text

      and we scale to them

      auto qimage = QImage(":/2554644-middle.png");
          {
          qimage = qimage.scaled(ui->label->width(),ui->label->height(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
          auto pixmap = QPixmap::fromImage(qimage);
          ui->label->setPixmap(pixmap);
          }
      
          {
          qimage = qimage.scaled(ui->label->width(),ui->label->height(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
          auto pixmap = QPixmap::fromImage(qimage);
          ui->label_2->setPixmap(pixmap);
          }
      

      alt text

      then i think you can see effect of KeepAspectRatio and IgnoreAspectRatio

      D 1 Reply Last reply 9 Jun 2021, 09:20
      3
      • S SGaist
        8 Jun 2021, 18:29

        Hi,

        That's what the @mrjjle answer suggested: do not set it to true if you want to handle the resize yourself.

        D Offline
        D Offline
        darrenleeleelee1
        wrote on 9 Jun 2021, 09:12 last edited by
        #6

        @SGaist ok.

        1 Reply Last reply
        0
        • M mrjj
          8 Jun 2021, 21:28

          Hi
          Also scaling the bitmap to its own size won't show anything

          say if you had to labels
          alt text

          and we scale to them

          auto qimage = QImage(":/2554644-middle.png");
              {
              qimage = qimage.scaled(ui->label->width(),ui->label->height(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
              auto pixmap = QPixmap::fromImage(qimage);
              ui->label->setPixmap(pixmap);
              }
          
              {
              qimage = qimage.scaled(ui->label->width(),ui->label->height(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
              auto pixmap = QPixmap::fromImage(qimage);
              ui->label_2->setPixmap(pixmap);
              }
          

          alt text

          then i think you can see effect of KeepAspectRatio and IgnoreAspectRatio

          D Offline
          D Offline
          darrenleeleelee1
          wrote on 9 Jun 2021, 09:20 last edited by
          #7

          @mrjj

          qimage = QtGui.QImage(arr.data, arr.shape[1], arr.shape[0], arr.shape[1]*2, QtGui.QImage.Format_Grayscale16).copy()
                  qimage = qimage.scaled(self.photo.width(), self.photo.height(), QtCore.Qt.IgnoreAspectRatio, QtCore.Qt.SmoothTransformation)
                  pixmap = QtGui.QPixmap.fromImage(qimage)
                  self.photo.setPixmap(pixmap)
          

          did you mean this?But it still not wok.print(self.photo.hasScaledContents()) this return False.

          M 1 Reply Last reply 9 Jun 2021, 09:54
          0
          • D darrenleeleelee1
            9 Jun 2021, 09:20

            @mrjj

            qimage = QtGui.QImage(arr.data, arr.shape[1], arr.shape[0], arr.shape[1]*2, QtGui.QImage.Format_Grayscale16).copy()
                    qimage = qimage.scaled(self.photo.width(), self.photo.height(), QtCore.Qt.IgnoreAspectRatio, QtCore.Qt.SmoothTransformation)
                    pixmap = QtGui.QPixmap.fromImage(qimage)
                    self.photo.setPixmap(pixmap)
            

            did you mean this?But it still not wok.print(self.photo.hasScaledContents()) this return False.

            M Offline
            M Offline
            mrjj
            Lifetime Qt Champion
            wrote on 9 Jun 2021, 09:54 last edited by
            #8

            @darrenleeleelee1
            Hi
            hmm, I cant guess why.
            for me, it clearly ignores the AspectRatio.

            Maybe your picture is perfectly square?

            D 1 Reply Last reply 9 Jun 2021, 09:57
            0
            • M mrjj
              9 Jun 2021, 09:54

              @darrenleeleelee1
              Hi
              hmm, I cant guess why.
              for me, it clearly ignores the AspectRatio.

              Maybe your picture is perfectly square?

              D Offline
              D Offline
              darrenleeleelee1
              wrote on 9 Jun 2021, 09:57 last edited by
              #9

              @mrjj no, It's(2235, 3408)

              M 1 Reply Last reply 9 Jun 2021, 09:59
              0
              • D darrenleeleelee1
                9 Jun 2021, 09:57

                @mrjj no, It's(2235, 3408)

                M Offline
                M Offline
                mrjj
                Lifetime Qt Champion
                wrote on 9 Jun 2021, 09:59 last edited by
                #10

                @darrenleeleelee1

                ok.

                what are
                photo.width() and self.photo.height()

                D 1 Reply Last reply 9 Jun 2021, 13:41
                0
                • M mrjj
                  9 Jun 2021, 09:59

                  @darrenleeleelee1

                  ok.

                  what are
                  photo.width() and self.photo.height()

                  D Offline
                  D Offline
                  darrenleeleelee1
                  wrote on 9 Jun 2021, 13:41 last edited by
                  #11

                  @mrjj (512, 512)

                  M 1 Reply Last reply 9 Jun 2021, 14:56
                  0
                  • D darrenleeleelee1
                    9 Jun 2021, 13:41

                    @mrjj (512, 512)

                    M Offline
                    M Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on 9 Jun 2021, 14:56 last edited by
                    #12

                    @darrenleeleelee1

                    Hi
                    I tried with the same sizes as you, found image at (2235, 3408) also

                    alt text

                    alt text

                    So not why you always seems to see the same.

                    What Qt version are you using ?

                    D 1 Reply Last reply 10 Jun 2021, 06:04
                    1
                    • M mrjj
                      9 Jun 2021, 14:56

                      @darrenleeleelee1

                      Hi
                      I tried with the same sizes as you, found image at (2235, 3408) also

                      alt text

                      alt text

                      So not why you always seems to see the same.

                      What Qt version are you using ?

                      D Offline
                      D Offline
                      darrenleeleelee1
                      wrote on 10 Jun 2021, 06:04 last edited by darrenleeleelee1 6 Oct 2021, 06:06
                      #13

                      @mrjj
                      4d78dd71-1242-4dcf-aead-373f43c746a1-image.png
                      You use scale for QImage not QPixmap?

                      M 1 Reply Last reply 10 Jun 2021, 06:08
                      0
                      • D darrenleeleelee1
                        10 Jun 2021, 06:04

                        @mrjj
                        4d78dd71-1242-4dcf-aead-373f43c746a1-image.png
                        You use scale for QImage not QPixmap?

                        M Offline
                        M Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on 10 Jun 2021, 06:08 last edited by
                        #14

                        @darrenleeleelee1

                        Hi
                        Yes.

                        {
                            qimage = qimage.scaled(ui->label->width(),ui->label->height(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
                            auto pixmap = QPixmap::fromImage(qimage);
                            ui->label->setPixmap(pixmap);
                            }
                        
                        D 1 Reply Last reply 10 Jun 2021, 06:26
                        1
                        • M mrjj
                          10 Jun 2021, 06:08

                          @darrenleeleelee1

                          Hi
                          Yes.

                          {
                              qimage = qimage.scaled(ui->label->width(),ui->label->height(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
                              auto pixmap = QPixmap::fromImage(qimage);
                              ui->label->setPixmap(pixmap);
                              }
                          
                          D Offline
                          D Offline
                          darrenleeleelee1
                          wrote on 10 Jun 2021, 06:26 last edited by
                          #15

                          @mrjj What is the different if I am scale to QPixmap

                          M 1 Reply Last reply 10 Jun 2021, 06:49
                          0
                          • D darrenleeleelee1
                            10 Jun 2021, 06:26

                            @mrjj What is the different if I am scale to QPixmap

                            M Offline
                            M Offline
                            mrjj
                            Lifetime Qt Champion
                            wrote on 10 Jun 2021, 06:49 last edited by
                            #16

                            @darrenleeleelee1

                            Hi
                            as far as I know, nothing.
                            Both return a scaled copy.

                            I cant see anything wrong with the code you shown. So unless its a bug in 5.9.7
                            i really have no idea why the images look the same to you.

                            Also, you scale it down a lot so there should always be an effect.

                            D 1 Reply Last reply 10 Jun 2021, 08:45
                            1
                            • M mrjj
                              10 Jun 2021, 06:49

                              @darrenleeleelee1

                              Hi
                              as far as I know, nothing.
                              Both return a scaled copy.

                              I cant see anything wrong with the code you shown. So unless its a bug in 5.9.7
                              i really have no idea why the images look the same to you.

                              Also, you scale it down a lot so there should always be an effect.

                              D Offline
                              D Offline
                              darrenleeleelee1
                              wrote on 10 Jun 2021, 08:45 last edited by
                              #17

                              @mrjj OK, thanks, I found I was not put two Image together like you do.And I miss the change.Thanks you alot.Sorry bother you.

                              M 1 Reply Last reply 10 Jun 2021, 09:43
                              1
                              • D darrenleeleelee1
                                10 Jun 2021, 08:45

                                @mrjj OK, thanks, I found I was not put two Image together like you do.And I miss the change.Thanks you alot.Sorry bother you.

                                M Offline
                                M Offline
                                mrjj
                                Lifetime Qt Champion
                                wrote on 10 Jun 2021, 09:43 last edited by
                                #18

                                @darrenleeleelee1

                                ahh. Well that explains why they look so much the same :)
                                No worries, its no bother at all.

                                1 Reply Last reply
                                1

                                13/18

                                10 Jun 2021, 06:04

                                • Login

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