Blurry images in ListView on different screen resolutions
-
I am trying to display images in a ListView. The images are generated just fine, but on certain screen sizes and e.g. on windows with the 125% (recommended) display zoom option, the images look blurry:
How would I be able to prevent this?
EDIT:
Here is an example of how the generated image that was saved to a file and opened in a viewer application looks like (left) compared to how it looks when displayed in the ListView:
-
@Creaperdown
Are you using Qt 6?If so, be aware that logical pixels and physical pixels are a distinct concept there. So just because your item's boundingRect shows a width of 800, that doesn't mean you have 800 physical pixels. This would be my first guess on why you get scaled images.
Using the QuickItem's global coordinates, get the corresponding QScreen (QGuiApplication::screenAt) and then look at the screen's devicePixelRatio. If it is not 1.0, you have found the cause of your issue.
-
I think the problem might be the QQuickItem that is being scaled.
I am constructing the QImage from the data that I am getting from the rendering library and then setting it as the texture of the QQuickItem using a QPainter which is then displayed in a qml ListView:auto image = m_pageController->renderPage(); QPainter painter(&image); n->setTexture(window()->createTextureFromImage(image)); n->setRect(boundingRect());
-
@Creaperdown
Are you using Qt 6?If so, be aware that logical pixels and physical pixels are a distinct concept there. So just because your item's boundingRect shows a width of 800, that doesn't mean you have 800 physical pixels. This would be my first guess on why you get scaled images.
Using the QuickItem's global coordinates, get the corresponding QScreen (QGuiApplication::screenAt) and then look at the screen's devicePixelRatio. If it is not 1.0, you have found the cause of your issue.
-
@Asperamanca You are right, that is the problem. I have read through the docs about this issue and found another person who had a similar issue and said that they divided the size off the item through
window()->devicePixelRatio
to get the "original" size (at devicePixelRatio == 1).Is this a valid approach? How would I do that for my QQuickItem?
-
@Creaperdown
I cannot say much from your short code snippet. In short, render an image that scaled based the devicePixelRatio and use that. I currently do not have a better solution. -