Reputation: 1585
Lets suppose we are using a Dialog
or a MessageDialog
element, where we have the default buttons. How can we change the text and even use qsTr for translating?
Lets suppose the following Dialog
Dialog {
id: dateDialog
visible: true
title: "Choose a date"
standardButtons: StandardButton.Save | StandardButton.Cancel
onAccepted: console.log("Saving the date " +
calendar.selectedDate.toLocaleDateString())
Calendar {
id: calendar
onDoubleClicked: dateDialog.click(StandardButton.Save)
}
}
and MessageDialog
:
import QtQuick 2.2
import QtQuick.Dialogs 1.1
MessageDialog {
title: "Overwrite?"
icon: StandardIcon.Question
text: "file.txt already exists. Replace?"
detailedText: "To replace a file means that its existing contents will be lost. " +
"The file that you are copying now will be copied over it instead."
standardButtons: StandardButton.Yes | StandardButton.YesToAll |
StandardButton.No | StandardButton.NoToAll | StandardButton.Abort
Component.onCompleted: visible = true
onYes: console.log("copied")
onNo: console.log("didn't copy")
onRejected: console.log("aborted")
}
As we can see it uses StandardButton
this is the one i want the text customizable.
Upvotes: 6
Views: 2764
Reputation: 71
I solved the problem calling the method
myDialog.standardButton(Dialog.Ok).text = qsTrId("Ok")
in Component.onCompleted
Upvotes: 7