Reputation: 97
In my project, the user can click a button in homepage to open a new Window (QtQuick.Window 2.2
). I want the button to be disabled when the Window is created and enabled when it's closed/destroyed.
The problem is
Code sample:
Homepage.qml
import QtQuick 2.12
Item {
id: homePageItem
property var component: null
property var obj: null
RoundButton {
id: windowBtn
enabled: // some condition
...
...
onClicked: {
component = Qt.createComponent("Window.qml")
obj = component.createObject(root)
obj.show()
// windowBtn.enabled = false
}
}
}
Window.qml
import QtQuick 2.12
import QtQuick.Window 2.2
Window {
width: 600
height: 600
...
...
}
Upvotes: 0
Views: 227
Reputation: 8287
You can listen for signals from the object you created.
Window.qml
Window {
width: 600
height: 600
signal closed() // Create a new signal
Component.onDestruction: {
closed() // Emit your signal when the object is destroyed
}
}
Homepage.qml
onClicked: {
component = Qt.createComponent("Window.qml")
obj = component.createObject(root)
// Create a listener for your signal
obj.onClosed.connect(()=> { windowBtn.enabled = true })
obj.show()
windowBtn.enabled = false
}
Upvotes: 1