How to detect Dialog.Discard
-
Hello. I have a QuickControls2 Dialog where I have defined
standardButtons: Dialog.Save | Dialog.Discard
. How do I detect when the Discard button is clicked? It does not close the dialog or emit a rejected signal. It does nothing. The documentation says it has the mysterious DestructiveRole, but doesn't explain how to use it. Thanks.Dialog { id: savdlg standardButtons: Dialog.Save | Dialog.Discard // ... Component.onCompleted: { console.log('savdlg completed') } Component.onDestruction: { console.log('savdlg destruction') } onAccepted: { console.log('savdlg: accepted') } onRejected: { console.log('savdlg: rejected') } Text { text: 'Save changes?' } }
-
what is bump here ?
Have you tried onDiscard signal ?
-
@dheerendra Bump gets the topic back to the top.
Ah, I should have specified I was using Qt 5.9. There is a Discard button and a DestructiveRole but no discarded signal. I see they added it in 5.10. Thanks.
-
You could use the fact that the
footer
of aDialog
is aDialogButtonBox
by default and add this to your dialog:signal discarded() Connections { target: dialog.footer onClicked: { if (button.DialogButtonBox.buttonRole) { dialog.discarded(); dialog.close(); } } }
-
@GrecKo Thank you! That worked. I could have also used a Cancel button and changed the text to 'Discard', but I did something else instead. I now want both a Cancel and Discard button, but don't like the default role for Cancel, so I made my own custom DialogButtonBox for the footer.
Glad I bumped :)