Sunday, April 28, 2024
4
rated 0 times [  4] [ 0]  / answers: 1 / hits: 2500  / 1 Year ago, sun, january 1, 2023, 3:09:05

Looking at the Dialog component example in the Ubuntu SDK documentation, it looks as if dialogs are intended to be defined as static components with fixed title and text. Or at least I cannot figure out how to change it before showing the dialog.



I've also been hinted at the show() method of the PopupBase class on which Dialog is based, but I've not worked out how to use them for my purposes.



I've got a signal handler in my code where I'd like to open a dialog and dynamically set the title and text.



onSomethingHappened: {
/* Open a dialog and set the title and text properties */
}


How can I do that?


More From » application-development

 Answers
3

I've found I can do this with the following snippet in my code (root is the caller id for the open() method, but can be ignored for this example). Essentially, populating the params argument in the PopUtils.open() function:



PopupUtils.open(Qt.resolvedUrl("QrCodeDialog.qml"), root, {
title: i18n.tr("This is the title"),
text: i18n.tr("This is the text")
})


And then the QrCodeDialog.qml file contains:



import QtQuick 2.0
import Ubuntu.Components 0.1
import Ubuntu.Components.Popups 0.1

Dialog {
id: qrcodedialog
title: ""
text: ""

Button {
text: i18n.tr("Close")
onClicked: PopupUtils.close(qrcodedialog)
}
}

[#30809] Tuesday, January 3, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
thellfi

Total Points: 222
Total Questions: 103
Total Answers: 123

Location: Palau
Member since Mon, Aug 16, 2021
3 Years ago
;