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. change the content of a listview
Forum Updated to NodeBB v4.3 + New Features

change the content of a listview

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 121 Views
  • 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.
  • O Offline
    O Offline
    Oussou
    wrote on last edited by
    #1

    Hello,
    I would like to change the content of the preview by a green rectangle by clicking on an element of the listview. By default the black rectangle should always be displayed.
    Thank you

    //code
    ScrollView{
    id:scrollview
    clip: true
    width: colonne_1_2.width/1.2
    height: colonne_1_2.height/3
    /width:parent.width
    height: parent.height
    /
    ScrollBar.vertical.policy:ScrollBar.AlwaysOn
    anchors{
    left: parent.left
    //leftMargin: parent.height * 0.05
    top: parent.top
    topMargin: parent.height * 0.09
    }

                        ListView{
                            id:modellist
                           // x:120
                           // y:40
                            width: 60
                            height: 200
                            anchors.centerIn: parent
                            highlight: Rectangle{
                                anchors.fill: parent
                                //color: "grey"
    
                            }
                            focus: true
                            orientation: Qt.Vertical
                            model:ListModel{
                                id: nameModel
                                ListElement{
                                    name:"Template BMD Simple"
                                }
                                ListElement{
                                    name:"element 1"
                                }
                                ListElement{
                                    name:"element 2"
                                }
                                ListElement{
                                    name:"element 3"
                                }
                                ListElement{
                                    name:"element 4"
                                }
    

    }
    delegate:nameDelegate

    Component {
    id: nameDelegate
    Rectangle {
    id: top
    color: ListView.isCurrentItem ? "royalblue" : "white"
    width:parent.width/1.2
    height: text.implicitHeight
    Text {
    id: text
    anchors.centerIn: parent
    text:name
    color: parent.ListView.isCurrentItem ? "white" : "black"
    font.pixelSize: 14
    MouseArea {
    anchors.fill: parent
    hoverEnabled: true
    onClicked: top.ListView.view.currentIndex = model.index
    }
    }
    }
    }
    // Below is the listview whose content I want to change by clicking on an element
    ListView {
    id: list
    width: preview.width
    height: preview.height

                        model: controller // model is read from Column's model
    
                        currentIndex: modellist.currentIndex
                        //highlightMoveDuration: 200
    
                        delegate:ColumnLayout{
                            Rectangle{
                                id:contenue2
                                width: preview.width
                                height: preview.height
                                color: "black"
                            }
                            Rectangle{
                                id:contenue3
                                width: preview.width
                                height: preview.height
                                color: "green"
                            }
                        }
    

    }

    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