PDA

View Full Version : Why antialiasing do not working for QML Image?



svv
16th March 2017, 05:24
Hello!

This is my code:


import QtQuick 2.6
import QtQuick.Window 2.2

Window {
visible: true
width: 640
height: 480
title: qsTr("Hello World")

Rectangle {
id: r0
anchors.fill: parent
color: "Black"

Image {
id: bi
source: "qrc:///3.png"
anchors.centerIn: parent
visible: true
antialiasing: true
}
}
}



I set antialiasing to true, but my .png on screen has a raggy boundary. Antialiasing do not working! Why?

My .png:
12388

On screen:
12389

anda_skoa
16th March 2017, 12:28
"antialiasing" is a property of Item, each subclass can handle this differently depending on its capabilities.

For Image that means that an SVG source is rendered with antialiasing, a pixel based source can only be displayed as it is.

If the only thing you need is a colored circle, you can do that with a Rectangle and its radius property or a custom item derived from QQuickPaintedItem

Cheers,
_

svv
16th March 2017, 16:40
"antialiasing" is a property of Item, each subclass can handle this differently depending on its capabilities.

For Image that means that an SVG source is rendered with antialiasing, a pixel based source can only be displayed as it is.

If the only thing you need is a colored circle, you can do that with a Rectangle and its radius property or a custom item derived from QQuickPaintedItem

Cheers,
_


Hello! Thank you! But it's very strange that antialiasing is performed only for svg. There is not a word in the documentation about this. That is, if I want a button of complex shape superimposed on an arbitrary background image, then the images must necessarily be in SVG format? Then why do we need all the other formats? May be it is bug?

anda_skoa
17th March 2017, 09:16
Hello! Thank you! But it's very strange that antialiasing is performed only for svg.

Not strange at all, actually :)

Antialiasing can only be done when drawing.
An SVG source is rendered on loading, a pixel based image is loaded as-is.



There is not a word in the documentation about this.

I guess it assumes that since it is a base class property, it is understood that different subclasses might handle it differently, depending on what they visualize, and in the case of Image that a pixel based image will be presented as-is.



That is, if I want a button of complex shape superimposed on an arbitrary background image, then the images must necessarily be in SVG format?

The use case for SVG is arbitrary scaling, i.e. the sourceSize property controls how large the SVG vector data will be rendered.
That makes it possible to "scale" without losing precision



Then why do we need all the other formats?

Not sure what you mean.
There are many formats for image content an application might want to display: e.g. PNG, JPEG, etc.

Image formats are handled by plugins and Qt supports quite a number of them by default.

Cheers,
_