假设我们使用的是Dialog或MessageDialog元素,其中有默认按钮。我们如何更改文本,甚至使用qsTr进行翻译?
让我们假设以下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)
}
}和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")
}正如我们所看到的,它使用了StandardButton,这就是我想要的可定制文本。
发布于 2020-09-11 16:04:49
我解决了调用该方法的问题
myDialog.standardButton(Dialog.Ok).text = qsTrId("Ok")在Component.onCompleted中
https://stackoverflow.com/questions/54901207
复制相似问题