旋转 QPixmap 而不缩放
我正在重写 QDial 的绘制事件并显示图像以赋予其新外观。现在我想根据当前值旋转图像。我正在使用以下代码执行此操作。
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);
}
图像确实旋转,但在不同的转盘值上缩放为不同的尺寸。因此,当我旋转 QDial 时,表盘会增大和缩小。
请让我知道如何解决这个问题。
有一种方法是获取每个 QDial 值的图像并根据旋钮值更新图像,但我不想这样做,因为旋钮范围是 0-1000。
谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是因为
scaled
对图像的边界框进行操作,因为您正在旋转图像,边界框会在 90 度增量之间“膨胀”。为什么不在显示图像时只设置一次比例,然后再旋转它呢?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?