Pergunta

I am overriding paint event of QDial and displaying an image to give it a new look. Now I want to rotate the image according to the current value. I am doing it using following code.

m_PixmapFound=m_Qpixmap.load(fileName);

if (m_PixmapFound)
{

            QMatrix rm;
            rm.rotate(value()*5);

            m_Qpixmap = m_Qpixmap.transformed(QPixmap::trueMatrix(rm,this->width(),this->height()));
            m_Qpixmap = m_Qpixmap.scaled(QSize(163,163),Qt::KeepAspectRatio,Qt::SmoothTransformation);

            QPainter  myPainter(&m_Qpixmap);
}

The image does rotate but its scaled to a different sizes on different dial values. So when I rotate QDial I the dial is growing and shrinking.

Please let me know how can fix this issue.

There is one way which is to get image for each QDial value and update the image according to the knob value but I don't want to do that since knob range is 0-1000.

Thanks

Foi útil?

Solução

It's because scaled operates on the bounding box of the image, because you are rotating it, the bounding box 'swells' between 90deg increments. Why not just set the scale once when showing the image, and then only rotate it after that?

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top