首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在对话框和MessageDialog上,我们如何改变qml中按钮的文本?

在对话框和MessageDialog上,我们如何改变qml中按钮的文本?
EN

Stack Overflow用户
提问于 2019-02-27 16:39:52
回答 1查看 749关注 0票数 3

假设我们使用的是DialogMessageDialog元素,其中有默认按钮。我们如何更改文本,甚至使用qsTr进行翻译?

让我们假设以下Dialog

代码语言:javascript
复制
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

代码语言:javascript
复制
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,这就是我想要的可定制文本。

EN

回答 1

Stack Overflow用户

发布于 2020-09-11 16:04:49

我解决了调用该方法的问题

代码语言:javascript
复制
myDialog.standardButton(Dialog.Ok).text = qsTrId("Ok")

Component.onCompleted

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54901207

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档