你的
GrabWindow
未显示,因为在设置
visible
属性它与您使用
Window
的
看得见的
所有物
你的只是
看得见的
的属性
QWindow
。
窗
不直接实例化
QQuickWindow
,它实例化一个私有Qt类
QQuickWindowImpl
将覆盖
看得见的
具有自定义属性的属性。
这似乎延迟了
QWindow::setVisible
在以后的时间。
因此,我认为
QQuickWindow
意味着继承自。你可以试试
visible = true
在您的
Component.onCompleted
但我不确定这会解决你的问题。
相反,我建议您不要子类化
QQuickWindow
但只需创建一个新类型并将其传递给现有类型
窗
。
可能的API可能是:
Window {
id: myWindow
//...
MouseArea {
anchors.fill: parent
onClicked: WindowGrabber.grab(myWindow, path) //singleton type
}
}
或
Window {
id: myWindow
//...
WindowGrabber { // regular type
id: windowGrabber
window: myWindow
}
MouseArea {
anchors.fill: parent
onClicked: windowGrabber.grab(path) // you could even add a path property in WindowGrabber and not have it as a function parameter if that makes sense for your use case
}
}