한국어
Qt
 

QML and Qt Quick OpacityMask 예제

makersweb 2023.01.26 21:03 조회 수 : 6530

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 116940
160 QML 바인딩 끊김 진단 makersweb 2020.11.08 4038
159 QMake 프로젝트를 CMake 프로젝트로 변환 with qmake2cmake makersweb 2022.09.17 4067
158 Qt MQTT 에 대해서 file makersweb 2020.06.02 4074
157 단일 인스턴스 Qt 응용 프로그램(Single-instance Application) makersweb 2022.06.23 4120
156 QScopedPointer 소개 및 사용법 makersweb 2019.11.29 4181
155 QRhi 에 대해서 file makersweb 2023.12.29 4209
154 Qbs 프로젝트를 정의하기 위해 사용되는 몇가지 중요한 아이템들 file makersweb 2019.10.13 4217
153 Embedded Linux 에서 Qt 및 Graphics Stack file 운영자 2020.05.27 4223
152 Qt 5 코드를 Qt 6로 포팅하기 위해 도움이 되는 Clazy Framework file makersweb 2021.03.01 4227
151 QML과 코루틴(Coroutines) makersweb 2020.11.03 4241
150 Qt 6에서 QList 변경사항 makersweb 2020.10.08 4262
149 ApplicationWindow 와 메뉴바(MenuBar)구성 file makersweb 2020.01.04 4299
148 하드디스크 드라이브 여유 공간 계산 file makersweb 2023.01.15 4321
147 tslib의 ts_calibrate를 응용해서 Qt로 터치보정기능 구현 file makersweb 2019.04.06 4327
146 안드로이드 가상장치 사용 file makersweb 2019.01.13 4406
145 Qt Bluetooth 관련 기능 확인 사항 makersweb 2018.07.10 4419
144 Qt 6의 C++ 프로퍼티 바인딩 예제 makersweb 2021.11.01 4455
143 ShaderEffect QML Type을 이용한 버튼 클릭 효과 file makersweb 2020.05.22 4477
142 Qt 5.15 및 Qt 6의 출시 일정 makersweb 2020.04.09 4519
141 Qt 스마트 포인터 (QSharedPointer, QScopedPointer, QPointer) makersweb 2022.08.18 4519