Ubuntu – How to create a dialog and set title and text dynamically

application-developmentqmlubuntu-sdkubuntu-touch

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?

Best Answer

This is not an answer to your question since the dialog text is not directly changed, but it might be an answer to your problem, since the dialog text changes itself dynamically :-)

Assuming that you have some item that triggeres the onSomethingHappened, you could connect properties of the dialog to properties of the item.

Example:

Item {
  Component {
     id: dialog
     Dialog {
        id: dialogue
        title: someID.dialogTitle
        text: someID.dialogText
        Button {
            text: "cancel"
            onClicked: PopupUtils.close(dialogue)
        }
     }
  }
}

SomeItem {
  id: someID
  property string dialogTitle
  property string dialogText
  onSomethingHappened: {
     dialogTitle = "Hello David"
     dialogText = "Whats up?"
     PopupUtils.open(dialog)
  }
}