한국어
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 453827
100 Qt의 오픈소스 라이센스 소개 file makersweb 2019.12.15 21862
99 Qt for MCU 1.0 릴리즈 makersweb 2019.12.10 15794
98 Qt Marketplace 발표 makersweb 2019.12.02 8776
97 QScopedPointer 소개 및 사용법 makersweb 2019.11.29 8034
96 QOpenVirtualkeyboard(Qt 5용 한글 및 영문, 숫자 가상키보드) file makersweb 2019.11.27 7767
95 Qt3D의 QML 타입으로 3D렌더링 file makersweb 2019.11.20 9421
94 라즈베리파이3에서 Boot to Qt 실행해보기 makersweb 2019.11.13 9714
93 Qt애플리케이션 객체(QCoreApplication, QGuiApplication, QApplication) 에 대해서 makersweb 2019.11.11 24384
92 Qt Quick 3D 소개 makersweb 2019.11.09 12669
91 QPushButton 의 커스텀 이미지버튼 file makersweb 2019.11.05 15544
90 qbs 사용 방법(Helloworld) file makersweb 2019.10.23 8584
89 웹기반 Qt Design Viewer [2] file makersweb 2019.10.23 11890
88 Qt Creator에서 Qt의존성 라이브러리 자동복사하기 file makersweb 2019.10.19 12807
87 Qt for Embedded Linux 화면출력 makersweb 2019.10.17 11795
86 Windows에서 Qt 설치 따라하기 file makersweb 2019.10.14 42784
85 Qbs 프로젝트를 정의하기 위해 사용되는 몇가지 중요한 아이템들 file makersweb 2019.10.13 9988
84 많은 리소스를 사용하는 Qt프로젝트에서 고려해봐야 할 qmake 옵션 makersweb 2019.10.11 10092
83 Qbs에 대한 소개와 설치하는 방법 makersweb 2019.10.09 9033
82 OpenGL 렌더링을 QtQuick과 통합하는 방법 file makersweb 2019.10.01 8973
81 QML내에서의 시그널, 슬롯 시스템 makersweb 2019.09.29 12881
 
단일배너