0

In Qt Quick project, I derived a custom class from QQuickPaintedItem and mapped screen coordinate system to Cartesian coordinate system by providing a transform matrix, now I want to display a png on the custom class with QPainter->drawImage, however, the y coordinate of the image is inversed, how to fix it, thanks! enter image description here Below is the code snippet:

void DrawArea::paint(QPainter *painter)
{
    painter->setRenderHint(QPainter::Antialiasing, true);
    QTransform transform;
    transform.setMatrix(800.0/10.0, 0.0, 0.0,
                        0.0, -600.0/10.0, 0.0,
                        400, 300, 1.0);
    painter->setWorldTransform(transform);

    painter->drawImage(QRectF(0, 0, 3, 3), m_image, QRectF(0, 0, m_image.width(), 
                m_image.height()));
}

the window size is 800x600, the Cartesian coordinate is from -5 to 5 with both x and y. The y coord is inversed due to -600.0/10.0, but if I remove the minus sign as 600.0/10.0, the image is correct displayed, but the image extend below y=0 axis in Cartesian coordinate system. enter image description here

James Hao
  • 765
  • 2
  • 11
  • 40
  • Hi James. I haven't studied your matrix, put noticed that although scaling is working, no positional translation is taking place: (0,0) of you image (top-left) is mapped to (0,0) of your Cartesian system in both cases. Rather than reflecting the image (with the 'minus'), shouldn't you be translating it upward? Better yet, setting the image origin (0,0) to the lower-left? – Mark Aug 09 '22 at 23:15
  • get it solved by calling m_image.mirrored(), not sure it is the best solution. – James Hao Aug 10 '22 at 03:14

0 Answers0