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. How to properly drawPixmap with smooth transformation
Forum Updated to NodeBB v4.3 + New Features

How to properly drawPixmap with smooth transformation

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 3 Posters 5.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.
  • M Offline
    M Offline
    Manifolds
    wrote on last edited by
    #1

    code :

        // draw table cell
        painter->setRenderHint(QPainter::Antialiasing, true);
        painter->setRenderHint(QPainter::SmoothPixmapTransform, true);
        QPixmap pm(":/icons/xxx.png");
        ... ...
       painter->drawPixmap(iconrect, pm);
    

    The size of file xxx.png is 250x250. The table cell size is 24x24. But the image qt drawed still have no antialias effect.

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

      How big is the original image ?

      M 1 Reply Last reply
      0
      • mrjjM mrjj

        How big is the original image ?

        M Offline
        M Offline
        Manifolds
        wrote on last edited by
        #3

        @mrjj

        250x250 -> 18x18

        mrjjM 1 Reply Last reply
        0
        • M Manifolds

          @mrjj

          250x250 -> 18x18

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

          @Manifolds
          Hi
          You can use the scaled function to scale your self .
          alt text

          QPixmap B2=orgpic.scaled(18,18, Qt::KeepAspectRatio,Qt::SmoothTransformation);

          If you have many cells, its recommended do scale only once and use the scaled copy for drawing as not
          to perform the expensive operation each repaint.

          M 1 Reply Last reply
          0
          • mrjjM mrjj

            @Manifolds
            Hi
            You can use the scaled function to scale your self .
            alt text

            QPixmap B2=orgpic.scaled(18,18, Qt::KeepAspectRatio,Qt::SmoothTransformation);

            If you have many cells, its recommended do scale only once and use the scaled copy for drawing as not
            to perform the expensive operation each repaint.

            M Offline
            M Offline
            Manifolds
            wrote on last edited by
            #5

            @mrjj

            I draw image in my own item delegate, in paint(...) function.

            scale function is not a good solution, smooth effect is not so good.

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

              Hi,

              At the same time you are reducing to 18 pixels, this isn't much. You can't expect to have at that size something as smooth as with a picture that's about 15 times bigger.

              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
              • M Manifolds

                @mrjj

                I draw image in my own item delegate, in paint(...) function.

                scale function is not a good solution, smooth effect is not so good.

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

                @Manifolds
                Qt does quite good actually with scaled.
                photoshop did not produce anything better.
                That is with algorithm they have perfected over a decade.
                The PNG is not vector and you kill most of it scaling that much.
                To use icons of such varying size. The common solution is to hand correct scaled version from
                ei photoshop for the various sizes.

                1 Reply Last reply
                2

                • Login

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