Here is one way to do this:
// TB.qml
MouseArea {
width: txt.contentWidth + 20
height: txt.contentHeight + 10
property alias text: txt.text
property alias color: sh.color
ShaderEffect {
id: sh
anchors.fill: parent
property color color: "red"
property var source : ShaderEffectSource {
sourceRect: Qt.rect(0, 0, sh.width, sh.height)
sourceItem: Item {
width: sh.width
height: sh.height
Text {
id: txt
anchors.centerIn: parent
font.bold: true
font.pointSize: 30
text: "test"
}
}
}
fragmentShader:
"varying highp vec2 qt_TexCoord0;
uniform highp vec4 color;
uniform sampler2D source;
void main() {
gl_FragColor = color * (1.0 - texture2D(source, qt_TexCoord0).w);
}"
}
}
Using it:
TB {
text: "HELLO WORLD!!!"
color: "red"
onClicked: console.log("hi world")
}
Result:

The button is red, the text is gray on a gray background, and it will accurately show everything that is under the button.
, , outta , - .
, : . , ShaderEffectSource, QML ShaderEffectSource sampler 2D , - RGB . OpacityMask, , , .