<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Has devicePixelRatio behavior changed for 5.8?]]></title><description><![CDATA[<p dir="auto">I pull images into a QPixmap like so:</p>
<pre><code>const qreal pixelRatio = ((QGuiApplication*)QCoreApplication::instance())-&gt;devicePixelRatio();
    p = p.scaled(w*pixelRatio, h*pixelRatio, Qt::KeepAspectRatio, Qt::SmoothTransformation);
    p.setDevicePixelRatio(pixelRatio);
    QIcon pixmapIcon(p);
</code></pre>
<p dir="auto">I'm not sure if this is the perfect method, but up to Qt 5.7 it resulted in a HiDPI pixmap that I was able to use at width/pixelRatio, height/pixelRatio in the UI. Now, I end up with a fuzzy bitmap no matter what which if I change nothing is twice the size as the containing widget (and clearly not HiDPI). Has the HiDPI behavior changed fundamentally for 5.8? I didn't see any difference in the documentation.</p>
<p dir="auto">Cheers!</p>
]]></description><link>https://forum.qt.io/topic/76837/has-devicepixelratio-behavior-changed-for-5-8</link><generator>RSS for Node</generator><lastBuildDate>Fri, 24 Apr 2026 02:59:49 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/76837.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 03 Mar 2017 16:45:08 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Has devicePixelRatio behavior changed for 5.8? on Fri, 03 Mar 2017 23:52:30 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/vronin">@<bdi>VRonin</bdi></a> The icon size is now correct, and sharp, using the above icon+pixmap initialization along with this with the resulting icon. I call setIconToSize with the pixmap and the display w/h of the container it's going into. I don't use the @2x filename trick since this is generating the pixmap programmatically using an image the user selects, which ends up on a back end:</p>
<pre><code>void SSImageButton::setIconToSize(QPixmap p, int w, int h)
{
    QIcon icon = Utilities::getIconForPixmap(p, w, h);
    QSize iconSize = QSize(w, h);
    this-&gt;setIconSize(iconSize);
    this-&gt;setIcon(icon);
}
</code></pre>
<p dir="auto">where getIconForPixmap is as follows:</p>
<pre><code>QIcon Utilities::getIconForPixmap(QPixmap p, int w, int h)
{
    QRect cropRect = QRect(0, 0, p.width(), p.height());
    if (p.height() &gt; p.width()) {
        cropRect.setHeight(cropRect.width() * h / w);
        cropRect.moveTop((p.height() - cropRect.height())/2);
        p = p.copy(cropRect);
    } else if (p.height() &lt; p.width()) {
        cropRect.setWidth(cropRect.height() * w / h);
        cropRect.moveLeft((p.width() - cropRect.width())/2);
        p = p.copy(cropRect);
    } else {
        // it is square, we are all set
    }

    const qreal pixelRatio = ((QGuiApplication*)QCoreApplication::instance())-&gt;devicePixelRatio();
    p = p.scaled(w*pixelRatio, h*pixelRatio, Qt::KeepAspectRatio, Qt::SmoothTransformation);
    p.setDevicePixelRatio(pixelRatio);
    QIcon pixmapIcon(p);
    return pixmapIcon;
}
</code></pre>
]]></description><link>https://forum.qt.io/post/379750</link><guid isPermaLink="true">https://forum.qt.io/post/379750</guid><dc:creator><![CDATA[krekeltronics]]></dc:creator><pubDate>Fri, 03 Mar 2017 23:52:30 GMT</pubDate></item><item><title><![CDATA[Reply to Has devicePixelRatio behavior changed for 5.8? on Fri, 03 Mar 2017 18:19:09 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/vronin">@<bdi>VRonin</bdi></a> that's really interesting. Oddly enough, it looks really nice and sharp on 5.5-5.7 with our method, sized properly and everything. We just scale it to the pixel ratio (in this case 2X for a HiDPI Mac), then size the container to the "points" width and height.</p>
<p dir="auto">I do think there are some wonky things in QPixmap and QIcon so maybe our implementation worked by accident before and now needs to be done a different way. Does anyone have this consistently working?</p>
]]></description><link>https://forum.qt.io/post/379691</link><guid isPermaLink="true">https://forum.qt.io/post/379691</guid><dc:creator><![CDATA[krekeltronics]]></dc:creator><pubDate>Fri, 03 Mar 2017 18:19:09 GMT</pubDate></item><item><title><![CDATA[Reply to Has devicePixelRatio behavior changed for 5.8? on Fri, 03 Mar 2017 17:40:40 GMT]]></title><description><![CDATA[<p dir="auto">For what it's worth, I noticed the "fuzzyness" in 5.8 even without devicePixelRatio when I create a QIcon from a QPixmap so I think the problem is <code>QIcon pixmapIcon(p);</code></p>
<p dir="auto">P.S.<br />
Maybe this is related: <a href="https://bugreports.qt.io/browse/QTBUG-44486" target="_blank" rel="noopener noreferrer nofollow ugc">https://bugreports.qt.io/browse/QTBUG-44486</a></p>
]]></description><link>https://forum.qt.io/post/379685</link><guid isPermaLink="true">https://forum.qt.io/post/379685</guid><dc:creator><![CDATA[VRonin]]></dc:creator><pubDate>Fri, 03 Mar 2017 17:40:40 GMT</pubDate></item></channel></rss>