Cannot display QImage correctly on QQuickPaintedItem providing world tranform matrix

84 Views Asked by At

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

0

There are 0 best solutions below