한국어
Qt
 

QML and Qt Quick OpacityMask 예제

makersweb 2023.01.26 21:03 조회 수 : 12159

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 453814
140 싱글 샷(Single-Shot) 시그널/슬롯 연결 makersweb 2021.05.12 8864
139 응용프로그램 자동실행 설정 (on Windows) makersweb 2021.05.08 7106
138 Qt 6 에서 프로퍼티 바인딩 makersweb 2021.04.03 6217
137 QML과 JavaScript 의 숫자 관련 내장된 함수 makersweb 2021.03.28 8084
136 Qt 5 코드를 Qt 6로 포팅하기 위해 도움이 되는 Clazy Framework file makersweb 2021.03.01 10592
135 C++로 작성한 클래스를 QML에서 생성 file makersweb 2021.02.10 11750
134 Qt MQTT의 pus/sub 튜토리얼 file makersweb 2021.02.06 12421
133 Qt 를 사용하거나 기반으로 하는 응용프로그램 file makersweb 2021.01.30 14956
132 Loader를 사용하여 동적으로 QML 로드 makersweb 2021.01.19 10200
131 QThread 및 QMutex 예제 makersweb 2021.01.12 8977
130 그래픽 소프트웨어에서 디자인 내보내기 (Exporting Designs from Graphics Software) j2doll 2020.12.25 10932
129 Qt5Compat 라이브러리를 사용하여 Qt5에서 Qt6로 포팅 [2] makersweb 2020.12.05 9819
128 Qt Quick Controls 2에 네이티브 데스크탑 스타일 추가 file makersweb 2020.11.23 15198
127 QML 바인딩 끊김 진단 makersweb 2020.11.08 7948
126 QML과 코루틴(Coroutines) makersweb 2020.11.03 7143
125 Qt 6의 비동기 API makersweb 2020.10.19 6911
124 QRandomGenerator 클래스를 사용하여 난수(random values) 생성 makersweb 2020.10.17 8456
123 Qt 6에서 QList 변경사항 makersweb 2020.10.08 10073
122 Qt 6.0의 개발 호스트 및 대상 플랫폼 makersweb 2020.09.16 11741
121 main함수 명령줄 옵션 해석 makersweb 2020.09.01 10109
 
단일배너