How can I intercept the signal of the red 'x' close button of a dialog in qml?
Dialog
{
id : dialog1
visible : false
title : "dialog1"
onRejected:
{
console.log("Red button x clicked signal") // Not working
}
Button
{
id: exitButton
text : "Exit"
onClicked :
{
console.log("exit button clicked") // this works
dialog1.visible = false
}
}
I've tried all signals of qml dialog, and none seem to work for the x red button.
Here I want the "X" button to behave exactly like it being rejected. You could call a different signal if you wanted, but I personally kept it to be the same as the rejected signal.
signal yesButtonClicked()
signal noButtonClicked()
signal rejectedButtonClicked()
signal acceptedButtonClicked()
property bool xButton: true
Dialog{
id: dialogId
title: dialogTitle
onYes: {
xButton = false
yesButtonClicked()
}
onNo: {
xButton = false
noButtonClicked()
}
onRejected: {
xButton = false
rejectedButtonClicked()
}
onAccepted: {
xButton = false
acceptedButtonClicked()
}
onVisibilityChanged: {
if (!this.visible && xButton){
rejectedButtonClicked()
}
if (this.visible){
xButton = true
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With