Предположим, мы используем элемент 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")
}
Asмы видим, что он использует StandardButton
это тот, который я хочу, чтобы текст настраивался.