Please nominate your Qt Champions for 2021!

QPainter drawImage seems different with original image

  • Hello everyone. I implement a class which extend QQuickPaintedItem and rewrite the paint( QPainter * ) to show an image of PDF page. I find the QPainter draw image do not work very well. Here is my drawing code:

    painter->setRenderHint(QPainter::HighQualityAntialiasing, true);
    painter->drawImage(m_rTarget, m_iPDFImage);

    and the following is a.bmp(part of image):
    but the result of drawImage looks like:
    here I hardly to see "-" in command "dpkg -i ".
    It cost my one day to try to solve it but fail. So what's the problem? Can anyone give me an advise? thx.

  • Moderators

    What is the type of m_rTarget? Is it a rect or a point?
    I assume it's a rect, so the image will be scaled to fit into it.

    If it's a point check if the painter itself is scaling, which means that the item is scaled?

  • Did you use the painter->setRenderHint(QPainter::SmoothPixmapTransform)?

  • @raven-worx m_rTarget is a QRectF.

  • @Devopia53 thx! now I can see the "-". I forgot it because I scaled the image using SmoothTransformation and didn't use it in painter again.

Log in to reply