5

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?

2
  • I have seen that you have found a different, better solution. Since I have voted to close another question as a duplicate of this one, you might want to add your solution as well.
    – xubuntix
    Jun 10, 2013 at 15:31
  • Done, thanks! Sorry, I found out shortly after having asked the question and was intending to post the answer, I just didn't have an Internet connection at the time :) Jun 10, 2013 at 18:39

2 Answers 2

4

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)
  }
}
1
  • In essence, it's what I was asking for. However, I've found an alternative way that does not depend on the Dialog component to know in advance the id of the caller, so I've posted it as another answer. Thanks! Jun 10, 2013 at 18:48
4

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)
    }
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .