旋转 QPixmap 而不缩放

发布于 2025-01-04 05:25:51 字数 635 浏览 4 评论 0原文

我正在重写 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

自在安然 2025-01-11 05:25:52

这是因为 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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文