한국어
Qt
 

QML and Qt Quick OpacityMask 예제

makersweb 2023.01.26 21:03 조회 수 : 943

OpacityMask을 사용하면 소스 아이템을 다른 아이템으로 마스킹할 수 있다.

import QtQuick
import QtQuick.Window
import Qt5Compat.GraphicalEffects

Window {
    visible: true
    width: 500
    height: 400
    title: qsTr("QtQuick GraphicalEffects")

    Rectangle {
        id: area
        anchors.fill: parent
        color: "white"

        Rectangle {
            id: punchHole
            width: 400
            height: 300

            anchors.centerIn: parent

            color: "yellowgreen"

            layer.enabled: true
            layer.effect: OpacityMask{
                maskSource: Rectangle {
                    width: punchHole.width
                    height: punchHole.height
                    radius: 15
                }
            }

            /* Internel Content */
            Text {
                font.pixelSize: 20
                text: qsTr("This property allows the effect output pixels to be cached \n in order to improve the rendering performance.")
                anchors.centerIn: parent
                color: "black"
                horizontalAlignment: Text.AlignHCenter
            }
        }
    }
}

 

OpacityMask.png


다음과 같은 이미지를 넣어보자.

sky.jpg

단지 Image 아이템을 사용하고 source를 지정하면 된다.

import QtQuick
import QtQuick.Window
import Qt5Compat.GraphicalEffects

Window {
    visible: true
    width: 500
    height: 400
    title: qsTr("QtQuick GraphicalEffects")

    Rectangle {
        id: area
        anchors.fill: parent
        color: "white"

        Image {
            id: punchHole
            width: 400
            height: 300

            anchors.centerIn: parent

            source: "qrc:/sky.jpg"

            layer.enabled: true
            layer.effect: OpacityMask{
                maskSource: Rectangle {
                    width: punchHole.width
                    height: punchHole.height
                    radius: 15
                }
            }

            /* Internel Content */
            Text {
                font.pixelSize: 20
                text: qsTr("This property allows the effect output pixels to be cached \n in order to improve the rendering performance.")
                anchors.centerIn: parent
                color: "greenyellow"
                horizontalAlignment: Text.AlignHCenter
            }
        }
    }
}

 

OpacityMask1.png

번호 제목 글쓴이 날짜 조회 수
공지 Qt프로그래밍(QtQuick) Beginner를 위한 글 읽는 순서 운영자 2019.01.05 87945
59 ShaderEffect QML Type을 이용한 버튼 클릭 효과 file makersweb 2020.05.22 1180
58 QScopedPointer 소개 및 사용법 makersweb 2019.11.29 1162
57 QML 전역 객체 (Global Object) file makersweb 2019.04.10 1158
56 Qt MQTT 에 대해서 file makersweb 2020.06.02 1114
55 Qt 6에서 QList 변경사항 makersweb 2020.10.08 1109
54 QML에서 D-Bus 통신 file makersweb 2023.03.15 1099
53 Qt로 XML 파싱 : Qt 6에서 업데이트된 (Parsing XML with Qt: Updates for Qt 6) [1] j2doll 2020.01.16 1075
52 Qt 6.0의 개발 호스트 및 대상 플랫폼 makersweb 2020.09.16 1063
51 [Qt] Google Play의 향후 요구 사항을 준수하는 방법 [2] j2doll 2019.07.29 1056
50 Qt기반의 서버와 클라이언트간 SOAP(Simple Object Access Protocol) file makersweb 2020.05.11 1053
49 QML 바인딩 끊김 진단 makersweb 2020.11.08 1052
48 Qt 5 코드를 Qt 6로 포팅하기 위해 도움이 되는 Clazy Framework file makersweb 2021.03.01 1044
47 Qt 5.15 및 Qt 6의 출시 일정 makersweb 2020.04.09 1033
46 Qt로 작성된 iOS 앱에서 시리얼 통신 file makersweb 2022.04.30 1020
45 Qt 응용프로그램에서 Lottie Animation사용 file makersweb 2021.05.30 999
44 QML 에서 QR코드 생성 file makersweb 2021.08.20 996
43 Qt로 작성된 안드로이드 APP에 Splash Screen을 추가 file makersweb 2020.03.10 983
42 클라우드용 Qt file makersweb 2024.01.16 972
41 QML에서 Websocket 서버와 통신 file makersweb 2021.09.18 972
40 Qt 6의 C++ 프로퍼티 바인딩 예제 makersweb 2021.11.01 949