How to properly drawPixmap with smooth transformation



  • 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.


  • Qt Champions 2017

    How big is the original image ?



  • @mrjj

    250x250 -> 18x18


  • Qt Champions 2017

    @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.



  • @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.


  • Lifetime Qt Champion

    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.


  • Qt Champions 2017

    @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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.