Qt - OpacityMask does not work properly
-
hi everyone ! i am new in Qt world so, please be nice :D
i need to work in .qml, to apply a shader effect over just a part of an image;
i tried something like this: i load an image, put a mask (a picture in black and white - white represents the aria where i want to apply the shader); i tried with OpacityMask but it does not work;the example from help does not work either : http://qt-project.org/doc/qt-5.0/qtgraphicaleffects/qml-qtgraphicaleffects1-opacitymask.html#example
what am i missing ? any ideas ? thanks
-
Me too! HELP!
-
I found the problem!
Your mask object size must be same as source object.
See a sample:
@import QtQuick 2.1
import QtGraphicalEffects 1.0Rectangle {
id: root
width: 600; height: 450
Rectangle {
id: sourceObj
anchors.fill: parent
Column {
anchors.centerIn: parent
rotation: -13
Text {
text: "Iran advancing science"
font { family: "Segoe UI Light"; pixelSize: 32 }
}
Text {
text: "Persia was a cradle of science in earlier times. "+"<br/>"+
"Persia contributed to the current understanding of nature, "+"<br/>"+
"medicine, mathematics, and philosophy. Persians made important "+"<br/>"+
"contributions to algebra and chemistry, invented the wind-power "+"<br/>"+
"machine, and the first distillation of alcohol. "
font { family: "Segoe UI Light"; pixelSize: 12 }
}
}
color: "skyblue"
visible: false
}
Rectangle {
id: maskObj
color: "transparent" //Notice! i want to mask only non-transparent area!
anchors.fill: sourceObj //Size must be same assourceObj
Rectangle {
id: realMask //<----- This is my real mask
width: 313; height: 72
anchors.centerIn: parent
color: "red"
radius: 36
}visible: false } OpacityMask { id: myEffect source: sourceObj maskSource: maskObj anchors.fill: parent }
}
@
Good luck!