[SOLVED]text output



  • hi everyone. I'm planning to display a question on my image that would come from a script or code...

    for example

    @var answer;
    var question;
    switch(operation)
    {
    case 0:
    answer= firstVar + secondVar;
    question=firstVar +"+"+ secondVar;
    break;@

    I need to display the question thingy on the falling objects I'm doing

    how would i do that? :D
    thanks for the response in advance :D



  • I'm sorry, but you want to use QML ? What's your falling object ?



  • yeah im using QML right now.. falling object.. a custom image of a meteor



  • I think that's should not be a problem. Do i understand it right ?
    @
    ....

    property string questionText : ""

    function xxx() {
    var answer;
    switch(operation)
    {
    case 0:
    answer = firstVar + secondVar;
    questionText = firstVar + "+" + secondVar;
    break;
    }
    }

    Image {
    .....

    Text {
    anchors.centerIn: parent // Something like this
    text: questionText // So the questionText should be a property
    }
    }

    ....
    @



  • wait Im gonna try that :D



  • your code seems helpful but now the image doesn't appear

    this is my complete code

    @import QtQuick 1.0
    import "Logic.js" as Logic

    Rectangle{
    property string questionText:""

    function questions(r){
        var first = Math.floor(Math.random()*11);
        var second = Math.floor(Math.random()*11);
        var operation = Math.floor(Math.random()*4);
    
        var answer;
        var question;
        switch(operation)
        {
        case 0:
            answer=first+second;
            question=first+"+"+second;
            break;
        case 1:
            answer=first-second;
            question = first + "-" + second;
            break;
        case 2:
            answer=first*second;
            question=first+"*"+second;
            break;
        case 3:
            answer=first/second;
            question=first+"/"+second;
            break;
        }
    }
    

    Image{
    id:fire
    width:90;height:90
    smooth: false
    visible: false
    source: "../../../../../Users/MAJA/Desktop/lahat na/Untitled-1.png"
    fillMode: Image.PreserveAspectCrop
    Text {
    anchors.centerIn: parent
    text: questionText
    }

    ParallelAnimation{
        running: visible
    
        NumberAnimation{target: fire;property: "width";to:150;duration:1500}
        NumberAnimation{target: fire;property: "height";to:150;duration: 1500}
        NumberAnimation {target:fire;property:"y";from:0 ;to:550;duration:4500}
        NumberAnimation{target: fire;property: "x";from: fire.x* Math.random;duration: 8500}
    
    }
    

    }

    }@

    so what's the problem here



  • Not trying your code, but something you should make sure:

    1. Your Rectangle width and height and also anchors when necessary

    @
    Image{
    id:fire
    width:90;height:90
    smooth: false
    visible: false // When to set it true
    .....

    ParallelAnimation{
        running: visible // use fire.visible
    

    ....
    }

    }
    @

    And a kind advice for you, when you start to write a QML app, have a look at the example and document first :-)



  • By the way, there are tons of wonderful examples available. Here is a directory for Qt Quick examples:
    http://developer.qt.nokia.com/wiki/qml_examples_directory



  • actually after carefully looking at my codes and modifying it.. I found the problem on my .js file so its working already. thanks for the help guys


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.