Help in qml



  • hi dears
    i want to create a special tic-tac-toe game.my board is like this:and user give us squares , i wrote this qml file to do this,but i have some problem:for expamle when user get us 3 it should be 3 squares like this:
    !http://img4up.com/up2/66989532615607363583.png(tictactoe)!
    i have 2 question:
    in list i create 2 sample but when i ggive 3 to program it get me error in rect[3],can list add to its?
    and what should i do to create sth like this?
    i calculate the positions but i can't draw them
    @import QtQuick 1.1

    Rectangle {
    id:game
    width: 500; height: 500

    property list<Rectangle> rects:[ Rectangle {x:0;y:0; width: 100; height: 100;},
            Rectangle {x:0;y:0; width: 200; height: 200}]
    
    function calculateRects(rects,text)
    {
        for(var i=0;i<text;i++)
        {
            rects[i].x = 5+i*20;
            rects[i].y = 5+i*20;
            rects[i].width = 480 - i * 40;
            rects[i].height = 480 - i * 40;
        }
    }
    
    TextInput{
        validator: IntValidator{bottom: 1; top: 20;}
        focus: true
        onAccepted: {
            game.calculateRects(game.rects,text);
        }
    }
    
    /*Repeater {
        model:rects
        Rectangle {
            x : rects[index].x
            y : rects[index].y
            width : rects[index].width
            height : rects[index].height
        }
    }*/
    

    /* Rectangle {
    id: board
    signal created
    x:5;y:5
    color: "#00B000"
    border.width: 3
    width: 480; height: 480
    Rectangle{
    width: 10; height: 10
    color:"black"
    x:-5;y:-5
    radius: 10
    }
    Rectangle{
    width: 10; height: 10
    color:"black"
    x:-5;y:235
    radius: 10
    }
    Rectangle{
    width: 10; height: 10
    color:"black"
    x:-5;y:475
    radius: 10
    }
    Rectangle{
    width: 10; height: 10
    color:"black"
    x:235;y:-5
    radius: 10
    }
    Rectangle{
    width: 10; height: 10
    color:"black"
    x:235;y:475
    radius: 10
    }
    Rectangle{
    width: 10; height: 10
    color:"black"
    x:475;y:-5
    radius: 10
    }
    Rectangle{
    width: 10; height: 10
    color:"black"
    x:475;y:235
    radius: 10
    }
    Rectangle{
    width: 10; height: 10
    color:"black"
    x:475;y:475
    radius: 10
    }
    }
    Rectangle {
    color : "red"
    border.width: 3
    width:440;height:440
    x :25
    y : 25
    }
    Rectangle {
    color : "yellow"
    border.width: 3
    width:400;height:400
    x :45
    y : 45
    }*/
    }
    @


Log in to reply
 

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