Decide what element in a delegate based on model content [Solved]



  • Hi all,
    I have this delegate:
    @
    Component {
    id: riepilogo_delegate
    Rectangle {
    color: index % 2 ? "lightsteelblue" : "steelblue"
    id: item
    width: parent.width -5
    height: 100

            Column
            {
                anchors.fill: parent
                Text
                {
                    text: descrizione_estesa
                    anchors.horizontalCenter: parent.horizontalCenter
                }
                Text
                {
                    id: valore_dato
                    text: valore
                    anchors.horizontalCenter: parent.horizontalCenter
                }
                Text
                {
                    id: data_ora
                    text: "(" + data_ora_satellite + ")"
                    anchors.horizontalCenter: parent.horizontalCenter
                }
                Text
                {
                    id: tipo_dato
                    text: "(" + tipo + ")"
                    anchors.horizontalCenter: parent.horizontalCenter
                }
            }
    
        }
    }
    

    @

    It show a column of 4 Text elements.
    Now I'd like to show a Rectangle instead of the last Text element if ' tipo=="some text" ' .

    Is there a way to do that without using states?



  • How about just adding a rectangle, and controlling both the visibility of the rectangle element and the last text based on the value of tipo?



  • [quote author="Andre" date="1324469773"]How about just adding a rectangle, and controlling both the visibility of the rectangle element and the last text based on the value of tipo?[/quote]

    Thanks, I solved this way:
    @
    Component {
    id: riepilogo_delegate
    Rectangle {
    color: index % 2 ? "lightsteelblue" : "steelblue"
    id: item
    width: parent.width -5
    height: 100

            Column
            {
                anchors.fill: parent
                Text
                {
                    text: descrizione_estesa
                    anchors.horizontalCenter: parent.horizontalCenter
                }
                Text
                {
                    id: valore_dato
                    text: valore
                    anchors.horizontalCenter: parent.horizontalCenter
                }
                Text
                {
                    id: data_ora
                    text: "(" + data_ora_satellite + ")"
                    anchors.horizontalCenter: parent.horizontalCenter
                }
                Rectangle {
                    id: item_tipo
                    height: data_ora.height
                    width: parent.width
                    border.width: 2
                    anchors.horizontalCenter: parent.horizontalCenter
    
                    Text
                    {
                        id: tipo_dato_tex
                        text: "(" + tipo + ")"
                        anchors.horizontalCenter: parent.horizontalCenter
                        //anchors.fill: parent
                        //visible: false
                        visible: (tipo === "stato")
                    }
                    Rectangle {
                        id: tipo_dato_rec
                        width: parent.width
                        height: tipo_dato_tex.height
                        //text: "(" + tipo + ")"
                        //anchors.horizontalCenter: parent.horizontalCenter
                        anchors.fill: parent
                        //visible: true
                        visible: (tipo !== "stato")
                    }
                }
            }
        }
    }
    

    @


Log in to reply
 

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