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. QPixmap increasing size issue
Forum Updated to NodeBB v4.3 + New Features

QPixmap increasing size issue

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 2 Posters 1.6k Views 1 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.
  • KiraK Offline
    KiraK Offline
    Kira
    wrote on last edited by
    #1

    Hello All,
    I have a qlabel which i am using to display a camera image.

    void ImageLabel::ShowImage(cv::Mat image)
    {
        QImage img = QImage(image.data, image.cols, image.rows, (int) image.step, QImage::Format_RGB888);
        QPixmap pixmap = QPixmap::fromImage(img).scaled(this->width(),this->height(), Qt::KeepAspectRatio);
        this->setPixmap(pixmap);
        this->setBaseSize(pixmap.size());
        _logger.LogInfo("QPixmap width= %d height= %d", pixmap.size().width(), pixmap.size().height());
        //this->setFixedSize(pixmap.size());
        this->repaint();
    }
    
    • My problem is when I call ShowImage(cv::Mat image) function QPixmap size(both height and width) increase by a fixed number. The size of the label keeps on increasing which misplaces the other widgets on the UI form.

    • If use the following : //this->setFixedSize(pixmap.size()); the size of the widget do not crease but i have no idea whether the aspect ratio is maintained.

    • Can anybody let me know why the size of qlabel increases when I call the ShowImage(cv::Mat image) ?

    jsulmJ 1 Reply Last reply
    0
    • KiraK Kira

      Hello All,
      I have a qlabel which i am using to display a camera image.

      void ImageLabel::ShowImage(cv::Mat image)
      {
          QImage img = QImage(image.data, image.cols, image.rows, (int) image.step, QImage::Format_RGB888);
          QPixmap pixmap = QPixmap::fromImage(img).scaled(this->width(),this->height(), Qt::KeepAspectRatio);
          this->setPixmap(pixmap);
          this->setBaseSize(pixmap.size());
          _logger.LogInfo("QPixmap width= %d height= %d", pixmap.size().width(), pixmap.size().height());
          //this->setFixedSize(pixmap.size());
          this->repaint();
      }
      
      • My problem is when I call ShowImage(cv::Mat image) function QPixmap size(both height and width) increase by a fixed number. The size of the label keeps on increasing which misplaces the other widgets on the UI form.

      • If use the following : //this->setFixedSize(pixmap.size()); the size of the widget do not crease but i have no idea whether the aspect ratio is maintained.

      • Can anybody let me know why the size of qlabel increases when I call the ShowImage(cv::Mat image) ?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Kira said in QPixmap increasing size issue:

      this->setBaseSize(pixmap.size());

      Is it the same if you comment out this line?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      KiraK 2 Replies Last reply
      0
      • jsulmJ jsulm

        @Kira said in QPixmap increasing size issue:

        this->setBaseSize(pixmap.size());

        Is it the same if you comment out this line?

        KiraK Offline
        KiraK Offline
        Kira
        wrote on last edited by
        #3

        Is it the same if you comment out this line?

        @jsulm : Yes

        1 Reply Last reply
        0
        • jsulmJ jsulm

          @Kira said in QPixmap increasing size issue:

          this->setBaseSize(pixmap.size());

          Is it the same if you comment out this line?

          KiraK Offline
          KiraK Offline
          Kira
          wrote on last edited by
          #4

          @jsulm: I was going through the following link :
          Resizing QLabel using resizeEvent()
          There its mentioned:
          It is not advisable to modify the original QPixmap since changing its size modifies the pixels and you will get an unexpected effect.

          In my case, I am setting pixmap each time. Can this be the reason ?

          jsulmJ 1 Reply Last reply
          0
          • KiraK Kira

            @jsulm: I was going through the following link :
            Resizing QLabel using resizeEvent()
            There its mentioned:
            It is not advisable to modify the original QPixmap since changing its size modifies the pixels and you will get an unexpected effect.

            In my case, I am setting pixmap each time. Can this be the reason ?

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @Kira You're not loading in resizeEvent, right? And you create a new pixmap each time, so I don't think this has any relevance.

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            KiraK 1 Reply Last reply
            0
            • jsulmJ jsulm

              @Kira You're not loading in resizeEvent, right? And you create a new pixmap each time, so I don't think this has any relevance.

              KiraK Offline
              KiraK Offline
              Kira
              wrote on last edited by Kira
              #6

              @jsulm said in QPixmap increasing size issue:

              @Kira You're not loading in resizeEvent, right? And you create a new pixmap each time, so I don't think this has any relevance.

              No, I am not using any resizeEvent().

              1 Reply Last reply
              0
              • KiraK Offline
                KiraK Offline
                Kira
                wrote on last edited by
                #7
                This post is deleted!
                1 Reply Last reply
                0
                • KiraK Offline
                  KiraK Offline
                  Kira
                  wrote on last edited by
                  #8

                  @jsulm: I the label growing issue is resolved using the following thread
                  Reszing qlabel issue
                  Where it mentioned setting the QSizePolicy as ignored. So my doubt is would setting the above property would still maintain my aspect ratio ??

                  jsulmJ 1 Reply Last reply
                  0
                  • KiraK Kira

                    @jsulm: I the label growing issue is resolved using the following thread
                    Reszing qlabel issue
                    Where it mentioned setting the QSizePolicy as ignored. So my doubt is would setting the above property would still maintain my aspect ratio ??

                    jsulmJ Offline
                    jsulmJ Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    @Kira said in QPixmap increasing size issue:

                    So my doubt is would setting the above property would still maintain my aspect ratio ??

                    You can just try

                    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