Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Decide what element in a delegate based on model content [Solved]
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 2 Posters 1.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    luca
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      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?

      1 Reply Last reply
      0
      • L Offline
        L Offline
        luca
        wrote on last edited by
        #3

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

        @

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved