Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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?

share|improve this question
    
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 '13 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 :) –  David Planella Jun 10 '13 at 18:39
add comment

2 Answers

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)
  }
}
share|improve this answer
    
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! –  David Planella Jun 10 '13 at 18:48
add comment
up vote 3 down vote accepted

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)
    }
}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.