qml 창에서 구성 요소가 투명해지는 것을 방지합니다.

qml 창에서 구성 요소가 투명해지는 것을 방지합니다.

다음은 qml의 투명하고 프레임 없는 창에 대한 코드입니다.

import QtQuick 2.2
import QtQuick.Window 2.1
import Ubuntu.Components 0.1

Window {
    MouseArea {
        anchors.fill: parent

        // move window on drag
        property real lastMouseX: 0
        property real lastMouseY: 0
        onPressed: {
          lastMouseX = mouseX
          lastMouseY = mouseY
        }
        onMouseXChanged: window1.x += (mouseX - lastMouseX)
        onMouseYChanged: window1.y += (mouseY - lastMouseY)

    }

    id: window1
    title: "transparent"
    height: 200
    width: 400
//    flags: Qt.FramelessWindowHint
    flags: Qt.Popup
    color: '#efeded'
    opacity: 0.3

    x: (Screen.width / 2) - (window1.width / 2)
    y: (Screen.height / 2) - (window1.height / 2)

    Text {
        id: text1
        text: "Hello World"
        font.bold: true
        style: Text.Raised
        font.pointSize: 24
        color: "black"
        anchors.horizontalCenter: parent.horizontalCenter
        y: 40
    }

    Button {
        id: button1
        text: "close"
        anchors.left: parent.left
        anchors.leftMargin: 0
        anchors.right: parent.right
        anchors.rightMargin: 0
        y: 160

        onClicked: {
            window1.close()
        }
    }

}

결과:

여기에 이미지 설명을 입력하세요

그럼 버튼과 텍스트가 투명해지는 것을 방지할 수 있을까요?

창의 배경만 투명해야 합니다.

답변1

"불투명도"를 제거하고 반투명 색상을 사용합니다.

  color: Qt.rgba(0.239, 0.237, 0.237, 0.3)

http://qt-project.org/doc/qt-4.8/qml-color.html

힌트를 주셔서 감사합니다https://stackoverflow.com/a/17244302

관련 정보