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. Pixmap zoom problem
Forum Updated to NodeBB v4.3 + New Features

Pixmap zoom problem

Scheduled Pinned Locked Moved Solved General and Desktop
11 Posts 3 Posters 4.4k 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.
  • O Offline
    O Offline
    ofmrew
    wrote on last edited by
    #1

    I am using Qt5.10 on Mint Linux and when I zoom out on a pixmap I loose part of the image, which is strictly lines. I draw the pixmap using:

    QPainter p(this);
        p.setRenderHint(QPainter::SmoothPixmapTransform);
        p.drawPixmap(this->rect(), *blocks, source);
    

    The addition of the hint made it better but did not fix the problem. The pixmap was created with the lines drawn at a width of 5. Is there some setting I am missing?
    Zoomed in
    zoomed in
    Zoomed out
    zoomed out

    Same area both images.

    raven-worxR 1 Reply Last reply
    0
    • O ofmrew

      I am using Qt5.10 on Mint Linux and when I zoom out on a pixmap I loose part of the image, which is strictly lines. I draw the pixmap using:

      QPainter p(this);
          p.setRenderHint(QPainter::SmoothPixmapTransform);
          p.drawPixmap(this->rect(), *blocks, source);
      

      The addition of the hint made it better but did not fix the problem. The pixmap was created with the lines drawn at a width of 5. Is there some setting I am missing?
      Zoomed in
      zoomed in
      Zoomed out
      zoomed out

      Same area both images.

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @ofmrew
      try also to enable antialiasing:

      p.setRenderHint(QPainter::Antialiasing);
      

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      O 1 Reply Last reply
      0
      • raven-worxR raven-worx

        @ofmrew
        try also to enable antialiasing:

        p.setRenderHint(QPainter::Antialiasing);
        
        O Offline
        O Offline
        ofmrew
        wrote on last edited by
        #3

        @raven-worx Better, but do not fix the problem. Thanks.

        O 1 Reply Last reply
        0
        • O ofmrew

          @raven-worx Better, but do not fix the problem. Thanks.

          O Offline
          O Offline
          ofmrew
          wrote on last edited by
          #4

          @ofmrew Tried it on Win10 Qt5.10, same result, but worse.

          mrjjM 1 Reply Last reply
          0
          • O ofmrew

            @ofmrew Tried it on Win10 Qt5.10, same result, but worse.

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

            @ofmrew

            hi
            Try heavier lines then.
            Normally it can smooth bitmaps ok.

            But you are scaling it down. that might eat lines if scaled to much.

            O 1 Reply Last reply
            0
            • mrjjM mrjj

              @ofmrew

              hi
              Try heavier lines then.
              Normally it can smooth bitmaps ok.

              But you are scaling it down. that might eat lines if scaled to much.

              O Offline
              O Offline
              ofmrew
              wrote on last edited by
              #6

              @mrjj I tried that, and, yes, it helped; however, the application that I am looking at has user provided scanned images that will be used as a background to be drawn over. There is no control over line thickness, nor even resolution of scans.

              I experimented with the GIMP Image Reader on Mint Linux and I could never get it to lose lines. It would appear that it is in the QPainter::drawPixmap function where a large source rectangle from the pixmap to the smaller target rectangle of widget is the source of the problem. Now to find the solution. I will try experimenting with QImage. Any suggestions are welcome.

              1 Reply Last reply
              0
              • O Offline
                O Offline
                ofmrew
                wrote on last edited by
                #7

                Found the answer; it required an intermediate step of scaling the pixmap and drawing that pixmap. It work the same with a QImage.

                    QPixmap bls = blocks->scaled(this->size(),Qt::KeepAspectRatio,Qt::SmoothTransformation);
                    p.drawPixmap(this->rect(), bls, bls.rect());
                

                Why was this not included as an option in the painter drawPixmap?

                O 1 Reply Last reply
                2
                • O ofmrew

                  Found the answer; it required an intermediate step of scaling the pixmap and drawing that pixmap. It work the same with a QImage.

                      QPixmap bls = blocks->scaled(this->size(),Qt::KeepAspectRatio,Qt::SmoothTransformation);
                      p.drawPixmap(this->rect(), bls, bls.rect());
                  

                  Why was this not included as an option in the painter drawPixmap?

                  O Offline
                  O Offline
                  ofmrew
                  wrote on last edited by
                  #8

                  @ofmrew Update. It also works with a 0 width pen, but is barely visible.

                  1 Reply Last reply
                  0
                  • mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    Ah
                    So you "zoomed" it by drawing it into a bigger rect and that did not apply
                    smoothing even with QPainter::SmoothPixmapTransform ?
                    Or at least not like scaled.

                    O 1 Reply Last reply
                    0
                    • mrjjM mrjj

                      Ah
                      So you "zoomed" it by drawing it into a bigger rect and that did not apply
                      smoothing even with QPainter::SmoothPixmapTransform ?
                      Or at least not like scaled.

                      O Offline
                      O Offline
                      ofmrew
                      wrote on last edited by
                      #10

                      @mrjj Let me explain it better. I have drawn a pixmap that is 20,000 by 10,000 and saved that to a PNG file. The widget that I am displaying that image on is 1014 by 657. The first image (see original post) is a 500 by 500 rectangle of the pixmap (aspect ratio adjusted) that is drawn on the widget (Zoomed In). The second image (Zoomed Out) is a rectangle larger that the widget, i.e, more of the pixmap is viewed. As I zoom out more of the lines disappear. raven-worx suggested QPainter::Antialiasing, then I found Qt::SmoothTransformation. Now I can zoom in or zoom out without a problem; however, I have not looked into how response time might be affected by creating a temporary pixmap to display.

                      1 Reply Last reply
                      1
                      • O Offline
                        O Offline
                        ofmrew
                        wrote on last edited by
                        #11

                        I used the Image Viewer to open the large file. And it, after changing the zoom out action to allow viewing the full image, drew the complete image and with good response on zooming and panning. I looked at the paintEvent in the QLabel source code and found my solution, namely:

                                        d->scaledpixmap = new QPixmap(QPixmap::fromImage(d->cachedimage->scaled(cr.size(),Qt::IgnoreAspectRatio,Qt::SmoothTransformation)));
                        

                        I guess great minds think alike. Anyway, ignore my comment about response time as there is none that I can see. I will need to change my widget, MyCanvas, to act like QLabel or subclass QLabel.

                        1 Reply Last reply
                        1

                        • Login

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