怎么做网站流量统计分析/如何自己创建网站
目标:QML实现弹窗实现点击按钮弹窗,点击不同的按钮 弹窗的内容会改变,但窗口不消失。点击窗口外部则窗口消失。
效果:
代码:
import QtQuick 2.15
import QtQuick.Controls 2.15ApplicationWindow {width: 400height: 300visible: true// 弹窗控制器property string currentContent: ""// 主界面按钮Row {spacing: 10Button {text: "显示内容A"onClicked: {currentContent = "A"popup.open()}}Button {text: "显示内容B"onClicked: {currentContent = "B"popup.open()}}}// 弹窗定义Popup {id: popupanchors.centerIn: parentmodal: truedim: true // 点击外部关闭closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutside// 核心:动态内容加载器Loader {id: contentLoadersourceComponent: {if (currentContent === "A") return contentAelse if (currentContent === "B") return contentBelse return null}}}// 定义不同内容组件Component {id: contentARectangle {width: 200height: 100color: "lightblue"Text { text: "这是内容A"; anchors.centerIn: parent }}}Component {id: contentBRectangle {width: 200height: 150color: "lightgreen"Column {anchors.centerIn: parentText { text: "这是内容B" }Button { text: "子按钮"; onClicked: console.log("点击B的子按钮") }}}}
}