How do I scale an image with QPainter?
Unsolved
General and Desktop
-
I have an image stored as QPixmap and I want to draw it out with QPainter and scale it. I overloaded the
QPaintEvent
in my widget and drew the QPixmap, but I don't know how to get it to scale.void ImagePainter::paintEvent(QPaintEvent *a_pEvent) { QPainter painter(this); painter.drawPixmap(10,10, m_image.width(), m_image.height(), m_image); painter.scale(1000,800); painter.end(); }
The scale function in here didn't do anything.
-
Scale first, then draw. Or you could also just do like
painter.drawPixmap(10,10, m_image.width() * 1000, m_image.height() * 800, m_image);
You may also call
painter.setRenderHint(QPainter::SmoothPixmapTransform)
before drawing any pixmap to make it scales more smoothly.