QML主界面 自定义消息弹出框 在主界面左上角显示
//---------------主窗口
Window
{
id: mainWindow
visible: true
width: 320
height: 676
//无边框
flags: Qt.FramelessWindowHint//|Qt.Window
//悬浮窗口自动消失定时器
Timer{
id:timerId
interval: 5000
onTriggered: {
console.log("timer out")
airMessageBoxId.visible = false;
}
}
//提示信息弹出框
AirMessageBox{
id:airMessageBoxId
x:200;y:20
//x:0;y:0
//anchors.right: parent.left
width: 200
height: 80
visible: true
}
}
//----------------------------AirMessageBox
BorderImage {
id:airMessageBox
//显示内容
property alias contectText: contentTextId.text
width: 200; height: 80
border { left: 20; top: 20; right: 30; bottom: 20 }
horizontalTileMode: BorderImage.Repeat
verticalTileMode: BorderImage.Repeat
//source: "image/bg_other/balloon.png"
Rectangle {
id: shade;
anchors.fill: airMessageBox;
//radius: 10; color: "black";
opacity: 0;/*定义了透明度,0为完全透明,1为完全不透明*/
}
//显示内容
Text{
id:contentTextId
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
text:"message"
font.pointSize: 10
}
}
事实上主界面有消息时才显示,这里做简化,主要是显示位置:怎么让它在主界面外面左上角显示,并且能跟着窗口位置