
Hier ist der Code für ein transparentes und rahmenloses Fenster in 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()
}
}
}
Das Ergebnis:
Ist es also möglich, zu verhindern, dass die Schaltfläche und der Text transparent werden?
Nur der Hintergrund des Fensters sollte transparent sein.
Antwort1
Entfernen Sie „Deckkraft“ und verwenden Sie halbtransparente Farben:
color: Qt.rgba(0.239, 0.237, 0.237, 0.3)
http://qt-project.org/doc/qt-4.8/qml-color.html
Danke für den Tipphttps://stackoverflow.com/a/17244302